Search in sources :

Example 6 with PersistableShoppingCartItem

use of com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem in project shopizer by shopizer-ecommerce.

the class ShoppingCartAPIIntegrationTest method addSecondToCart.

/**
 * Add an second Item to existing Cart, should give HTTP 201 & 2 qty
 *
 * @throws Exception
 */
@Test
@Order(2)
public void addSecondToCart() throws Exception {
    ReadableProduct product = sampleProduct("add2Cart");
    assertNotNull(product);
    data.getProducts().add(product);
    PersistableShoppingCartItem cartItem = new PersistableShoppingCartItem();
    cartItem.setProduct(product.getId());
    cartItem.setQuantity(1);
    final HttpEntity<PersistableShoppingCartItem> cartEntity = new HttpEntity<>(cartItem, getHeader());
    final ResponseEntity<ReadableShoppingCart> response = testRestTemplate.exchange(String.format("/api/v1/cart/" + String.valueOf(data.getCartId())), HttpMethod.PUT, cartEntity, ReadableShoppingCart.class);
    assertNotNull(response);
    assertThat(response.getStatusCode(), is(CREATED));
    assertEquals(response.getBody().getQuantity(), 2);
}
Also used : HttpEntity(org.springframework.http.HttpEntity) PersistableShoppingCartItem(com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with PersistableShoppingCartItem

use of com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem in project shopizer by shopizer-ecommerce.

the class ShoppingCartAPIIntegrationTest method updateMultiWZeroOnOneProd.

/**
 * Update cart with qnt 0 on one cart item which gives 3 qty left
 *
 * @throws Exception
 */
@Test
@Order(5)
public void updateMultiWZeroOnOneProd() throws Exception {
    PersistableShoppingCartItem cartItem1 = new PersistableShoppingCartItem();
    cartItem1.setProduct(data.getProducts().get(0).getId());
    cartItem1.setQuantity(0);
    PersistableShoppingCartItem[] productsQtyUpdates = { cartItem1 };
    final HttpEntity<PersistableShoppingCartItem[]> cartEntity = new HttpEntity<>(productsQtyUpdates, getHeader());
    final ResponseEntity<ReadableShoppingCart> response = testRestTemplate.exchange(String.format("/api/v1/cart/" + data.getCartId() + "/multi"), HttpMethod.POST, cartEntity, ReadableShoppingCart.class);
    assertNotNull(response);
    assertThat(response.getStatusCode(), is(CREATED));
    assertEquals(3, response.getBody().getQuantity());
}
Also used : HttpEntity(org.springframework.http.HttpEntity) PersistableShoppingCartItem(com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with PersistableShoppingCartItem

use of com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem in project shopizer by shopizer-ecommerce.

the class ShoppingCartAPIIntegrationTest method addToWrongToCartId.

/**
 * Add an other item to cart which then does not exist which should return HTTP 404
 *
 * @throws Exception
 */
@Test
@Order(3)
public void addToWrongToCartId() throws Exception {
    ReadableProduct product = sampleProduct("add3Cart");
    assertNotNull(product);
    data.getProducts().add(product);
    PersistableShoppingCartItem cartItem = new PersistableShoppingCartItem();
    cartItem.setProduct(product.getId());
    cartItem.setQuantity(1);
    final HttpEntity<PersistableShoppingCartItem> cartEntity = new HttpEntity<>(cartItem, getHeader());
    final ResponseEntity<ReadableShoppingCart> response = testRestTemplate.exchange(String.format("/api/v1/cart/" + data.getCartId() + "breakIt"), HttpMethod.PUT, cartEntity, ReadableShoppingCart.class);
    assertNotNull(response);
    assertThat(response.getStatusCode(), is(NOT_FOUND));
}
Also used : HttpEntity(org.springframework.http.HttpEntity) PersistableShoppingCartItem(com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem) ReadableShoppingCart(com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart) ReadableProduct(com.salesmanager.shop.model.catalog.product.ReadableProduct) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

PersistableShoppingCartItem (com.salesmanager.shop.model.shoppingcart.PersistableShoppingCartItem)8 ReadableShoppingCart (com.salesmanager.shop.model.shoppingcart.ReadableShoppingCart)8 HttpEntity (org.springframework.http.HttpEntity)6 Order (org.junit.jupiter.api.Order)5 Test (org.junit.jupiter.api.Test)5 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 ReadableProduct (com.salesmanager.shop.model.catalog.product.ReadableProduct)4 ShoppingCartItem (com.salesmanager.shop.model.shoppingcart.ShoppingCartItem)2 LocalDate (java.time.LocalDate)2 Date (java.util.Date)2 HashSet (java.util.HashSet)2 ServiceException (com.salesmanager.core.business.exception.ServiceException)1 PricingService (com.salesmanager.core.business.services.catalog.product.PricingService)1 ProductService (com.salesmanager.core.business.services.catalog.product.ProductService)1 ProductAttributeService (com.salesmanager.core.business.services.catalog.product.attribute.ProductAttributeService)1 ShoppingCartCalculationService (com.salesmanager.core.business.services.shoppingcart.ShoppingCartCalculationService)1 ShoppingCartService (com.salesmanager.core.business.services.shoppingcart.ShoppingCartService)1 ProductPriceUtils (com.salesmanager.core.business.utils.ProductPriceUtils)1 Product (com.salesmanager.core.model.catalog.product.Product)1