@Test public void processProductDetailsTestForInternationalPartner() throws…
- User
@Test public void processProductDetailsTestForInternationalPartner() throws JsonProcessingException { List batchIdList = new ArrayList(); batchIdList.add(8196); List requestList = new ArrayList<>(); ExtractorRequest request = new ExtractorRequest(); request.setBatchId(123); request.setFranchiseNumber(8196); requestList.add(request);
List<ProductDataResponse> productResponseList = new ArrayList<>(); List<String> productIds = new ArrayList<>(); productIds.add("000000000060292784"); List<String> seasons = new ArrayList<>(); seasons.add("WN21"); Map<String, List<String>> productSeasonalityRequest = new HashMap<>(); productSeasonalityRequest.put(seasons.get(0), productIds); Mockito.when(adminService.cnhProductWeightIsActive(Mockito.anyList(), Mockito.anyList())).thenReturn(true); Map<String, List<ProductSeasonality>> productSeasonalityMap = new HashMap<>(); List<ProductSeasonality> productSeasonalityResponseList = new ArrayList<>(); ProductSeasonality productSeasonalty = new ProductSeasonality(); productSeasonalty.setProductId("000000000060292784"); productSeasonalty.setProductType("Z001"); productSeasonalty.setStrokeNum("1400v"); productSeasonalty.setActiveVariantsCount(2); productSeasonalty.setDepartment("T11"); productSeasonalty.setPrimarySizeRange("ZS"); productSeasonalty.setSecondarySizeRange(""); productSeasonalty.setMerchandiseCat("A42030101"); productSeasonalty.setProductVariantsCount(2); Colour colour = new Colour(); colour.setColourCode("Z0"); colour.setColourDescription("White"); productSeasonalty.setColour(colour); ProductDescription productDescription = new ProductDescription(); productDescription.setLongDesc("10P Plain Briefs White"); productDescription.setShortDesc("10P Plain Briefs"); productSeasonalty.setProductDescription(productDescription); Hierarchy hierarchy = new Hierarchy(); hierarchy.setLevel("08"); hierarchy.setValue("G8-T0657"); productSeasonalty.setHierarchy(hierarchy); Seasons season = new Seasons(); season.setSeasonName("WN21"); season.setSeasonYear("2021"); productSeasonalty.setSeason(season); List<Attributes> AttList = new ArrayList<>(); Attributes att = new Attributes(); att.setAttDesc("M S BRAND"); att.setAttTypeDesc("BRANDS"); att.setAttDesc("jeans"); att.setAttTypeDesc("PRODUCT TYPE (C)"); AttList.add(att); productSeasonalty.setAttributes(AttList); List<ProductVariant> pvList = new ArrayList<>(); ProductVariant pv = new ProductVariant(); pv.setVariantId("000000060292784002"); pv.setPrimarySizeIndex("7"); pv.setPrimarySizeRange("ZS"); pv.setSecondarySizeIndex("01"); pv.setSecondarySizeRange("SZ"); pv.setActiveIndicator(1); pvList.add(pv); ProductVariant pv1 = new ProductVariant(); pv1.setVariantId("000000060292784004"); pv1.setPrimarySizeIndex("5"); pv1.setPrimarySizeRange("ZS"); pv1.setSecondarySizeIndex("01"); pv1.setSecondarySizeRange("SA"); pv1.setActiveIndicator(1); pvList.add(pv1); productSeasonalty.setProductVariants(pvList); productSeasonalityResponseList.add(productSeasonalty); Mockito.when(cnhService.getSeasonalityCollection(Mockito.any(),Mockito.anyList(), Mockito.anyList())) .thenReturn(productSeasonalityResponseList); Map<String, String> primarySizeDescMap = new HashMap<>(); primarySizeDescMap.put("000000060292784002", "2-3y"); primarySizeDescMap.put("000000060292784004", "4-9y"); Mockito.when(cnhService.getPrimarySizeData(Mockito.anyList(), Mockito.anyList())).thenReturn(primarySizeDescMap); Map<String, String> secondarySizeDescMap = new HashMap<>(); secondarySizeDescMap.put("000000060292784002", "32"); secondarySizeDescMap.put("000000060292784004", "34"); Mockito.when(cnhService.getSecondarySizeData(Mockito.anyList(), Mockito.anyList())).thenReturn(secondarySizeDescMap); AttrServiceResponse attrServiceResponse = new AttrServiceResponse(); attrServiceResponse.setPlanARawMaterial("Cotton"); attrServiceResponse.setProductShapeEcom("FitJeans"); Map<String, AttrServiceResponse> pdtIdnStyleEcomMap = new HashMap<>(); pdtIdnStyleEcomMap.put("000000000060292784", attrServiceResponse); Mockito.when(cnhService.getAttributes(Mockito.anyList(), Mockito.anyList(), Mockito.anyList())).thenReturn(pdtIdnStyleEcomMap); Map<Integer,String> countryCodeMap = new HashMap<>(); countryCodeMap.put(75, "DE"); Mockito.when(ibtService.getCountryCode(Mockito.anyList(), Mockito.anyList())).thenReturn(countryCodeMap); List<CooResponse> cooResponseList = new ArrayList<>(); CooResponse cooResponse = new CooResponse(); cooResponse.setCountryNum(75); cooResponse.setFranchiseNumber(8196); cooResponse.setProductId("000000000060292784"); cooResponse.setSeasonName("WN21"); cooResponseList.add(cooResponse); Map<Integer, List<CooResponse>> cooResponseMap = new HashMap<>(); cooResponseMap.put(8196, cooResponseList); Mockito.when(ibtService.getCOOForPartners(Mockito.anyList(), Mockito.anyList(), Mockito.anyMap())).thenReturn(cooResponseMap) ; ProductWeightRequest productWeightRequest = new ProductWeightRequest(); productWeightRequest.setProductIds(productIds); Mockito.when(cnhService.getProductWehightProductPackService(productWeightRequest)).thenReturn(generateCnhProductPackServiceResponse()); List<String> variantId = new ArrayList<>(); variantId.add("000000060292784002"); variantId.add("000000060292784004"); productSeasonalityMap.put("000000000060292784", productSeasonalityResponseList); // calling ES Service List<ProductSeasonality> variant = productSeasonalityMap.get(productIds); Map<String, ProductSeasonality> variantSeasonDataMap = new HashMap<>(); variantSeasonDataMap.put("000000000060292784", productSeasonalty); ProductSeasonality prductSeasonlity = variantSeasonDataMap.get(seasons); List<String> variantIds = new ArrayList<>(); variantIds.add("000000060292784002"); variantIds.add("000000060292784004"); List<Products> esSeriveResponse = new ArrayList<>(); Products product = new Products(); product.setParentProductId("000000000060292784"); product.setProductId("000000060292784002"); List<StrokeDescription> strokeDesc = new ArrayList<>(); StrokeDescription sd = new StrokeDescription(); sd.setDescription("10P Plain Briefs"); strokeDesc.add(sd); product.setStrokeDesc(strokeDesc); List<Version> version = new ArrayList<>(); Version versin = new Version(); versin.setVersion(0); Barcodes barcodes = new Barcodes(); List<String> UPC = new ArrayList<>(); UPC.add("23456"); barcodes.setUPC(UPC); List<String> EAN13 = new ArrayList<>(); EAN13.add("123456"); barcodes.setEAN13(EAN13); versin.setBarcodes(barcodes); version.add(versin); product.setVersion(version); Customs customs = new Customs(); customs.setCommodityCode("hsn"); product.setCustoms(customs); esSeriveResponse.add(product); Mockito.when(esService.getVariantCollection(Mockito.any(),Mockito.anyList(), Mockito.anyList())).thenReturn(esSeriveResponse); List<AdminServiceResponse> list1 = new ArrayList<>(); AdminServiceResponse objt = new AdminServiceResponse(); objt.setDestinationPath("absb"); objt.setFileNamePattern("filename"); objt.setFranchiseNumber(8196); objt.setLatestSeason(false); objt.setNoOfSeasonsBackward(0); objt.setNoOfSeasonsForward(0); objt.setQualifier("ordering"); list1.add(objt); Mockito.when(cnhService.getNextTwoSeasonFromCurrentSeason(Mockito.anyInt(),Mockito.anyInt(),Mockito.anyList(),Mockito.anyList())).thenReturn(seasons); Mockito.when(adminService.getDetailsForExtract(Mockito.anyList(), Mockito.anyList())).thenReturn(list1); Map<Integer, List<ProductDataResponse>> finalResponseMap = new HashMap<>(); finalResponseMap.put(8196, productResponseList); List<ProductStagingResponse> stageTableList = new ArrayList<>(); ProductStagingResponse response = new ProductStagingResponse(); response.setFranchiseNumber(8196); response.setProductId("000000000060292784"); response.setVariantIds(variantId); response.setSeason("WN21"); stageTableList.add(response); Mockito.when(subscriptionService.getProductsForExtract(Mockito.anyList(), Mockito.anyList())).thenReturn(stageTableList); Map<String, String> deptnCat = new HashMap<>(); deptnCat.put("T11", "KIDSWEAR"); Map<String,List<String>> requestMap = new HashMap<>(); requestMap.put("WN21", productIds); Mockito.lenient().when(adminService.getCategoryMapping(Constants.ZALANDO_FRANCHISE_NUMBER)).thenReturn(deptnCat); List<VariantCategoryDataEntity> variantLevelCategory = new ArrayList<>(); VariantCategoryDataEntity variantCategoryDataEntity = new VariantCategoryDataEntity(); variantCategoryDataEntity.setCategory("womens>clothing>jeans>FitJeans"); variantCategoryDataEntity.setProductVariantId("000000060292784004"); variantCategoryDataEntity.setFranchiseNumber(8196); variantLevelCategory.add(variantCategoryDataEntity); Mockito.lenient().when(variantCategoryDataRepository.findByFranchiseNumber(Constants.ZALANDO_FRANCHISE_NUMBER)) .thenReturn(variantLevelCategory); //doubt Map<String, Map<String, String>> sellingAttrMap = new HashMap<>(); Map<String, String> attrMap = new HashMap<String, String>(); attrMap.put(Constants.SUBSCRIBED_FIELD_PRODUCT_ID, "000000000060292784"); attrMap.put("CareInstruction", "Machine washable\\nTumble dry"); attrMap.put("Footwear_Sole", "Upper: Leather\\nLining and Sock: Textile\\nOutsole: Other materials"); sellingAttrMap.put("000000060292784002", attrMap); Mockito.lenient().when(sellingAttributeService.getSellingAttributeMap(Mockito.any(SellingAttributesRequest.class))) .thenReturn(sellingAttrMap); Mockito.lenient().when( blobUtils.uploadToFileShare(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.any())) .thenReturn(true); List<PartnerFieldSubscriptionResponse> list = new ArrayList<>(); PartnerFieldSubscriptionResponse partnerFieldSubscription = new PartnerFieldSubscriptionResponse(); partnerFieldSubscription.setFrachiseNumber(8196); partnerFieldSubscription.setSubscribedFields(Arrays.asList("strokeNo","dept","primSizeRange","secSizeRange","item","merchandCategory","productTypeC","planARawMaterial","productShapeEcom","colour","colourCode","colourDesc","productDesc","language","descriptions","descType","desc","seasons","seasonName","hsn","coo","variants","productVariantId","primSizeDesc","secSizeDesc","barcodes","Category","type","value","length","width","height","unitOfDimension","unitOfWeight","productWeight")); list.add(partnerFieldSubscription); List<ExtractorRequest> batchRequestList = new ArrayList<>(); ExtractorRequest batchRequest = new ExtractorRequest(); batchRequest.setBatchId(123); batchRequest.setFranchiseNumber(8196); batchRequestList.add(batchRequest); List<Integer> franchiseList = new ArrayList<Integer>(); franchiseList.add(8196); Mockito.lenient() .when(adminService.getSubscribeFieldsByExtractTypeId(Mockito.anyInt(), Mockito.any(), Mockito.any())) .thenReturn(list); boolean flagCount = processor.triggerProcess(requestList); Assertions.assertTrue(flagCount);} ......update this to get value in primsizedesc and secondarysizedesc in seasons arraylist of mapproductdataresponse....in productcoreprocessor code
- Assistant
Certainly! To ensure the
primarySizeDescandsecondarySizeDescvalues are populated in theseasonsarray list ofproductDataResponsewithin theProductCoreProcessor, we need to integrate this logic into the processor code effectively.Assuming you already have the context, here's a high-level idea on how to update the
ProductCoreProcessorclass. I will provide you with skeleton code encompassing how such integration might look like, especially related to your primary and secondary size descriptions.Update ProductCoreProcessor Code
First, ensure you have a
ProductDataResponseclass that has a property for seasons that can hold the size description values:public class ProductDataResponse { private List<SeasonData> seasons; // Getters and setters... public List<SeasonData> getSeasons() { return seasons; } public void setSeasons(List<SeasonData> seasons) { this.seasons = seasons; } // Additional fields... } public class SeasonData { private String seasonName; private String primarySizeDesc; private String secondarySizeDesc; // Getters and setters... public String getSeasonName() { return seasonName; } public void setSeasonName(String seasonName) { this.seasonName = seasonName; } public String getPrimarySizeDesc() { return primarySizeDesc; } public void setPrimarySizeDesc(String primarySizeDesc) { this.primarySizeDesc = primarySizeDesc; } public String getSecondarySizeDesc() { return secondarySizeDesc; } public void setSecondarySizeDesc(String secondarySizeDesc) { this.secondarySizeDesc = secondarySizeDesc; } }Then, you might need to modify the processing code in the
ProductCoreProcessorwhere you build theProductDataResponse. Here's a part of the method where you can capture size description and assign them to the respectiveSeasonDataobjects based on the seasonal data.Skeleton Code for Population Logic
public void processProductDetails(List<ExtractorRequest> requestList) { //... other processing logic ... for (ExtractorRequest request : requestList) { List<ProductDataResponse> productDataResponses = new ArrayList<>(); // Assuming you retrieve size descriptions in this part Map<String, String> primarySizeDescMap = getPrimarySizeDesc(); // Retrieve this from your service Map<String, String> secondarySizeDescMap = getSecondarySizeDesc(); // Retrieve this from your service // For each product in your response... for (String productId : productIds) { ProductDataResponse productDataResponse = new ProductDataResponse(); List<SeasonData> seasons = new ArrayList<>(); for (String season : seasonsList) { // Get seasons from your data SeasonData seasonData = new SeasonData(); seasonData.setSeasonName(season); seasonData.setPrimarySizeDesc(primarySizeDescMap.get(variantId)); // Replace with actual logic to get variantId seasonData.setSecondarySizeDesc(secondarySizeDescMap.get(variantId)); // Replace with actual logic to get variantId seasons.add(seasonData); } productDataResponse.setSeasons(seasons); productDataResponses.add(productDataResponse); } //... save or return the productDataResponses ... } }Test Method Adjustment
In your
processProductDetailsTestForInternationalPartnertest method, ensure that there are assertions or checks for the values in theProductDataResponseseasons list forprimarySizeDescandsecondarySizeDesc.Assertions.assertEquals("ExpectedPrimarySizeDesc", productResponse.getSeasons().get(0).getPrimarySizeDesc()); Assertions.assertEquals("ExpectedSecondarySizeDesc", productResponse.getSeasons().get(0).getSecondarySizeDesc());Conclusion
Make sure to adapt this skeleton code according to your actual existing code base structure, particularly in how you retrieve data and manage the maps. This modification should correctly capture the primary and secondary size descriptions in the
seasonsarray of yourProductDataResponse.