XsltModel extends LoadableDetachableModel<String> { @Override protected String load() { final List<URL> urls = metadataUrlsModel.getObject(); if (urls == null || urls.isEmpty()) { return ""; } return urls.stream() .filter(Objects::nonNull) .flatMap(url -> { return tryTransform(url, urls); }) .findFirst() .orElse("<b>Could not load complete CMDI metadata</b>"); } XsltModel(IModel<List<URL>> metadataUrl);   }
@Test public void testLoadNullModelObject() { urlModel.setObject(null); String result = instance.load(); assertEquals("", result); }
@Test public void testLoadNullValue() { urlModel.setObject(Lists.newArrayList((URL) null)); String result = instance.load(); assertTrue(result.contains("Could not load")); }
@Test public void testLoad() throws Exception { final URL url = new URL("http: urlModel.setObject(Arrays.asList(url)); context.checking(new Expectations() { { oneOf(service).transformXml(url); will(returnValue("transformation output")); } }); final String result = instance.load(); assertEquals("transformation output", result); }
@Test public void testLoadMultiple() throws Exception { final URL url1 = new URL("http: final URL url2 = new URL("http: urlModel.setObject(Arrays.asList(url1, url2)); context.checking(new Expectations() { { oneOf(service).transformXml(url1); will(returnValue("transformation output")); never(service).transformXml(url2); } }); final String result = instance.load(); assertEquals("transformation output", result); }
@Test public void testLoadTransformerException() throws Exception { final URL url = new URL("http: urlModel.setObject(Arrays.asList(url)); context.checking(new Expectations() { { oneOf(service).transformXml(url); will(throwException(new TransformerException("intentional testing exception"))); } }); final String result = instance.load(); assertTrue(result.contains("Could not load")); }
@Test public void testLoadTransformerExceptionMultiple() throws Exception { final URL url1 = new URL("http: final URL url2 = new URL("http: urlModel.setObject(Arrays.asList(url1, url2)); context.checking(new Expectations() { { oneOf(service).transformXml(url1); will(throwException(new TransformerException("intentional testing exception"))); oneOf(service).transformXml(url2); will(returnValue("transformation output")); } }); final String result = instance.load(); assertEquals("transformation output", result); }