Skip to content

Commit 86f789f

Browse files
committed
DEVX-640: adding tests for different attributes
1 parent bccd7ed commit 86f789f

File tree

6 files changed

+329
-0
lines changed

6 files changed

+329
-0
lines changed

commercetools/commercetools-importapi-utils/src/test/java/com/commercetools/sdk/ProductUtilTest.java

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
import static com.commercetools.sdk.TestUtils.stringFromResource;
66
import static org.junit.jupiter.api.Assertions.*;
77

8+
import com.commercetools.api.models.product.Attribute;
89
import com.commercetools.api.models.product.ProductProjection;
910
import com.commercetools.api.models.product.ProductProjectionImpl;
11+
import com.commercetools.importapi.models.productvariants.NumberAttribute;
12+
import com.commercetools.importapi.models.productvariants.TextAttributeImpl;
1013
import com.fasterxml.jackson.databind.ObjectMapper;
1114

1215
import io.vrap.rmf.base.client.utils.json.JsonUtils;
@@ -36,4 +39,60 @@ void productTransformTest() {
3639
//assertEquals(testProduct.getName(), transformedProduct.getName());
3740
}
3841

42+
@Test
43+
void productTransformTestAttributesString() {
44+
String productProjectionExampleAttr = "src/test/resources/product-projection.example-attr-string.json";
45+
var testProduct = JsonUtils.fromJsonString(stringFromResource(productProjectionExampleAttr),
46+
ProductProjection.class);
47+
var transformedProduct = toProductDraftImport(testProduct);
48+
assertEquals(testProduct.getKey(), transformedProduct.getKey());
49+
assertEquals(1, transformedProduct.getAttributes().size());
50+
assertEquals("text", transformedProduct.getAttributes().get(0).getType());
51+
}
52+
53+
@Test
54+
void productTransformTestAttributesInt() {
55+
String productProjectionExampleAttr = "src/test/resources/product-projection.example-attr-int.json";
56+
var testProduct = JsonUtils.fromJsonString(stringFromResource(productProjectionExampleAttr),
57+
ProductProjection.class);
58+
var transformedProduct = toProductDraftImport(testProduct);
59+
assertEquals(testProduct.getKey(), transformedProduct.getKey());
60+
assertEquals(1, transformedProduct.getAttributes().size());
61+
assertEquals("number", transformedProduct.getAttributes().get(0).getType());
62+
}
63+
64+
@Test
65+
void productTransformTestAttributesBool() {
66+
String productProjectionExampleAttr = "src/test/resources/product-projection.example-attr-bool.json";
67+
var testProduct = JsonUtils.fromJsonString(stringFromResource(productProjectionExampleAttr),
68+
ProductProjection.class);
69+
var transformedProduct = toProductDraftImport(testProduct);
70+
assertEquals(testProduct.getKey(), transformedProduct.getKey());
71+
assertEquals(1, transformedProduct.getAttributes().size());
72+
assertEquals("boolean", transformedProduct.getAttributes().get(0).getType());
73+
}
74+
75+
@Test
76+
void productTransformTestAttributesDouble() {
77+
String productProjectionExampleAttr = "src/test/resources/product-projection.example-attr-double.json";
78+
var testProduct = JsonUtils.fromJsonString(stringFromResource(productProjectionExampleAttr),
79+
ProductProjection.class);
80+
var transformedProduct = toProductDraftImport(testProduct);
81+
assertEquals(testProduct.getKey(), transformedProduct.getKey());
82+
assertEquals(1, transformedProduct.getAttributes().size());
83+
assertEquals("number", transformedProduct.getAttributes().get(0).getType());
84+
}
85+
86+
87+
@Test
88+
void productTransformTestAttributesLong() {
89+
String productProjectionExampleAttr = "src/test/resources/product-projection.example-attr-long.json";
90+
var testProduct = JsonUtils.fromJsonString(stringFromResource(productProjectionExampleAttr),
91+
ProductProjection.class);
92+
var transformedProduct = toProductDraftImport(testProduct);
93+
assertEquals(testProduct.getKey(), transformedProduct.getKey());
94+
assertEquals(1, transformedProduct.getAttributes().size());
95+
assertEquals("number", transformedProduct.getAttributes().get(0).getType());
96+
}
97+
3998
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"id": "080feded-4f74-4d31-9309-f7ef6b7f1279",
3+
"version": 3,
4+
"key": "productKey",
5+
"productType": {
6+
"typeId": "product-type",
7+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
8+
"obj": {
9+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
10+
"version": 1,
11+
"createdAt": "1970-01-01T00:00:00.001Z",
12+
"lastModifiedAt": "1970-01-01T00:00:00.001Z",
13+
"key": "productTypeKey",
14+
"name": "productTypeName",
15+
"description": "productTypeDescription",
16+
"attributes": []
17+
}
18+
},
19+
"name": {
20+
"en": "Some Products"
21+
},
22+
"categories": [],
23+
"slug": {
24+
"en": "product_slug_jxeutnxwkswk"
25+
},
26+
"masterVariant": {
27+
"key": "masterVariantKey",
28+
"id": 1,
29+
"prices": [],
30+
"images": [],
31+
"attributes": [
32+
{
33+
"name": "text1",
34+
"value": {
35+
"it": "italian1",
36+
"de": "german1",
37+
"en": "englisch1"
38+
}
39+
}
40+
]
41+
},
42+
"variants": [],
43+
"searchKeywords": {},
44+
"hasStagedChanges": false,
45+
"published": true,
46+
"createdAt": "1970-01-01T00:00:00.001Z",
47+
"lastModifiedAt": "2014-01-07T15:25:50.034Z",
48+
"attributes": [
49+
{
50+
"name": "attr1",
51+
"value": true
52+
}
53+
]
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"id": "080feded-4f74-4d31-9309-f7ef6b7f1279",
3+
"version": 3,
4+
"key": "productKey",
5+
"productType": {
6+
"typeId": "product-type",
7+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
8+
"obj": {
9+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
10+
"version": 1,
11+
"createdAt": "1970-01-01T00:00:00.001Z",
12+
"lastModifiedAt": "1970-01-01T00:00:00.001Z",
13+
"key": "productTypeKey",
14+
"name": "productTypeName",
15+
"description": "productTypeDescription",
16+
"attributes": []
17+
}
18+
},
19+
"name": {
20+
"en": "Some Products"
21+
},
22+
"categories": [],
23+
"slug": {
24+
"en": "product_slug_jxeutnxwkswk"
25+
},
26+
"masterVariant": {
27+
"key": "masterVariantKey",
28+
"id": 1,
29+
"prices": [],
30+
"images": [],
31+
"attributes": [
32+
{
33+
"name": "text1",
34+
"value": {
35+
"it": "italian1",
36+
"de": "german1",
37+
"en": "englisch1"
38+
}
39+
}
40+
]
41+
},
42+
"variants": [],
43+
"searchKeywords": {},
44+
"hasStagedChanges": false,
45+
"published": true,
46+
"createdAt": "1970-01-01T00:00:00.001Z",
47+
"lastModifiedAt": "2014-01-07T15:25:50.034Z",
48+
"attributes": [
49+
{
50+
"name": "attr1",
51+
"value": 5.2
52+
}
53+
]
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"id": "080feded-4f74-4d31-9309-f7ef6b7f1279",
3+
"version": 3,
4+
"key": "productKey",
5+
"productType": {
6+
"typeId": "product-type",
7+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
8+
"obj": {
9+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
10+
"version": 1,
11+
"createdAt": "1970-01-01T00:00:00.001Z",
12+
"lastModifiedAt": "1970-01-01T00:00:00.001Z",
13+
"key": "productTypeKey",
14+
"name": "productTypeName",
15+
"description": "productTypeDescription",
16+
"attributes": []
17+
}
18+
},
19+
"name": {
20+
"en": "Some Products"
21+
},
22+
"categories": [],
23+
"slug": {
24+
"en": "product_slug_jxeutnxwkswk"
25+
},
26+
"masterVariant": {
27+
"key": "masterVariantKey",
28+
"id": 1,
29+
"prices": [],
30+
"images": [],
31+
"attributes": [
32+
{
33+
"name": "text1",
34+
"value": {
35+
"it": "italian1",
36+
"de": "german1",
37+
"en": "englisch1"
38+
}
39+
}
40+
]
41+
},
42+
"variants": [],
43+
"searchKeywords": {},
44+
"hasStagedChanges": false,
45+
"published": true,
46+
"createdAt": "1970-01-01T00:00:00.001Z",
47+
"lastModifiedAt": "2014-01-07T15:25:50.034Z",
48+
"attributes": [
49+
{
50+
"name": "attr1",
51+
"value": 5
52+
}
53+
]
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"id": "080feded-4f74-4d31-9309-f7ef6b7f1279",
3+
"version": 3,
4+
"key": "productKey",
5+
"productType": {
6+
"typeId": "product-type",
7+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
8+
"obj": {
9+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
10+
"version": 1,
11+
"createdAt": "1970-01-01T00:00:00.001Z",
12+
"lastModifiedAt": "1970-01-01T00:00:00.001Z",
13+
"key": "productTypeKey",
14+
"name": "productTypeName",
15+
"description": "productTypeDescription",
16+
"attributes": []
17+
}
18+
},
19+
"name": {
20+
"en": "Some Products"
21+
},
22+
"categories": [],
23+
"slug": {
24+
"en": "product_slug_jxeutnxwkswk"
25+
},
26+
"masterVariant": {
27+
"key": "masterVariantKey",
28+
"id": 1,
29+
"prices": [],
30+
"images": [],
31+
"attributes": [
32+
{
33+
"name": "text1",
34+
"value": {
35+
"it": "italian1",
36+
"de": "german1",
37+
"en": "englisch1"
38+
}
39+
}
40+
]
41+
},
42+
"variants": [],
43+
"searchKeywords": {},
44+
"hasStagedChanges": false,
45+
"published": true,
46+
"createdAt": "1970-01-01T00:00:00.001Z",
47+
"lastModifiedAt": "2014-01-07T15:25:50.034Z",
48+
"attributes": [
49+
{
50+
"name": "attr1",
51+
"value": 5000000000000000
52+
}
53+
]
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"id": "080feded-4f74-4d31-9309-f7ef6b7f1279",
3+
"version": 3,
4+
"key": "productKey",
5+
"productType": {
6+
"typeId": "product-type",
7+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
8+
"obj": {
9+
"id": "1c095f1b-e638-4c7e-86c4-c58df873fca6",
10+
"version": 1,
11+
"createdAt": "1970-01-01T00:00:00.001Z",
12+
"lastModifiedAt": "1970-01-01T00:00:00.001Z",
13+
"key": "productTypeKey",
14+
"name": "productTypeName",
15+
"description": "productTypeDescription",
16+
"attributes": []
17+
}
18+
},
19+
"name": {
20+
"en": "Some Products"
21+
},
22+
"categories": [],
23+
"slug": {
24+
"en": "product_slug_jxeutnxwkswk"
25+
},
26+
"masterVariant": {
27+
"key": "masterVariantKey",
28+
"id": 1,
29+
"prices": [],
30+
"images": [],
31+
"attributes": [
32+
{
33+
"name": "text1",
34+
"value": {
35+
"it": "italian1",
36+
"de": "german1",
37+
"en": "englisch1"
38+
}
39+
}
40+
]
41+
},
42+
"variants": [],
43+
"searchKeywords": {},
44+
"hasStagedChanges": false,
45+
"published": true,
46+
"createdAt": "1970-01-01T00:00:00.001Z",
47+
"lastModifiedAt": "2014-01-07T15:25:50.034Z",
48+
"attributes": [
49+
{
50+
"name": "attr1",
51+
"value": "attr1Value"
52+
}
53+
]
54+
}

0 commit comments

Comments
 (0)