Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class ConstructorItem {
private String imageUrl;
private String id;
private String description;
private Boolean active;
private Map<String, List<Object>> facets;
private Map<String, Object> metadata;
private List<String> groupIds;
Expand All @@ -37,6 +38,7 @@ public ConstructorItem(String id, String name) throws IllegalArgumentException {
this.url = null;
this.imageUrl = null;
this.description = null;
this.active = null;
this.facets = null;
this.metadata = null;
this.groupIds = null;
Expand All @@ -54,6 +56,7 @@ public ConstructorItem(String id) throws IllegalArgumentException {
this.url = null;
this.imageUrl = null;
this.description = null;
this.active = null;
this.facets = null;
this.metadata = null;
this.groupIds = null;
Expand Down Expand Up @@ -82,6 +85,7 @@ public Map<String, Object> toMap() {
dataMap.put("facets", this.facets);
dataMap.put("group_ids", this.groupIds);
dataMap.put("description", this.description);
dataMap.put("active", this.active);
params.put("data", dataMap);

return params;
Expand Down Expand Up @@ -171,6 +175,20 @@ public void setDescription(String description) {
this.description = description;
}

/**
* @return the active status of the item
*/
public Boolean getActive() {
return active;
}

/**
* @param active the active status to set for the item
*/
public void setActive(Boolean active) {
this.active = active;
}

/**
* @return the id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ public class ConstructorVariation {
private String id;
private String itemId;
private String description;
private Boolean active;
private Map<String, List<Object>> facets;
private Map<String, Object> metadata;
private List<String> groupIds;

/**
* Creates a variation. Optional public fields are in the <a
* href="https://docs.constructor.com/docs/integrating-with-constructor-product-catalog-items-variations">API documentation</a>
* href="https://docs.constructor.com/docs/integrating-with-constructor-product-catalog-items-variations">API
* documentation</a>
*
* @param id the id of the variation that you are adding.
* @param itemId the id of the item this variation is attached to.
Expand All @@ -45,6 +47,7 @@ public ConstructorVariation(String id, String itemId, String name)
this.url = null;
this.imageUrl = null;
this.description = null;
this.active = null;
this.facets = null;
this.metadata = null;
this.groupIds = null;
Expand All @@ -67,6 +70,7 @@ public ConstructorVariation(String id, String itemId) throws IllegalArgumentExce
this.url = null;
this.imageUrl = null;
this.description = null;
this.active = null;
this.facets = null;
this.metadata = null;
this.groupIds = null;
Expand All @@ -85,6 +89,7 @@ public ConstructorVariation(String id) throws IllegalArgumentException {
this.url = null;
this.imageUrl = null;
this.description = null;
this.active = null;
this.facets = null;
this.metadata = null;
this.groupIds = null;
Expand Down Expand Up @@ -114,6 +119,7 @@ public Map<String, Object> toMap() {
dataMap.put("facets", this.facets);
dataMap.put("group_ids", this.groupIds);
dataMap.put("description", this.description);
dataMap.put("active", this.active);
params.put("data", dataMap);

return params;
Expand Down Expand Up @@ -203,6 +209,20 @@ public void setDescription(String description) {
this.description = description;
}

/**
* @return the active status of the variation
*/
public Boolean getActive() {
return active;
}

/**
* @param active the active status to set for the variation
*/
public void setActive(Boolean active) {
this.active = active;
}

/**
* @return the id
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void AutocompleteWithPlusShouldBeEncodedInUrl() throws Exception {

RecordedRequest recordedRequest = mockServer.takeRequest();
String expectedPath =
String.format("/autocomplete/r%%2Bco?key=%s&c=ciojava-7.0.0", apiKey);
String.format("/autocomplete/r%%2Bco?key=%s&c=ciojava-7.1.0", apiKey);
String actualPath = recordedRequest.getPath();
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
}
Expand All @@ -60,7 +60,7 @@ public void AutocompleteWithSpaceShouldBeEncodedInUrl() throws Exception {

RecordedRequest recordedRequest = mockServer.takeRequest();
String expectedPath =
String.format("/autocomplete/r%%20co?key=%s&c=ciojava-7.0.0", apiKey);
String.format("/autocomplete/r%%20co?key=%s&c=ciojava-7.1.0", apiKey);
String actualPath = recordedRequest.getPath();
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
}
Expand All @@ -78,7 +78,7 @@ public void AutocompleteWithSlashShouldBeEncodedInUrl() throws Exception {

RecordedRequest recordedRequest = mockServer.takeRequest();
String expectedPath =
String.format("/autocomplete/r%%2Fco?key=%s&c=ciojava-7.0.0", apiKey);
String.format("/autocomplete/r%%2Fco?key=%s&c=ciojava-7.1.0", apiKey);
String actualPath = recordedRequest.getPath();
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
}
Expand All @@ -95,7 +95,7 @@ public void AutocompleteWithSingleQuoteShouldBeAllowedInUrl() throws Exception {
constructor.autocomplete(request, null);

RecordedRequest recordedRequest = mockServer.takeRequest();
String expectedPath = String.format("/autocomplete/r'co?key=%s&c=ciojava-7.0.0", apiKey);
String expectedPath = String.format("/autocomplete/r'co?key=%s&c=ciojava-7.1.0", apiKey);
String actualPath = recordedRequest.getPath();
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void makeUrlShouldReturnAUrl() throws Exception {
HttpUrl url = constructor.makeUrl(Arrays.asList("getitUuuurl"));
assertEquals("host is set", url.host(), "ac.cnstrc.com");
assertEquals("protocol is set", url.scheme(), "https");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
}

Expand All @@ -160,7 +160,7 @@ public void makeUrlWithBasePathShouldReturnAUrl() throws Exception {
assertEquals("Path is correct", url.encodedPath(), "/123/2345/getitUuuurl");
assertEquals("host is set", url.host(), "ac.cnstrc.com");
assertEquals("protocol is set", url.scheme(), "https");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
}

Expand All @@ -179,7 +179,7 @@ public void makeUrlWithBasePathAndUserInfoShouldReturnAUrl() throws Exception {
assertEquals("Path is correct", url.encodedPath(), "/123/2345/getitUuuurl");
assertEquals("host is set", url.host(), "ac.cnstrc.com");
assertEquals("protocol is set", url.scheme(), "https");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
}

Expand All @@ -190,7 +190,7 @@ public void makeUrlWithUserIdShouldReturnAUrl() throws Exception {
HttpUrl url = constructor.makeUrl(Arrays.asList("getitUuuurl"), info);
assertEquals("host is set", url.host(), "ac.cnstrc.com");
assertEquals("protocol is set", url.scheme(), "https");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
assertEquals("session id is set", url.queryParameter("s"), "2");
assertEquals("client id is set", url.queryParameter("i"), "sideshow bob");
Expand All @@ -205,7 +205,7 @@ public void makeUrlWithUserInfoShouldReturnAUrl() throws Exception {
HttpUrl url = constructor.makeUrl(Arrays.asList("getitUuuurl"), info);
assertEquals("host is set", url.host(), "ac.cnstrc.com");
assertEquals("protocol is set", url.scheme(), "https");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
assertEquals("session id is set", url.queryParameter("s"), "2");
assertEquals("client id is set", url.queryParameter("i"), "sideshow bob");
Expand All @@ -220,7 +220,7 @@ public void makeUrlWithUserSegmentsShouldReturnAUrl() throws Exception {
HttpUrl url = constructor.makeUrl(Arrays.asList("getitUuuurl"), info);
assertEquals("host is set", url.host(), "ac.cnstrc.com");
assertEquals("protocol is set", url.scheme(), "https");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.0.0");
assertEquals("version is set", url.queryParameter("c"), "ciojava-7.1.0");
assertEquals("apiKey is set", url.queryParameter("key"), "doinkaKey");
assertEquals("session id is set", url.queryParameter("s"), "2");
assertEquals("client id is set", url.queryParameter("i"), "sideshow bob");
Expand All @@ -238,7 +238,7 @@ public void verifyShouldReturnTrueWithValidKeyTokenPair() throws Exception {
@Test
public void getVersionShouldReturnClientVersion() throws Exception {
ConstructorIO constructor = new ConstructorIO(token, apiKey, true, null);
assertEquals("grabs version from pom.xml", constructor.getVersion(), "ciojava-7.0.0");
assertEquals("grabs version from pom.xml", constructor.getVersion(), "ciojava-7.1.0");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void SearchWithPlusShouldBeEncodedInUrl() throws Exception {
RecordedRequest recordedRequest = mockServer.takeRequest();
String expectedPath =
String.format(
"/search/r%%2Bco?key=%s&c=ciojava-7.0.0&section=Products&num_results_per_page=30",
"/search/r%%2Bco?key=%s&c=ciojava-7.1.0&section=Products&num_results_per_page=30",
apiKey);
String actualPath = recordedRequest.getPath();
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
Expand All @@ -63,7 +63,7 @@ public void SearchWithSpaceShouldBeEncodedInUrl() throws Exception {
RecordedRequest recordedRequest = mockServer.takeRequest();
String expectedPath =
String.format(
"/search/r%%20co?key=%s&c=ciojava-7.0.0&section=Products&num_results_per_page=30",
"/search/r%%20co?key=%s&c=ciojava-7.1.0&section=Products&num_results_per_page=30",
apiKey);
String actualPath = recordedRequest.getPath();
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
Expand All @@ -83,7 +83,7 @@ public void SearchWithSlashShouldBeEncodedInUrl() throws Exception {
RecordedRequest recordedRequest = mockServer.takeRequest();
String expectedPath =
String.format(
"/search/r%%2Fco?key=%s&c=ciojava-7.0.0&section=Products&num_results_per_page=30",
"/search/r%%2Fco?key=%s&c=ciojava-7.1.0&section=Products&num_results_per_page=30",
apiKey);
String actualPath = recordedRequest.getPath();
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
Expand All @@ -103,7 +103,7 @@ public void SearchWithSingleQuoteShouldBeAllowedInUrl() throws Exception {
RecordedRequest recordedRequest = mockServer.takeRequest();
String expectedPath =
String.format(
"/search/r'co?key=%s&c=ciojava-7.0.0&section=Products&num_results_per_page=30",
"/search/r'co?key=%s&c=ciojava-7.1.0&section=Products&num_results_per_page=30",
apiKey);
String actualPath = recordedRequest.getPath();
assertEquals("recorded request is encoded correctly", actualPath, expectedPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void newShouldReturnDefaultProperties() throws Exception {
assertEquals(item.getUrl(), null);
assertEquals(item.getImageUrl(), null);
assertEquals(item.getDescription(), null);
assertEquals(item.getActive(), null);
assertEquals(item.getId(), itemName);
assertEquals(item.getFacets(), null);
assertEquals(item.getGroupIds(), null);
Expand All @@ -60,6 +61,7 @@ public void settersShouldSet() throws Exception {
item.setUrl("https://constructor.io/test");
item.setImageUrl("https://constructor.io/test.png");
item.setDescription("See the world!");
item.setActive(true);
item.setId("TICK-007");
item.setGroupIds(Arrays.asList("Lucky Tickets", "Special Tickets", "Fancy Tickets"));

Expand All @@ -69,6 +71,7 @@ public void settersShouldSet() throws Exception {
assertEquals(item.getUrl(), "https://constructor.io/test");
assertEquals(item.getImageUrl(), "https://constructor.io/test.png");
assertEquals(item.getDescription(), "See the world!");
assertEquals(item.getActive(), true);
assertEquals(item.getId(), "TICK-007");
assertEquals(item.getFacets(), null);
assertEquals(item.getMetadata(), null);
Expand Down Expand Up @@ -97,4 +100,25 @@ public void toMapShouldHaveADataObject() throws Exception {
assertEquals(metadataFields.get("image_url"), "https://constructor.io/test.png");
assertEquals(metadataFields.get("test_field"), "test");
}

@Test
public void toMapShouldIncludeActiveWhenSet() throws Exception {
String itemName = this.getRandomProductName();
String itemId = itemName;
ConstructorItem item = new ConstructorItem(itemId, itemName);
item.setActive(true);

Map<String, Object> dataFields = (Map<String, Object>) item.toMap().get("data");
assertEquals(dataFields.get("active"), true);
}

@Test
public void toMapShouldIncludeActiveAsNullWhenNotSet() throws Exception {
String itemName = this.getRandomProductName();
String itemId = itemName;
ConstructorItem item = new ConstructorItem(itemId, itemName);

Map<String, Object> dataFields = (Map<String, Object>) item.toMap().get("data");
assertEquals(dataFields.get("active"), null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void newShouldReturnDefaultProperties() throws Exception {
assertEquals(variation.getUrl(), null);
assertEquals(variation.getImageUrl(), null);
assertEquals(variation.getDescription(), null);
assertEquals(variation.getActive(), null);
assertEquals(variation.getId(), variationName);
assertEquals(variation.getItemId(), itemId);
assertEquals(variation.getFacets(), null);
Expand All @@ -67,6 +68,7 @@ public void settersShouldSet() throws Exception {
variation.setUrl("https://constructor.io/test");
variation.setImageUrl("https://constructor.io/test.png");
variation.setDescription("See the world!");
variation.setActive(false);
variation.setId("TICK-007");
variation.setItemId("TICK");
variation.setGroupIds(Arrays.asList("Lucky Tickets", "Special Tickets", "Fancy Tickets"));
Expand All @@ -77,6 +79,7 @@ public void settersShouldSet() throws Exception {
assertEquals(variation.getUrl(), "https://constructor.io/test");
assertEquals(variation.getImageUrl(), "https://constructor.io/test.png");
assertEquals(variation.getDescription(), "See the world!");
assertEquals(variation.getActive(), false);
assertEquals(variation.getId(), "TICK-007");
assertEquals(variation.getItemId(), "TICK");
assertEquals(variation.getFacets(), null);
Expand Down Expand Up @@ -108,4 +111,27 @@ public void toMapShouldHaveADataObject() throws Exception {
assertEquals(metadataFields.get("image_url"), "https://constructor.io/test.png");
assertEquals(metadataFields.get("test_field"), "test");
}

@Test
public void toMapShouldIncludeActiveWhenSet() throws Exception {
String variationName = this.getRandomProductName();
String itemId = this.getRandomProductName();
ConstructorVariation variation =
new ConstructorVariation(variationName, itemId, variationName);
variation.setActive(false);

Map<String, Object> dataFields = (Map<String, Object>) variation.toMap().get("data");
assertEquals(dataFields.get("active"), false);
}

@Test
public void toMapShouldIncludeActiveAsNullWhenNotSet() throws Exception {
String variationName = this.getRandomProductName();
String itemId = this.getRandomProductName();
ConstructorVariation variation =
new ConstructorVariation(variationName, itemId, variationName);

Map<String, Object> dataFields = (Map<String, Object>) variation.toMap().get("data");
assertEquals(dataFields.get("active"), null);
}
}
Loading