public Builder toBuilder() { return builder().fromProductItemPrice(this); }
public Builder toBuilder() { return builder().fromProductItemPrice(this); }
public Builder toBuilder() { return builder().fromProductItemPrice(this); }
@Override public ProductItemPrice apply(String arg0) { return ProductItemPrice.builder().id(Integer.parseInt(arg0)).build(); } });
@Override public ProductItemPrice apply(String arg0) { return ProductItemPrice.builder().id(Integer.parseInt(arg0)).build(); } });
private Iterable<ProductItemPrice> getPrices(Template template) { Builder<ProductItemPrice> result = ImmutableSet.builder(); int imageId = Integer.parseInt(template.getImage().getId()); result.add(ProductItemPrice.builder().id(imageId).build()); Iterable<String> hardwareIds = Splitter.on(",").split(template.getHardware().getId()); for (String hardwareId : hardwareIds) { int id = Integer.parseInt(hardwareId); result.add(ProductItemPrice.builder().id(id).build()); } ProductItem uplinkItem = find(productPackageSupplier.get().getItems(), and(capacity(portSpeed), categoryCode("port_speed"))); result.add(get(uplinkItem.getPrices(), 0)); result.addAll(prices); return result.build(); }
private Iterable<ProductItemPrice> getPrices(Template template) { Builder<ProductItemPrice> result = ImmutableSet.builder(); int imageId = Integer.parseInt(template.getImage().getId()); result.add(ProductItemPrice.builder().id(imageId).build()); Iterable<String> hardwareIds = Splitter.on(",").split(template.getHardware().getId()); for (String hardwareId : hardwareIds) { int id = Integer.parseInt(hardwareId); result.add(ProductItemPrice.builder().id(id).build()); } ProductItem uplinkItem = find(productPackageSupplier.get().getItems(), and(capacity(portSpeed), categoryCode("port_speed"))); result.add(get(uplinkItem.getPrices(), 0)); result.addAll(prices); return result.build(); }
@Test public void testPriceMultiplePrices() { ImmutableSet<ProductItemPrice> prices = ImmutableSet.of(price, ProductItemPrice.builder().id(2).build()); ProductItem item2 = ProductItem.builder().prices(prices).build(); assertEquals(price().apply(item2),price); }
@Test public void testItemCallGetsCategory() { ProductItemPrice price = ProductItemPrice.builder().id(1) .categories(category) .item(item) .build(); ProductItem newItem = item().apply(price); assertEquals(newItem.getCategories(), ImmutableSet.of(category)); }
@Test public void testIdManyPrices() { ProductItemPrice price1 = ProductItemPrice.builder().id(1234).build(); ProductItemPrice price2 = ProductItemPrice.builder().id(5678).build(); ProductItem item = ProductItem.builder().prices(ImmutableSet.of(price1,price2)).build(); assertEquals("1234",imageId().apply(item)); }
@Test public void testItemCallNoCategoryOnPrice() { ProductItem item1 = item.toBuilder().categories(ImmutableSet.of(category)).build(); ProductItemPrice price = ProductItemPrice.builder().id(1) .item(item1) .build(); ProductItem newItem = item().apply(price); assertEquals(newItem.getCategories(), ImmutableSet.of(category)); }
@Test public void testId() { ProductItemPrice price = ProductItemPrice.builder().id(1234).build(); ProductItem item = ProductItem.builder().prices(price).build(); assertEquals("1234",imageId().apply(item)); }
@Test public void testHardwareId() { ProductItem item1 = ProductItem.builder().prices(ProductItemPrice.builder().id(123).build()).build(); ProductItem item2 = ProductItem.builder().prices(ProductItemPrice.builder().id(456).build()).build(); ProductItem item3 = ProductItem.builder().prices(ProductItemPrice.builder().id(789).build()).build(); String id = hardwareId().apply(ImmutableList.of(item1, item2, item3)); assertEquals("123,456,789", id); }
@Test public void testItemCallCategoryExists() { ProductItemCategory category2 = ProductItemCategory.builder() .id(12) .categoryCode("new category") .build(); ProductItem item1 = item.toBuilder().categories(ImmutableSet.of(category2)).build(); ProductItemPrice price = ProductItemPrice.builder().id(1) .categories(category) .item(item1) .build(); ProductItem newItem = item().apply(price); assertEquals(newItem.getCategories(), ImmutableSet.of(category2)); }
@Test(expectedExceptions = NullPointerException.class) public void testNoDescription() { ProductItem item = ProductItem.builder() .prices(ProductItemPrice.builder().id(1234).build()) .build(); new ProductItemToImage().apply(item); }
@BeforeMethod public void setup() { category = ProductItemCategory.builder().id(1).categoryCode("category").build(); price = ProductItemPrice.builder().id(1).build(); item = ProductItem.builder().id(1) .capacity(2.0f) .description("an item") .prices(price) .build(); }
@Test public void test64BitUnknown() { ProductItem item = ProductItem.builder() .description("This only has the bit-count (64 bit)") .prices(ProductItemPrice.builder().id(1234).build()) .build(); Image i = new ProductItemToImage().apply(item); OperatingSystem os = i.getOperatingSystem(); assertNotNull(os); assertEquals(OsFamily.UNRECOGNIZED, os.getFamily()); assertNull(os.getVersion()); assertTrue(os.is64Bit()); }
@Test public void testUbuntuNoBitCount() { ProductItem item = ProductItem.builder() .description("Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install") .prices(ProductItemPrice.builder().id(1234).build()) .build(); Image i = new ProductItemToImage().apply(item); OperatingSystem os = i.getOperatingSystem(); assertNotNull(os); assertEquals(OsFamily.UBUNTU, os.getFamily()); assertEquals("10.04",os.getVersion()); assertFalse(os.is64Bit()); }
@Test public void testUbuntu() { ProductItem item = ProductItem.builder() .description("Ubuntu Linux 10.04 LTS Lucid Lynx - Minimal Install (64 bit)") .prices(ProductItemPrice.builder().id(1234).build()) .build(); Image i = new ProductItemToImage().apply(item); OperatingSystem os = i.getOperatingSystem(); assertNotNull(os); assertEquals(OsFamily.UBUNTU, os.getFamily()); assertEquals("10.04",os.getVersion()); assertTrue(os.is64Bit()); }
@Test public void testCompletelyUnknown() { ProductItem item = ProductItem.builder() .description("This fails to match anything!!!") .prices(ProductItemPrice.builder().id(1234).build()) .build(); Image i = new ProductItemToImage().apply(item); OperatingSystem os = i.getOperatingSystem(); assertNotNull(os); assertEquals(OsFamily.UNRECOGNIZED, os.getFamily()); assertNull(os.getVersion()); assertFalse(os.is64Bit()); }