@Test public void checkProductVaiantAtributes() throws Exception { assertThat(productVariant.getSku().equals("1f92d491-2180-489c-bcef-3966cdc68c0b")); assertThat(productVariant.getPrices()) .as("comparing prices ") .isEqualTo(asList(Price.of(BigDecimal.valueOf(12.34), DefaultCurrencyUnits.EUR).withCountry(CountryCode.DE).withId("70a56289-bd20-4c47-8364-47b498ad993b"))); assertThat(productVariant.getImages().isEmpty()); assertThat(productVariant.getAssets().isEmpty()); assertThat(productVariant.getAttributes().isEmpty()); } }
@Test public void checkProductVaiantAtributes() throws Exception { assertThat(productVariant.getSku().equals("1f92d491-2180-489c-bcef-3966cdc68c0b")); assertThat(productVariant.getPrices()) .as("comparing prices ") .isEqualTo(asList(Price.of(BigDecimal.valueOf(12.34), DefaultCurrencyUnits.EUR).withCountry(CountryCode.DE).withId("70a56289-bd20-4c47-8364-47b498ad993b"))); assertThat(productVariant.getImages().isEmpty()); assertThat(productVariant.getAssets().isEmpty()); assertThat(productVariant.getAttributes().isEmpty()); } }
private void locationCheck(final Location searchLocation, final Zone ... expected) { final PagedQueryResult<Zone> result = client().executeBlocking(ZoneQuery.of().byLocation(searchLocation)); final Set<Zone> actual = new HashSet<>(result.getResults()); assertThat(actual).isEqualTo(new HashSet<>(asList(expected))); } }
@Test public void testExtensionForOrder(){ ExtensionResourceType extensionResourceType = ExtensionResourceType.ORDER; final List<Trigger> triggers = asList(TriggerBuilder.of(extensionResourceType, asList(TriggerType.CREATE, TriggerType.UPDATE)).build()); final Destination destination =getDestination(); withExtensionDraft(client(), ExtensionDraftBuilder.of(randomKey(), destination, triggers).build(), extension -> { assertThat(extension.getTriggers()).hasSize(1); assertThat(extension.getTriggers().get(0).getResourceTypeId()).isEqualByComparingTo(extensionResourceType); return extension; }); }
@Test public void sortProductProjectionsOnSearchByCategory1() { final Comparator<ProductProjection> comparator = comparingCategoryOrderHints(category1Id); final List<String> expectedOrder = asList(id1, id3, id2, id5, id4); assertWithQueryResult(result -> { assertThat(productProjectionsSortedBy(result.productProjections, comparator)).isEqualTo(expectedOrder); assertThat(result.sortedFromSearchForCategory1).extracting("id").as("search").isEqualTo(expectedOrder); }); }
@Test public void changeTriggers(){ withExtension(client(), extension -> { final List<Trigger> triggers = asList(TriggerBuilder.of(ExtensionResourceType.CART, asList(TriggerType.CREATE)).build()); Extension updatedExtension = client().executeBlocking(ExtensionUpdateCommand.of(extension, ChangeTriggers.of(triggers))); assertThat(updatedExtension.getTriggers()).containsAll(triggers); return updatedExtension; }); }
public static void withUpdateableShippingMethod(final BlockingSphereClient client, final UnaryOperator<ShippingMethodDraftBuilder> builderMapper, final Function<ShippingMethod, ShippingMethod> f) { withTaxCategory(client, taxCategory -> { final ShippingMethodDraftBuilder builder = ShippingMethodDraftBuilder.of(randomString(), "test shipping method", taxCategory.toReference(), asList(), false); final ShippingMethodDraft draft = builderMapper.apply(builder).build(); final ShippingMethod shippingMethod = client.executeBlocking(ShippingMethodCreateCommand.of(draft)); final ShippingMethod possiblyUpdatedShippingMethod = f.apply(shippingMethod); client.executeBlocking(ShippingMethodDeleteCommand.of(possiblyUpdatedShippingMethod)); }); }
@Test public void changeGroups() throws Exception { withPersistentDiscountCode(client(), discountCode -> { final long maxApplications = randomLong(); final String GROUP_NAME = "GroupName"; final DiscountCode updatedDiscountCode = client().executeBlocking(DiscountCodeUpdateCommand.of(discountCode, ChangeGroups.of(asList(GROUP_NAME)))); assertThat(updatedDiscountCode.getGroups()).containsExactly(GROUP_NAME); }); }
@Test public void changeValidFromUntil() throws Exception { withPersistentCartDiscount(client(), cartDiscount -> { final ZonedDateTime start = ZonedDateTime.parse("2015-07-09T07:46:40.230Z"); final ZonedDateTime end = start.plusYears(100); final CartDiscount updatedDiscount = client().executeBlocking(CartDiscountUpdateCommand.of(cartDiscount, asList(SetValidFrom.of(start),SetValidUntil.of(end)))); assertThat(updatedDiscount.getValidFrom()).isEqualTo(start); assertThat(updatedDiscount.getValidUntil()).isEqualTo(end); }); }
public static ShoppingListDraftDsl newShoppingListDraftWithTextLineItem(final Long quantity) { final List<TextLineItemDraft> textLineItemDrafts = asList( TextLineItemDraftBuilder.of(en(randomString()), quantity).build()); final ShoppingListDraftDsl shoppingListDraft = newShoppingListDraftBuilder().textLineItems(textLineItemDrafts).build(); return shoppingListDraft; }
public static ShoppingListDraftDsl newShoppingListDraftWithLineItem(final Product product, final Long quantity) { final List<LineItemDraft> lineItemDrafts = asList( LineItemDraftBuilder.of(product.getId()).quantity(quantity).build()); final ShoppingListDraftDsl shoppingListDraft = newShoppingListDraftBuilder().lineItems(lineItemDrafts).build(); return shoppingListDraft; }
@Test public void addExternalImage() throws Exception { withUpdateableProduct(client(), (Product product) -> { assertThat(product.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); final Image image = createExternalImage(); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.of(image, MASTER_VARIANT_ID))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); return updatedProduct; }); }
@Test public void selectAPriceByCurrencyInProductProjectionByIdGet() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductProjectionByIdGet request = ProductProjectionByIdGet.ofStaged(product) .withPriceSelection(PriceSelection.of(EUR));//price selection config final ProductProjection result = client().executeBlocking(request); final ProductVariant masterVariant = result.getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test public void selectAPriceByCurrencyInProductByIdGet() { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); withProductOfPrices(prices, product -> { final ProductByIdGet request = ProductByIdGet.of(product) .withPriceSelection(PriceSelection.of(EUR));//price selection config final Product result = client().executeBlocking(request); final ProductVariant masterVariant = result.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
public static ProductType productReferenceProductType(final BlockingSphereClient client) { final AttributeDefinition productReferenceDefinition = AttributeDefinitionBuilder .of("productreference", en("suggested product"), ReferenceAttributeType.ofProduct()) .required(true) .build(); final ProductTypeDraft productTypeDraft = ProductTypeDraft.of(randomKey(), productReferenceProductTypeName, "has an attribute which is reference to a product", asList(productReferenceDefinition)); final Optional<ProductType> productTypeOptional = client.executeBlocking(ProductTypeQuery.of().byName(productReferenceProductTypeName)).head(); return productTypeOptional.orElseGet(() -> client.executeBlocking(ProductTypeCreateCommand.of(productTypeDraft))); }
@Test public void removeImageByVariantId() throws Exception { final Image image = createExternalImage(); withUpdateableProduct(client(), product -> { final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofVariantId(MASTER_VARIANT_ID, image))); assertThat(productWithImage.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithImage, RemoveImage.ofVariantId(MASTER_VARIANT_ID, image))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); return updatedProduct; }); }
@Test public void selectAPriceByCurrencyInProductUpdateCommand() { ProductFixtures.withProduct(client(), product -> { final List<PriceDraft> prices = asList(PriceDraft.of(EURO_30), PriceDraft.of(USD_20)); final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, SetPrices.of(1, prices)) .withPriceSelection(PriceSelection.of(EUR)); final Product updatedProduct = client().executeBlocking(cmd); final ProductVariant masterVariant = updatedProduct.getMasterData().getStaged().getMasterVariant(); assertThat(masterVariant.getPrice()).isNotNull().has(price(PriceDraft.of(EURO_30))); }); }
@Test public void byCountry() throws Exception { ZoneFixtures.withUpdateableZone(client(), zoneA -> { ZoneFixtures.withUpdateableZone(client(), zoneB -> { final Set<Location> locations = zoneA.getLocations(); final PagedQueryResult<Zone> result = client().executeBlocking(ZoneQuery.of().byCountry(oneOf(locations).getCountry())); assertThat(result.getResults()).isEqualTo(asList(zoneA)); return zoneB; }, CF); return zoneA; }, CG); }
@Test public void removeImageBySku() throws Exception { final Image image = createExternalImage(); withUpdateableProduct(client(), product -> { final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final Product productWithImage = client().executeBlocking(ProductUpdateCommand.of(product, AddExternalImage.ofSku(sku, image))); assertThat(productWithImage.getMasterData().getStaged().getMasterVariant().getImages()).isEqualTo(asList(image)); final Product updatedProduct = client().executeBlocking(ProductUpdateCommand.of(productWithImage, RemoveImage.ofSku(sku, image))); assertThat(updatedProduct.getMasterData().getStaged().getMasterVariant().getImages()).hasSize(0); return updatedProduct; }); }
public static TypeDraftBuilder createTypeDraftBuilder() { final String typeKey = randomKey(); return TypeDraftBuilder.of(typeKey, en(TYPE_NAME), TYPE_IDS) .description(en("description")) .fieldDefinitions(asList(stringfieldDefinition(), enumFieldDefinition(), localizedEnumFieldDefinition(), catRefDefinition(), booleanDefinition(), LocalizedStringDefinition(), intDefinition(), doubleDefinition(), bigDecimalDefinition(), moneyDefinition(), dateDefinition(), dateTimeDefinition(), timeDefinition(), stringSetDefinition())); }