@Test public void checkProductVariantId() throws Exception { final String productId = "73f002a1-0c5a-4849-b985-fa1145a8c76d"; assertThat(productId.equals(lineItem.getProductId())); assertThat(productId.equals(productVariant.getIdentifier().getProductId())); }
@Test public void checkProductVariantId() throws Exception { final String productId = "73f002a1-0c5a-4849-b985-fa1145a8c76d"; assertThat(productId.equals(lineItem.getProductId())); assertThat(productId.equals(productVariant.getIdentifier().getProductId())); }
@Test public void variantIdentifierIsAvailable() throws Exception { withProduct(client(), product -> { final ByIdVariantIdentifier identifier = product.getMasterData().getStaged().getMasterVariant().getIdentifier(); assertThat(identifier).isEqualTo(ByIdVariantIdentifier.of(product.getId(), 1)); }); }
@Test public void uploadImage() { withUpdateableProduct(client(), product -> { final ByIdVariantIdentifier identifier = product.getMasterData().getStaged().getMasterVariant().getIdentifier(); File imageFile ; try{ imageFile = File.createTempFile("ct_logo_farbe",".gif"); imageFile.deleteOnExit(); byte[] fileBytes = IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("ct_logo_farbe.gif")); FileOutputStream outStream = new FileOutputStream(imageFile); outStream.write(fileBytes); outStream.close(); }catch(IOException e){ imageFile = new File("src/test/resources/ct_logo_farbe.gif"); } final ProductImageUploadCommand cmd = ProductImageUploadCommand .ofVariantId(imageFile, identifier) .withFilename("logo.gif") .withStaged(true); final Product updatedProduct = client().executeBlocking(cmd); final Image image = updatedProduct.getMasterData().getStaged().getMasterVariant().getImages().get(0); assertThat(image.getDimensions().getHeight()).isEqualTo(102); assertThat(image.getDimensions().getWidth()).isEqualTo(460); assertThat(image.getUrl()).contains("logo"); return updatedProduct; }); }
@Test public void addLineItem() throws Exception { withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).isEmpty(); final long quantity = 3; final String productId = product.getId(); final AddLineItem action = AddLineItem.of(productId, MASTER_VARIANT_ID, quantity); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, action)); assertThat(updatedCart.getLineItems()).hasSize(1); final LineItem lineItem = updatedCart.getLineItems().get(0); assertThat(lineItem.getName()).isEqualTo(product.getMasterData().getStaged().getName()); assertThat(lineItem.getQuantity()).isEqualTo(quantity); assertThat(lineItem.getProductSlug()).isEqualTo(product.getMasterData().getStaged().getSlug()); assertThat(lineItem.getVariant().getIdentifier()).isEqualTo(ByIdVariantIdentifier.of(lineItem.getProductId(), lineItem.getVariant().getId())); assertThat(lineItem.getDiscountedPricePerQuantity()).isNotNull().isEmpty(); }); }
@Test public void variantIdentifierIsAvailable() throws Exception { withProduct(client(), product -> { final Query<ProductProjection> query = ProductProjectionQuery.of(STAGED) .withPredicates(m -> m.id().is(product.getId())); final ProductProjection productProjection = client().executeBlocking(query).head().get(); final ByIdVariantIdentifier identifier = productProjection.getMasterVariant().getIdentifier(); assertThat(identifier).isEqualTo(ByIdVariantIdentifier.of(product.getId(), 1)); }); }
@Test public void giftLineItemCartDiscountValue() throws Exception { withProduct(client(), product -> { final ByIdVariantIdentifier variantId = product.getMasterData().getStaged().getMasterVariant().getIdentifier(); final GiftLineItemCartDiscountValue value = CartDiscountValue.ofGiftLineItem(variantId, null, null); checkCreation(builder -> builder.value(value).target(null), discount -> { assertThat(discount.getValue()).isEqualTo(value); assertThat(((GiftLineItemCartDiscountValue)discount.getValue()).getProduct()).isInstanceOf(ResourceIdentifier.class); } ); }); }
@Test public void addLineItemOfDraftOfVariantIdentifier() throws Exception { withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).isEmpty(); final long quantity = 3; final Channel inventorySupplyChannel = ChannelFixtures.persistentChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY); final Channel distributionChannel = ChannelFixtures.persistentChannelOfRole(client(), ChannelRole.PRODUCT_DISTRIBUTION); ByIdVariantIdentifier variantIdentifier = product.getMasterData().getStaged().getMasterVariant().getIdentifier(); final LineItemDraft lineItemDraft = io.sphere.sdk.carts.LineItemDraftBuilder.ofVariantIdentifier(variantIdentifier, quantity) .distributionChannel(distributionChannel) .supplyChannel(inventorySupplyChannel) .build(); final AddLineItem action = AddLineItem.of(lineItemDraft); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, action)); assertThat(updatedCart.getLineItems()).hasSize(1); final LineItem lineItem = updatedCart.getLineItems().get(0); assertThat(lineItem.getName()).isEqualTo(product.getMasterData().getStaged().getName()); assertThat(lineItem.getQuantity()).isEqualTo(quantity); assertThat(lineItem.getProductSlug()).isEqualTo(product.getMasterData().getStaged().getSlug()); assertThat(lineItem.getVariant().getIdentifier()).isEqualTo(ByIdVariantIdentifier.of(lineItem.getProductId(), lineItem.getVariant().getId())); assertThat(lineItem.getSupplyChannel().toReference()).isEqualTo(inventorySupplyChannel.toReference()); assertThat(lineItem.getDistributionChannel().toReference()).isEqualTo(distributionChannel.toReference()); assertThat(lineItem.getDiscountedPricePerQuantity()).isNotNull().isEmpty(); }); }
@Test public void addLineItemOfDraftOfSku() throws Exception { withEmptyCartAndProduct(client(), (cart, product) -> { assertThat(cart.getLineItems()).isEmpty(); final long quantity = 3; final Channel inventorySupplyChannel = ChannelFixtures.persistentChannelOfRole(client(), ChannelRole.INVENTORY_SUPPLY); final Channel distributionChannel = ChannelFixtures.persistentChannelOfRole(client(), ChannelRole.PRODUCT_DISTRIBUTION); final String sku = product.getMasterData().getStaged().getMasterVariant().getSku(); final LineItemDraft lineItemDraft = io.sphere.sdk.carts.LineItemDraftBuilder.ofSku(sku, quantity) .distributionChannel(distributionChannel) .supplyChannel(inventorySupplyChannel) .build(); final AddLineItem action = AddLineItem.of(lineItemDraft); final Cart updatedCart = client().executeBlocking(CartUpdateCommand.of(cart, action)); assertThat(updatedCart.getLineItems()).hasSize(1); final LineItem lineItem = updatedCart.getLineItems().get(0); assertThat(lineItem.getName()).isEqualTo(product.getMasterData().getStaged().getName()); assertThat(lineItem.getQuantity()).isEqualTo(quantity); assertThat(lineItem.getProductSlug()).isEqualTo(product.getMasterData().getStaged().getSlug()); assertThat(lineItem.getVariant().getIdentifier()).isEqualTo(ByIdVariantIdentifier.of(lineItem.getProductId(), lineItem.getVariant().getId())); assertThat(lineItem.getSupplyChannel().toReference()).isEqualTo(inventorySupplyChannel.toReference()); assertThat(lineItem.getDistributionChannel().toReference()).isEqualTo(distributionChannel.toReference()); assertThat(lineItem.getDiscountedPricePerQuantity()).isNotNull().isEmpty(); }); }
@Test(expected = IllegalStateException.class) public void uploadInvalidImageType() { withUpdateableProduct(client(), product -> { final ByIdVariantIdentifier identifier = product.getMasterData().getStaged().getMasterVariant().getIdentifier(); final ProductImageUploadCommand cmd = ProductImageUploadCommand .ofVariantId(new File("src/test/resources/ct_logo_farbe.bmp"), identifier) .withFilename("logo.bmp") .withStaged(true); final Product updatedProduct = client().executeBlocking(cmd); return updatedProduct; }); } }
withTaxedProduct(client(), product3 -> { final LineItemDraft lineItemDraft1 = LineItemDraft.of(product1, 1, 15); final LineItemDraft lineItemDraftOfVariantIdentifier = LineItemDraftBuilder.ofVariantIdentifier(product2.getMasterData().getStaged().getMasterVariant().getIdentifier(), 25L).build(); String sku = product3.getMasterData().getStaged().getMasterVariant().getSku(); final LineItemDraft lineItemDraftOfSku = LineItemDraftBuilder.ofSkuVariantIdentifier(BySkuVariantIdentifier.of(sku), 35L).build();