ProductSearchResultDTOImpl implements ProductSearchResultDTO { @Override public ProductSearchResultDTOImpl copy() { final ProductSearchResultDTOImpl copy = new ProductSearchResultDTOImpl(); copy.setId(this.id); copy.setCode(this.code); copy.setManufacturerCode(this.manufacturerCode); copy.setFulfilmentCentreCode(this.fulfilmentCentreCode); copy.setDefaultSkuCode(this.defaultSkuCode); copy.setName(this.name); if (this.displayName != null) { copy.setDisplayName(this.displayName.copy()); } copy.setDescription(this.description); if (this.displayDescription != null) { copy.setDisplayDescription(this.displayDescription.copy()); } copy.setTypeId(this.typeId); copy.setType(this.type); if (this.displayType != null) { copy.setDisplayType(this.displayType.copy()); } copy.setTypeMask(this.typeMask); copy.setTag(this.tag); copy.setBrand(this.brand); copy.setDefaultImage(this.defaultImage); copy.setCreatedTimestamp(this.createdTimestamp); copy.setUpdatedTimestamp(this.updatedTimestamp); final Map<Long, ProductSkuSearchResultDTO> copyBaseSku = new HashMap<>(); if (this.baseSkus != null) { for (final Map.Entry<Long, ProductSkuSearchResultDTO> skuDTO : this.baseSkus.entrySet()) { copyBaseSku.put(skuDTO.getKey(), skuDTO.getValue().copy()); } } copy.setBaseSkus(copyBaseSku); if (this.attributes != null) { copy.setAttributes(new StoredAttributesDTOImpl(this.attributes.toString())); } return copy; }  @Override String getDefaultImage(); void setDefaultImage(final String defaultImage); @Override @JsonIgnore Map<String, BigDecimal> getQtyOnWarehouse(final long shopId); @Override @JsonIgnore LocalDateTime getAvailableto(); @Override @JsonIgnore LocalDateTime getAvailablefrom(); @Override @JsonIgnore LocalDateTime getReleaseDate(); @Override @JsonIgnore int getAvailability(); @Override @JsonIgnore LocalDateTime getRestockDate(); @Override @JsonIgnore String getRestockNote(final String locale); @Override @JsonIgnore I18NModel getRestockNotes(); @Override long getId(); void setId(final long id); @Override String getCode(); void setCode(final String code); @Override String getManufacturerCode(); void setManufacturerCode(final String manufacturerCode); @Override String getFulfilmentCentreCode(); void setFulfilmentCentreCode(final String fulfilmentCentreCode); @Override @JsonIgnore boolean isMultisku(); @Override @JsonIgnore String getDefaultSkuCode(); void setDefaultSkuCode(final String defaultSkuCode); @Override StringI18NModel getDisplayName(); void setDisplayName(final StringI18NModel displayName); @Override String getName(final String locale); @Override String getName(); void setName(final String name); @Override String getDescription(); void setDescription(final String description); @Override String getDescription(final String locale); @Override StringI18NModel getDisplayDescription(); void setDisplayDescription(final StringI18NModel displayDescription); @Override long getTypeId(); void setTypeId(final long typeId); @Override String getType(final String locale); @Override String getType(); void setType(final String type); @Override StringI18NModel getDisplayType(); void setDisplayType(final StringI18NModel displayType); int getTypeMask(); void setTypeMask(final int typeMask); @Override @JsonIgnore boolean isService(); void setService(final boolean service); @Override @JsonIgnore boolean isConfigurable(); void setConfigurable(final boolean configurable); @Override @JsonIgnore boolean isShippable(); void setShippable(final boolean shippable); @Override @JsonIgnore boolean isDigital(); void setDigital(final boolean digital); @Override @JsonIgnore boolean isDownloadable(); void setDownloadable(final boolean downloadable); @Override @JsonIgnore boolean isNotSoldSeparately(); void setNotSoldSeparately(final boolean notSoldSeparately); @Override String getTag(); void setTag(final String tag); @Override String getBrand(); void setBrand(final String brand); @Override @JsonIgnore boolean isFeatured(); @Override @JsonIgnore BigDecimal getMinOrderQuantity(); @Override @JsonIgnore BigDecimal getMaxOrderQuantity(); @Override @JsonIgnore BigDecimal getStepOrderQuantity(); @Override @JsonIgnore ProductSkuSearchResultDTO getBaseSku(final long skuId); @Override Map<Long, ProductSkuSearchResultDTO> getBaseSkus(); void setBaseSkus(final Map<Long, ProductSkuSearchResultDTO> baseSkus); @Override @JsonIgnore List<ProductSkuSearchResultDTO> getSearchSkus(); @Override @JsonIgnore void setSearchSkus(final List<ProductSkuSearchResultDTO> searchSkus); @Override StoredAttributesDTO getAttributes(); void setAttributes(final StoredAttributesDTO attributes); @Override Instant getCreatedTimestamp(); void setCreatedTimestamp(final Instant createdTimestamp); @Override Instant getUpdatedTimestamp(); void setUpdatedTimestamp(final Instant updatedTimestamp); @Override ProductSearchResultDTOImpl copy(); @Override String toString();  }
@Test public void testCopy() throws Exception { final ProductSkuSearchResultDTOImpl firstSKU = new ProductSkuSearchResultDTOImpl(); firstSKU.setId(2); firstSKU.setCode("First SKU"); firstSKU.setManufacturerCode("ManFirst SKU"); firstSKU.setFulfilmentCentreCode("Main"); firstSKU.setName("FirstName SKU"); firstSKU.setDisplayName(new StringI18NModel("EN#~#FirstDisplayName SKU")); firstSKU.setDescription("FirstDescription SKU"); firstSKU.setDisplayDescription(new StringI18NModel("EN#~#FirstDisplayDescription SKU")); firstSKU.setAvailablefrom(LocalDateTime.now()); firstSKU.setAvailableto(LocalDateTime.now()); firstSKU.setReleaseDate(LocalDateTime.now()); firstSKU.setRestockDate(LocalDateTime.now()); firstSKU.setRestockNotes(new StringI18NModel("EN#~#Some text")); firstSKU.setCreatedTimestamp(Instant.now()); firstSKU.setUpdatedTimestamp(Instant.now()); firstSKU.setAvailability(2); firstSKU.setQtyOnWarehouse(new HashMap<Long, BigDecimal>() {{ put(10L, BigDecimal.ONE); }}); firstSKU.setFeatured(true); firstSKU.setTag("tag1 tag2"); firstSKU.setDefaultImage("FirstDefaultImageSKU.jpg"); final ProductSearchResultDTOImpl first = new ProductSearchResultDTOImpl(); first.setId(1); first.setCode("First"); first.setManufacturerCode("ManFirst"); first.setDefaultSkuCode("FirstCode"); first.setName("FirstName"); first.setDisplayName(new StringI18NModel("EN#~#FirstDisplayName")); first.setDescription("FirstDescription"); first.setDisplayDescription(new StringI18NModel("EN#~#FirstDisplayDescription")); first.setTypeId(123L); first.setType("typeA"); first.setDisplayType(new StringI18NModel("EN#~#displayTypeA")); first.setService(true); first.setConfigurable(true); first.setShippable(true); first.setDigital(true); first.setDownloadable(true); first.setTag("tag"); first.setBrand("brand"); first.setCreatedTimestamp(Instant.now()); first.setUpdatedTimestamp(Instant.now()); first.setDefaultImage("FirstDefaultImage.jpg"); first.setBaseSkus(Collections.singletonMap(firstSKU.getId(), firstSKU)); final ProductSearchResultDTO copy = first.copy(); assertEquals(first.getId(), copy.getId()); assertEquals(first.getCode(), copy.getCode()); assertEquals(first.getManufacturerCode(), copy.getManufacturerCode()); assertEquals(first.isMultisku(), copy.isMultisku()); assertEquals(first.getDefaultSkuCode(), copy.getDefaultSkuCode()); assertEquals(first.getName(), copy.getName()); assertEquals(first.getDisplayName(), copy.getDisplayName()); assertEquals(first.getDescription(), copy.getDescription()); assertEquals(first.getDisplayDescription(), copy.getDisplayDescription()); assertEquals(first.getTypeId(), copy.getTypeId()); assertEquals(first.getType(), copy.getType()); assertEquals(first.getDisplayType(), copy.getDisplayType()); assertTrue(copy.isService()); assertTrue(copy.isConfigurable()); assertTrue(copy.isShippable()); assertTrue(copy.isDigital()); assertTrue(copy.isDownloadable()); assertEquals(first.getTag(), copy.getTag()); assertEquals(first.getBrand(), copy.getBrand()); assertNull(first.getAvailablefrom()); assertEquals(first.getAvailablefrom(), copy.getAvailablefrom()); assertNull(first.getAvailableto()); assertEquals(first.getAvailableto(), copy.getAvailableto()); assertNull(first.getReleaseDate()); assertEquals(first.getReleaseDate(), copy.getReleaseDate()); assertNull(first.getRestockDate()); assertEquals(first.getRestockDate(), copy.getRestockDate()); assertNull(first.getRestockNote("EN")); assertEquals(first.getRestockNote("EN"), copy.getRestockNote("EN")); assertEquals(first.getCreatedTimestamp(), copy.getCreatedTimestamp()); assertEquals(first.getUpdatedTimestamp(), copy.getUpdatedTimestamp()); assertEquals(1, first.getAvailability()); assertEquals(first.getAvailability(), copy.getAvailability()); assertNotNull(first.getQtyOnWarehouse(10L)); assertNull(first.getQtyOnWarehouse(10L).get("First SKU")); assertNull(copy.getQtyOnWarehouse(10L).get("First SKU")); assertEquals(first.getDefaultImage(), copy.getDefaultImage()); assertFalse(first.isFeatured()); assertEquals(first.isFeatured(), copy.isFeatured()); assertNull("Search SKU will be set on a copy by search service", copy.getSearchSkus()); assertFalse(first.equals(copy)); assertFalse(first.hashCode() == copy.hashCode()); copy.setSearchSkus(Collections.singletonList(copy.getBaseSku(2))); assertEquals(first.getId(), copy.getId()); assertEquals(first.getCode(), copy.getCode()); assertEquals(first.getManufacturerCode(), copy.getManufacturerCode()); assertEquals(first.isMultisku(), copy.isMultisku()); assertEquals(firstSKU.getCode(), copy.getDefaultSkuCode()); assertEquals(first.getName(), copy.getName()); assertEquals(first.getDisplayName(), copy.getDisplayName()); assertEquals(first.getDescription(), copy.getDescription()); assertEquals(first.getDisplayDescription(), copy.getDisplayDescription()); assertEquals(first.getTypeId(), copy.getTypeId()); assertEquals(first.getType(), copy.getType()); assertEquals(first.getDisplayType(), copy.getDisplayType()); assertTrue(copy.isService()); assertTrue(copy.isConfigurable()); assertTrue(copy.isShippable()); assertTrue(copy.isDigital()); assertTrue(copy.isDownloadable()); assertEquals(first.getTag(), copy.getTag()); assertEquals(first.getBrand(), copy.getBrand()); assertNull(first.getAvailablefrom()); assertNotNull(copy.getAvailablefrom()); assertEquals(firstSKU.getAvailablefrom(), copy.getAvailablefrom()); assertNull(first.getAvailableto()); assertNotNull(copy.getAvailableto()); assertEquals(firstSKU.getAvailableto(), copy.getAvailableto()); assertNull(first.getReleaseDate()); assertNotNull(copy.getReleaseDate()); assertEquals(firstSKU.getReleaseDate(), copy.getReleaseDate()); assertNull(first.getRestockDate()); assertNotNull(copy.getRestockDate()); assertEquals(firstSKU.getRestockDate(), copy.getRestockDate()); assertNull(first.getRestockNote("EN")); assertNotNull(copy.getRestockNote("EN")); assertEquals(firstSKU.getRestockNote("EN"), copy.getRestockNote("EN")); assertEquals(first.getCreatedTimestamp(), copy.getCreatedTimestamp()); assertEquals(first.getUpdatedTimestamp(), copy.getUpdatedTimestamp()); assertEquals(1, first.getAvailability()); assertEquals(firstSKU.getAvailability(), copy.getAvailability()); assertNotNull(first.getQtyOnWarehouse(10L)); assertNull(first.getQtyOnWarehouse(10L).get("First SKU")); assertNotNull(copy.getQtyOnWarehouse(10L).get("First SKU")); assertEquals("FirstDefaultImage.jpg", first.getDefaultImage()); assertEquals(firstSKU.getDefaultImage(), copy.getDefaultImage()); assertFalse(first.isFeatured()); assertTrue(copy.isFeatured()); }