NetworkUtil { public static Network deserialize(byte[] epn) throws Exception { Network ret=null; java.io.ByteArrayInputStream bais=new java.io.ByteArrayInputStream(epn); ret = MAPPER.readValue(bais, Network.class); bais.close(); return (ret); } private  NetworkUtil(); static byte[] serialize(Network epn); static Network deserialize(byte[] epn);  }
@Test public void testDeserializeEPN() { try { java.io.InputStream is=NetworkUtilTest.class.getResourceAsStream("/jsondata/TestNetwork1.json"); byte[] b = new byte[is.available()]; is.read(b); is.close(); Network network=NetworkUtil.deserialize(b); if (network.getNodes().size() != 3) { fail("Number of nodes not 3: "+network.getNodes().size()); } Node n1=network.getNodes().get(0); Node n2=network.getNodes().get(1); Node n3=network.getNodes().get(2); if (n1.getPredicate() == null) { fail("Predicate 1 should not be null"); } if (!(n1.getPredicate() instanceof TestPredicate1)) { fail("Predicate 1 not correct class"); } if (n1.getEventProcessor() == null) { fail("Event Processor 1 should not be null"); } if (!(n1.getEventProcessor() instanceof TestEventProcessor1)) { fail("Event Processor 1 not correct class"); } TestEventProcessor1 tep1=(TestEventProcessor1)n1.getEventProcessor(); if (!(tep1.getServices().get("testCache") instanceof CacheManager)) { fail("Failed to find test cache"); } if (n2.getPredicate() == null) { fail("Predicate 2 should not be null"); } if (!(n2.getPredicate() instanceof TestPredicate2)) { fail("Predicate 2 not correct class"); } if (n2.getEventProcessor() == null) { fail("Event Processor 2 should not be null"); } if (!(n2.getEventProcessor() instanceof TestEventProcessor2)) { fail("Event Processor 2 not correct class"); } if (n3.getPredicate() != null) { fail("Predicate 3 should be null"); } if (n3.getEventProcessor() == null) { fail("Event Processor 3 should not be null"); } if (!(n3.getEventProcessor() instanceof TestEventProcessor3)) { fail("Event Processor 3 not correct class"); } } catch(Exception e) { e.printStackTrace(); fail("Failed to deserialize: "+e); } }