MetadataUtils { public static <T> String getKey(T t) { if (t instanceof StreamDefinition) { return ((StreamDefinition) t).getStreamId(); } if (t instanceof PolicyAssignment) { return ((PolicyAssignment) t).getPolicyName(); } if (t instanceof ScheduleState) { return ((ScheduleState) t).getVersion(); } if (t instanceof AlertPublishEvent) { return ((AlertPublishEvent) t).getAlertId(); } try { Method m = t.getClass().getMethod("getName"); return (String) m.invoke(t); } catch (NoSuchMethodException | SecurityException | InvocationTargetException | IllegalAccessException | IllegalArgumentException e) { LOG.error(" getName not found on given class :" + t.getClass().getName()); } throw new RuntimeException(String.format("no getName() found on target class %s for matching", t.getClass() .getName())); }  static String getKey(T t); static Connection getJdbcConnection(Config config); static final String META_DATA; static final String ALERT_META_DATA_DAO; static final String JDBC_USERNAME_PATH; static final String JDBC_PASSWORD_PATH; static final String JDBC_DRIVER_PATH; static final String JDBC_DATABASE_PATH; static final String JDBC_CONNECTION_PATH; static final String JDBC_CONNECTION_PROPERTIES_PATH; static final String MONGO_CONNECTION_PATH; static final String MONGO_DATABASE; }
@Test public void testGetKey() throws Exception { StreamDefinition stream = new StreamDefinition(); Assert.assertNull(MetadataUtils.getKey(stream)); PolicyAssignment policyAssignment = new PolicyAssignment(); policyAssignment.setPolicyName("test"); Assert.assertEquals("test", MetadataUtils.getKey(policyAssignment)); ScheduleState scheduleState = new ScheduleState(); scheduleState.setVersion("1.0"); Assert.assertEquals("1.0", MetadataUtils.getKey(scheduleState)); }
@Test public void testGetKeyThrowable() { thrown.expect(RuntimeException.class); Object obj = new Object(); MetadataUtils.getKey(obj); }