TwilioServiceInfoCreator extends CloudFoundryServiceInfoCreator<TwilioServiceInfo> { @Override public TwilioServiceInfo createServiceInfo(Map<String, Object> serviceData) { String accountId = null; String authToken = null; String id = null; Object credObject = serviceData.get("credentials"); Object idObj = serviceData.get("name"); if (idObj instanceof String) { id = (String) idObj; } if (credObject instanceof Map<?, ?>) { Map<String, Object> credentials = (Map<String, Object>) credObject; Object accoutIdObj = credentials.get("twilio_account_sid"); Object authTokenObj = credentials.get("twilio_auth_token"); if (accoutIdObj instanceof String) { accountId = (String) accoutIdObj; } if (authTokenObj instanceof String) { authToken = (String) authTokenObj; } } return new TwilioServiceInfo(id, accountId, authToken); } TwilioServiceInfoCreator(); @Override boolean accept(Map<String, Object> serviceData); @Override TwilioServiceInfo createServiceInfo(Map<String, Object> serviceData);  }
@Test public void testCreateServiceInfo() { Map<String, Object> empty = new HashMap<String, Object>(); Map<String, Object> badTypes = new HashMap<String, Object>(); badTypes.put("name", 1); Map<String, Object> badCredTypes = new HashMap<String, Object>(); badCredTypes.put("twilio_account_sid", 1); badCredTypes.put("twilio_auth_token", 1); badTypes.put("credentials", badCredTypes); Map<String, Object> rawInfo = new HashMap<String, Object>(); rawInfo.put("name", "id"); Map<String, Object> rawInfoCreds = new HashMap<String, Object>(); rawInfoCreds.put("twilio_account_sid", "abc"); rawInfoCreds.put("twilio_auth_token", "123"); rawInfo.put("credentials", rawInfoCreds); TwilioServiceInfo nullServiceInfo = new TwilioServiceInfo(null, null, null); TwilioServiceInfo serviceInfo = new TwilioServiceInfo("id", "abc", "123"); assertEquals(nullServiceInfo, creator.createServiceInfo(empty)); assertEquals(nullServiceInfo, creator.createServiceInfo(badTypes)); assertEquals(serviceInfo, creator.createServiceInfo(rawInfo)); }