EventFactory { public static Event create(String name) throws CoreException { try { Event result = (Event) Class.forName(name).newInstance(); result.setUniqueId(uidGenerator.create(result)); result.setCreationTime(System.currentTimeMillis()); return result; } catch (Exception e) { throw new CoreException(e); } }  static Event create(String name); static T create(Class<T> name); static Event createEvent(AdaptrisMessage msg, AdaptrisMarshaller marshaller); static Event createEvent(AdaptrisMessage msg);  }
@Test public void testCreateInvalidEvents() { String invalid = "com.adaptris.core.PingEventx"; String nonEvent = "java.lang.String"; String empty = ""; try { EventFactory.create(invalid); fail("no CoreException from invalid class name"); } catch (CoreException e) { } try { EventFactory.create(nonEvent); fail("no CoreException from non-Event class (String)"); } catch (CoreException e) { } try { EventFactory.create(empty); fail("no CoreException from \"\""); } catch (CoreException e) { } try { EventFactory.create((String) null); fail("no CoreException from null"); } catch (CoreException e) { } }
@Test public void testCreateEventFromString() throws Exception { for (int i = 0; i < ALL_EVENT_CLASSES.length; i++) { Event e = EventFactory.create(ALL_EVENT_CLASSES[i]); assertNotSame(ALL_EVENT_CLASSES[i], e.getNameSpace(), EventNameSpaceConstants.EVENT); } }
@Test public void testXmlRoundTrip() throws Exception { AdaptrisMarshaller m = DefaultMarshaller.getDefaultMarshaller(); for (int i = 0; i < ALL_EVENT_CLASSES.length; i++) { Event input = EventFactory.create(ALL_EVENT_CLASSES[i]); setSetters(input); String xml = m.marshal(input); log.trace(xml); Event output = (Event) m.unmarshal(xml); BaseCase.assertRoundtripEquality(input, output); } }
@Test public void testCreateNamespace() throws Exception { for (int i = 0; i < ALL_EVENT_CLASSES.length; i++) { Event e = (Event) EventFactory.create(Class.forName(ALL_EVENT_CLASSES[i])); assertNotNull(e.createNameSpace()); } }
@Test public void testUniqueId() throws Exception { for (int i = 0; i < ALL_EVENT_CLASSES.length; i++) { Event e = (Event) EventFactory.create(Class.forName(ALL_EVENT_CLASSES[i])); try { e.setUniqueId(""); fail("allows unique-id=''"); } catch (IllegalArgumentException expected) { } try { e.setUniqueId(null); fail("allows unique-id=null"); } catch (IllegalArgumentException expected) { } } }