CentralViewResolverProductImpl implements CentralViewResolver { @Override public Pair<String, String> resolveMainPanelRendererLabel(final Map parameters) { if (parameters.containsKey(WebParametersKeys.SKU_ID)) { final long skuId = NumberUtils.toLong(HttpUtil.getSingleValue(parameters.get(WebParametersKeys.SKU_ID))); if (skuId > 0L) { final ProductSku sku = productService.getSkuById(skuId, true); if (sku != null) { final String template = sku.getProduct().getProducttype().getUitemplate(); if (StringUtils.isNotBlank(template)) { return new Pair<>(template, CentralViewLabel.SKU); } return DEFAULT_S; } } } else if (parameters.containsKey(WebParametersKeys.PRODUCT_ID)) { final long prodId = NumberUtils.toLong(HttpUtil.getSingleValue(parameters.get(WebParametersKeys.PRODUCT_ID))); if (prodId > 0L) { final Product product = productService.getProductById(prodId, true); if (product != null) { final String template = product.getProducttype().getUitemplate(); if (StringUtils.isNotBlank(template)) { return new Pair<>(template, CentralViewLabel.PRODUCT); } return DEFAULT_P; } } } return null; } CentralViewResolverProductImpl(final ProductService productService); @Override Pair<String, String> resolveMainPanelRendererLabel(final Map parameters);  }
@Test public void testResolveMainPanelRendererLabelNA() throws Exception { final ProductService productService = context.mock(ProductService.class, "productService"); CentralViewResolverProductImpl resolver = new CentralViewResolverProductImpl(productService); final Pair<String, String> resolved = resolver.resolveMainPanelRendererLabel(new HashMap<String, String>() {{ put("someparam", "1"); }}); assertNull(resolved); context.assertIsSatisfied(); }
@Test public void testResolveMainPanelRendererLabelSkuNaN() throws Exception { final ProductService productService = context.mock(ProductService.class, "productService"); CentralViewResolverProductImpl resolver = new CentralViewResolverProductImpl(productService); final Pair<String, String> resolved = resolver.resolveMainPanelRendererLabel(new HashMap<String, String>() {{ put(WebParametersKeys.SKU_ID, "abc"); }}); assertNull(resolved); context.assertIsSatisfied(); }
@Test public void testResolveMainPanelRendererLabelSkuNoSku() throws Exception { final ProductService productService = context.mock(ProductService.class, "productService"); CentralViewResolverProductImpl resolver = new CentralViewResolverProductImpl(productService); context.checking(new Expectations() {{ oneOf(productService).getSkuById(1L, true); will(returnValue(null)); }}); final Pair<String, String> resolved = resolver.resolveMainPanelRendererLabel(new HashMap<String, String>() {{ put(WebParametersKeys.SKU_ID, "1"); }}); assertNull(resolved); context.assertIsSatisfied(); }
@Test public void testResolveMainPanelRendererLabelSkuTemplate() throws Exception { final ProductService productService = context.mock(ProductService.class, "productService"); final ProductSku sku = context.mock(ProductSku.class, "sku"); final Product product = context.mock(Product.class, "product"); final ProductType type = context.mock(ProductType.class, "type"); CentralViewResolverProductImpl resolver = new CentralViewResolverProductImpl(productService); context.checking(new Expectations() {{ oneOf(productService).getSkuById(1L, true); will(returnValue(sku)); oneOf(sku).getProduct(); will(returnValue(product)); oneOf(product).getProducttype(); will(returnValue(type)); oneOf(type).getUitemplate(); will(returnValue("skutemplate1")); }}); final Pair<String, String> resolved = resolver.resolveMainPanelRendererLabel(new HashMap<String, String>() {{ put(WebParametersKeys.SKU_ID, "1"); }}); assertNotNull(resolved); assertEquals("skutemplate1", resolved.getFirst()); assertEquals(CentralViewLabel.SKU, resolved.getSecond()); context.assertIsSatisfied(); }
@Test public void testResolveMainPanelRendererLabelSkuNoTemplate() throws Exception { final ProductService productService = context.mock(ProductService.class, "productService"); final ProductSku sku = context.mock(ProductSku.class, "sku"); final Product product = context.mock(Product.class, "product"); final ProductType type = context.mock(ProductType.class, "type"); CentralViewResolverProductImpl resolver = new CentralViewResolverProductImpl(productService); context.checking(new Expectations() {{ oneOf(productService).getSkuById(1L, true); will(returnValue(sku)); oneOf(sku).getProduct(); will(returnValue(product)); oneOf(product).getProducttype(); will(returnValue(type)); oneOf(type).getUitemplate(); will(returnValue("")); }}); final Pair<String, String> resolved = resolver.resolveMainPanelRendererLabel(new HashMap<String, String>() {{ put(WebParametersKeys.SKU_ID, "1"); }}); assertNotNull(resolved); assertEquals(CentralViewLabel.SKU, resolved.getFirst()); assertEquals(CentralViewLabel.SKU, resolved.getSecond()); context.assertIsSatisfied(); }
@Test public void testResolveMainPanelRendererLabelProductNaN() throws Exception { final ProductService productService = context.mock(ProductService.class, "productService"); CentralViewResolverProductImpl resolver = new CentralViewResolverProductImpl(productService); final Pair<String, String> resolved = resolver.resolveMainPanelRendererLabel(new HashMap<String, String>() {{ put(WebParametersKeys.PRODUCT_ID, "abc"); }}); assertNull(resolved); context.assertIsSatisfied(); }
@Test public void testResolveMainPanelRendererLabelProductNoProduct() throws Exception { final ProductService productService = context.mock(ProductService.class, "productService"); CentralViewResolverProductImpl resolver = new CentralViewResolverProductImpl(productService); context.checking(new Expectations() {{ oneOf(productService).getProductById(1L, true); will(returnValue(null)); }}); final Pair<String, String> resolved = resolver.resolveMainPanelRendererLabel(new HashMap<String, String>() {{ put(WebParametersKeys.PRODUCT_ID, "1"); }}); assertNull(resolved); context.assertIsSatisfied(); }
@Test public void testResolveMainPanelRendererLabelProductTemplate() throws Exception { final ProductService productService = context.mock(ProductService.class, "productService"); final Product product = context.mock(Product.class, "product"); final ProductType type = context.mock(ProductType.class, "type"); CentralViewResolverProductImpl resolver = new CentralViewResolverProductImpl(productService); context.checking(new Expectations() {{ oneOf(productService).getProductById(1L, true); will(returnValue(product)); oneOf(product).getProducttype(); will(returnValue(type)); oneOf(type).getUitemplate(); will(returnValue("producttemplate1")); }}); final Pair<String, String> resolved = resolver.resolveMainPanelRendererLabel(new HashMap<String, String>() {{ put(WebParametersKeys.PRODUCT_ID, "1"); }}); assertNotNull(resolved); assertEquals("producttemplate1", resolved.getFirst()); assertEquals(CentralViewLabel.PRODUCT, resolved.getSecond()); context.assertIsSatisfied(); }
@Test public void testResolveMainPanelRendererLabelProductNoTemplate() throws Exception { final ProductService productService = context.mock(ProductService.class, "productService"); final Product product = context.mock(Product.class, "product"); final ProductType type = context.mock(ProductType.class, "type"); CentralViewResolverProductImpl resolver = new CentralViewResolverProductImpl(productService); context.checking(new Expectations() {{ oneOf(productService).getProductById(1L, true); will(returnValue(product)); oneOf(product).getProducttype(); will(returnValue(type)); oneOf(type).getUitemplate(); will(returnValue("")); }}); final Pair<String, String> resolved = resolver.resolveMainPanelRendererLabel(new HashMap<String, String>() {{ put(WebParametersKeys.PRODUCT_ID, "1"); }}); assertNotNull(resolved); assertEquals(CentralViewLabel.PRODUCT, resolved.getFirst()); assertEquals(CentralViewLabel.PRODUCT, resolved.getSecond()); context.assertIsSatisfied(); }