CustomMetricsCondition implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { try { new CFConfigurationProvider(); } catch (IllegalArgumentException ex) { LOG.error("Custom Metrics reporter will not start since required ENVs are missing: {}", ex.getMessage()); return false; } return true; }  @Override boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata);  }
@Test public void testMatches_WithAllEnvs() throws Exception { EnvUtils.setEnvs(new String[][] { CF_INSTANCE_GUID_KEY_ENV, CF_INSTANCE_INDEX_KEY_ENV, VCAP_SERVICES_KEY_ENV, VCAP_APPLICATION_KEY_ENV }); boolean matches = condition.matches(null, null); assertTrue(matches); }
@Test public void testMatches_Without_VCAP_APPLICATION_KEY() throws Exception { EnvUtils.setEnvs(new String[][] { CF_INSTANCE_GUID_KEY_ENV, CF_INSTANCE_INDEX_KEY_ENV, VCAP_SERVICES_KEY_ENV }); boolean matches = condition.matches(null, null); assertFalse(matches); }
@Test public void testMatches_Without_VCAP_SERVICES_KEY_ENV() throws Exception { EnvUtils .setEnvs(new String[][] { CF_INSTANCE_GUID_KEY_ENV, CF_INSTANCE_INDEX_KEY_ENV, VCAP_APPLICATION_KEY_ENV }); boolean matches = condition.matches(null, null); assertFalse(matches); }
@Test public void testMatches_Without_CF_INSTANCE_INDEX_KEY_ENV() throws Exception { EnvUtils.setEnvs(new String[][] { CF_INSTANCE_GUID_KEY_ENV, VCAP_SERVICES_KEY_ENV, VCAP_APPLICATION_KEY_ENV }); boolean matches = condition.matches(null, null); assertFalse(matches); }
@Test public void testMatches_Without_CF_INSTANCE_GUID_KEY_ENV() throws Exception { EnvUtils.setEnvs(new String[][] { CF_INSTANCE_INDEX_KEY_ENV, VCAP_SERVICES_KEY_ENV, VCAP_APPLICATION_KEY_ENV }); boolean matches = condition.matches(null, null); assertFalse(matches); }
@Test public void testMatches_WithoutAllEnvs() throws Exception { EnvUtils.setEnvs(new String[][] {}); boolean matches = condition.matches(null, null); assertFalse(matches); }