Examples of CartDto


Examples of org.multibit.mbm.client.interfaces.rest.api.cart.CartDto

  @Test
  public void retrieveCartNoItems() throws Exception {

    // Arrange
    final CartDto expectedCart = new CartDto();
    expectedCart.setItemTotal("2");

    final UserDto clientUser = new UserDto();
    clientUser.setApiKey("apiKey");
    clientUser.setSecretKey("secretKey");

    URI expectedUri = URI.create("http://localhost:8080/mbm/cart");

    // Test-specific JerseyClient behaviour
    when(client.resource(expectedUri))
      .thenReturn(webResource);
    when(webResource.get(String.class))
      .thenReturn(FixtureAsserts.jsonFixture("/fixtures/hal/cart/expected-public-retrieve-cart.json"));

    // Act
    CartDto actualCart = PublicMerchantClient
      .newInstance(locale)
      .cart()
      .retrieveCartNoItems(clientUser);

    // Assert
    assertEquals("Unexpected item count", "2", actualCart.getItemTotal());

  }
View Full Code Here

Examples of org.multibit.mbm.client.interfaces.rest.api.cart.CartDto

  @Test
  public void retrieveCart() throws Exception {

    // Arrange
    final CartDto expectedCart = new CartDto();
    expectedCart.setItemTotal("2");

    final UserDto clientUser = new UserDto();
    clientUser.setApiKey("apiKey");
    clientUser.setSecretKey("secretKey");

    URI expectedUri = URI.create("http://localhost:8080/mbm/cart");

    // Test-specific JerseyClient behaviour
    when(client.resource(expectedUri))
      .thenReturn(webResource);
    when(webResource.get(String.class))
      .thenReturn(FixtureAsserts.jsonFixture("/fixtures/hal/cart/expected-public-retrieve-cart.json"));

    // Act
    CartDto actualCart = PublicMerchantClient
      .newInstance(locale)
      .cart()
      .retrieveCart(clientUser);

    // Assert
    assertEquals("Unexpected item count", "2", actualCart.getItemTotal());

  }
View Full Code Here

Examples of org.multibit.mbm.client.interfaces.rest.api.cart.CartDto

  @Test
  public void updateCartItems() throws Exception {

    // Arrange
    final CartDto expectedCart = new CartDto();
    expectedCart.setItemTotal("2");

    final UserDto clientUser = new UserDto();
    clientUser.setApiKey("apiKey");
    clientUser.setSecretKey("secretKey");

    URI expectedUri = URI.create("http://localhost:8080/mbm/cart");

    // Test-specific JerseyClient behaviour
    when(client.resource(expectedUri))
      .thenReturn(webResource);
    // Use builder since it is a PUT
    when(builder.put(String.class))
      .thenReturn(FixtureAsserts.jsonFixture("/fixtures/hal/cart/expected-public-update-cart.json"));

    // Act
    List<PublicCartItemDto> cartItems = Lists.newArrayList();

    CartDto actualCart = PublicMerchantClient
      .newInstance(locale)
      .cart()
      .updateCartItems(clientUser, cartItems);

    // Assert
    assertEquals("Unexpected item count", "2", actualCart.getItemTotal());

  }
View Full Code Here

Examples of org.multibit.mbm.client.interfaces.rest.api.cart.CartDto

   * @return A ClientCart with all items populated
   */
  private CartDto buildClientCart(ReadableRepresentation rr, Map<String, Object> properties) {

    // Build the basic cart
    CartDto clientCart = buildClientCartNoItems(properties);

    // Read the cart items
    Collection<Map.Entry<String,ReadableRepresentation>> cartitemRepresentations = rr.getResources();

    for (Map.Entry<String, ReadableRepresentation> cartItemRepresentation : cartitemRepresentations) {

      CartItemDto cartItem = buildClientCartItem(cartItemRepresentation.getValue().getProperties());

      // Extract the embedded item
      Preconditions.checkArgument(cartItemRepresentation.getValue().getResources().size()==1);

      // TODO Fix or replace this
      //Representation itemRepresentation = cartItemRepresentation.getValue().getResources().iterator().next().getValue();
      //List<Link> links = itemRepresentation.getLinks();

      //cartItem.setItem(ClientItemHandler.buildClientItem(itemRepresentation.getProperties(), links));

      clientCart.getCartItems().add(cartItem);

    }

    return clientCart;
  }
View Full Code Here

Examples of org.multibit.mbm.client.interfaces.rest.api.cart.CartDto

   *
   * @return A ClientCart with no items populated
   */
  public static CartDto buildClientCartNoItems(Map<String, Object> properties) {

    CartDto cart = new CartDto();

    cart.setCurrencySymbol(getMandatoryPropertyAsString("currency_symbol", properties));
    cart.setCurrencyCode(getMandatoryPropertyAsString("currency_code", properties));
    cart.setPriceTotal(getMandatoryPropertyAsString("price_total", properties));
    cart.setItemTotal(getMandatoryPropertyAsString("item_total", properties));
    cart.setQuantityTotal(getMandatoryPropertyAsString("quantity_total", properties));

    return cart;
  }
View Full Code Here

Examples of org.multibit.mbm.client.interfaces.rest.api.cart.CartDto

public class CopyCart implements DomainAdapter<CartDto, Cart> {

  @Override
  public CartDto on(Cart cart) {

    CartDto dto = new CartDto();

    dto.setId(cart.getId());
    dto.setItemTotal(String.valueOf(cart.getItemTotal()));
    dto.setQuantityTotal(String.valueOf(cart.getQuantityTotal()));

    // TODO Need to inject these
    dto.setCurrencyCode("BTC");
    dto.setCurrencySymbol("Ƀ");

    return dto;
  }
View Full Code Here

Examples of org.multibit.mbm.client.interfaces.rest.api.cart.CartDto

   * @return A ClientCart with all items populated
   */
  private CartDto buildClientCart(ReadableRepresentation rr, Map<String, Object> properties) {

    // Build the basic cart
    CartDto clientCart = buildClientCartNoItems(properties);

    // Read the cart items
    Collection<Map.Entry<String, ReadableRepresentation>> cartitemResources = rr.getResources();

    for (Map.Entry<String, ReadableRepresentation> cartItemResource : cartitemResources) {

      CartItemDto cartItem = buildClientCartItem(cartItemResource.getValue().getProperties());

      // Extract the embedded item
      Preconditions.checkArgument(cartItemResource.getValue().getResources().size()==1);

      // TODO Fix or replace this
      //Representation itemResource = cartItemResource.getValue().getResources().iterator().next().getValue();
      //List<Link> links = itemResource.getLinks();

      //cartItem.setItem(ClientItemHandler.buildClientItem(itemResource.getProperties(), links));

      clientCart.getCartItems().add(cartItem);

    }

    return clientCart;
  }
View Full Code Here

Examples of org.multibit.mbm.client.interfaces.rest.api.cart.CartDto

   *
   * @return A ClientCart with no items populated
   */
  public static CartDto buildClientCartNoItems(Map<String, Object> properties) {

    CartDto clientCart = new CartDto();

    clientCart.setCurrencySymbol(getMandatoryPropertyAsString("currency_symbol", properties));
    clientCart.setCurrencyCode(getMandatoryPropertyAsString("currency_code", properties));
    clientCart.setPriceTotal(getMandatoryPropertyAsString("price_total", properties));
    clientCart.setItemTotal(getMandatoryPropertyAsString("item_total", properties));
    clientCart.setQuantityTotal(getMandatoryPropertyAsString("quantity_total", properties));

    return clientCart;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.