@Test(expected = WroRuntimeException.class) public void testInvalidStream() throws Exception { factory = new JsonModelFactory() { @Override protected InputStream getModelResourceAsStream() throws IOException { throw new IOException(); }; }; factory.create(); }
@Test(expected = WroRuntimeException.class) public void testInvalidContent() { factory = new JsonModelFactory() { @Override protected InputStream getModelResourceAsStream() throws IOException { return new ByteArrayInputStream("".getBytes()); }; }; Assert.assertNull(factory.create()); }
@Test public void createValidModel() { factory = new JsonModelFactory() { @Override protected InputStream getModelResourceAsStream() throws IOException { return TestGroovyModelFactory.class.getResourceAsStream("wro.json"); }; }; final WroModel model = factory.create(); Assert.assertNotNull(model); Assert.assertEquals(Arrays.asList("g1", "g2"), new WroModelInspector(model).getGroupNames()); LOG.debug("model: {}", model); }
/** * Test the usecase when the resource has no type. For now, it is ok to have it null because * you'll get a NPE exception during processing if no type is specified anyway. */ @Test public void createIncompleteModel() { factory = new JsonModelFactory() { @Override protected InputStream getModelResourceAsStream() throws IOException { return getClass().getResourceAsStream("incomplete-wro.json"); }; }; final WroModel model = factory.create(); Assert.assertNotNull(model); Assert.assertEquals(1, model.getGroups().size()); final Group group = new ArrayList<Group>(model.getGroups()).get(0); Assert.assertNull(group.getResources().get(0).getType()); LOG.debug("model: {}", model); }
@Test public void shouldBeThreadSafe() throws Exception { factory = new JsonModelFactory() { @Override protected InputStream getModelResourceAsStream() throws IOException { return TestGroovyModelFactory.class.getResourceAsStream("wro.json"); }; }; WroTestUtils.init(factory); final WroModel expected = factory.create(); WroTestUtils.runConcurrently( new Callable<Void>() { @Override public Void call() throws Exception { Assert.assertEquals(expected, factory.create()); return null; } }, 10); }