@Test public void testVcapTwoServicesWithNulls() { Resource resource = new ClassPathResource("/vcap3.json"); String content; try { content = new String(Files.readAllBytes(Paths.get(resource.getURI()))); VcapResult result = parser.parse(content); VcapPojo[] pojos = result.getPojos(); assertNotNull(pojos); assertEquals(2, pojos.length); VcapPojo pojo = result.findPojoForServiceType(VcapServiceType.AZURE_REDISCACHE); assertNotNull(pojo); LOG.debug("pojo = " + pojo); assertEquals(6, pojo.getCredentials().size()); assertEquals(0, pojo.getTags().length); assertEquals(0, pojo.getVolumeMounts().length); assertEquals("azure-rediscache", pojo.getLabel()); assertNull(pojo.getProvider()); assertEquals("azure-rediscache", pojo.getServiceBrokerName()); assertEquals("myredis", pojo.getServiceInstanceName()); assertEquals("basic", pojo.getServicePlan()); assertNull(pojo.getSyslogDrainUrl()); assertEquals("hostname", pojo.getCredentials().get("hostname")); assertEquals("username", pojo.getCredentials().get("name")); assertEquals("6379", pojo.getCredentials().get("port")); assertEquals("DIK5TNeN6qFhrF6ATpxLLIZ7SpNMDg9xU+0123456789", pojo.getCredentials().get("primaryKey")); assertEquals("nP/eeEyCo2c11UP1g4D5KgZgQN8bfR6clM0123456789=", pojo.getCredentials().get("secondaryKey")); assertEquals("6380", pojo.getCredentials().get("sslPort")); pojo = result.findPojoForServiceType(VcapServiceType.AZURE_STORAGE); assertNotNull(pojo); LOG.debug("pojo = " + pojo); assertEquals(3, pojo.getCredentials().size()); assertEquals(2, pojo.getTags().length); assertEquals(0, pojo.getVolumeMounts().length); assertEquals("azure-storage", pojo.getLabel()); assertNull(pojo.getProvider()); assertEquals("azure-storage", pojo.getServiceBrokerName()); assertEquals("mystorage", pojo.getServiceInstanceName()); assertEquals("standard", pojo.getServicePlan()); assertNull(pojo.getSyslogDrainUrl()); assertEquals("Azure", pojo.getTags()[0]); assertEquals("Storage", pojo.getTags()[1]); assertEquals("Vrpr5RGe7lf9FgNNmsrzYY9N8PUB1USAJLbDE2oytjD+3bUJXjt0H6Uwu+wGaQ+icyakQLNI8g8t0123456789==", pojo.getCredentials().get("primary_access_key")); assertEquals("7Dp5E253piI0rsfx1EIsSpw2ZQaJVe5uq56+OyEnom3wgC7DQs2jVbEwIL+90a7+u5xdLOzxxy0d0123456789==", pojo.getCredentials().get("secondary_access_key")); assertEquals("storage", pojo.getCredentials().get("storage_account_name")); } catch (IOException e) { LOG.error("Error reading json file", e); } }
VcapResult parse(String vcapServices) { VcapResult result = new VcapResult(); List<VcapPojo> results = new ArrayList<VcapPojo>(); log("VcapParser.parse: vcapServices = " + vcapServices); if (vcapServices != null) { try { JSONObject json = new JSONObject(vcapServices); JSONArray names = json.names(); for (int i = 0; i < names.length(); i++) { String name = (String) names.get(i); if (name.startsWith(AZURE)) { JSONArray azureService = json.getJSONArray(name); int numElements = azureService.length(); for (int index = 0; index < numElements; index++) { VcapPojo pojo = parseService(name, azureService, vcapServices, index); results.add(pojo); } } } } catch (JSONException e) { System.err.println("Error parsing " + vcapServices); e.printStackTrace(System.err); } } result.setPojos(results.toArray(new VcapPojo[results.size()])); return result; }
VcapParser implements EnvironmentPostProcessor { VcapResult parse(String vcapServices) { VcapResult result = new VcapResult(); List<VcapPojo> results = new ArrayList<VcapPojo>(); log("VcapParser.parse: vcapServices = " + vcapServices); if (vcapServices != null) { try { JSONObject json = new JSONObject(vcapServices); JSONArray names = json.names(); for (int i = 0; i < names.length(); i++) { String name = (String) names.get(i); if (name.startsWith(AZURE)) { JSONArray azureService = json.getJSONArray(name); int numElements = azureService.length(); for (int index = 0; index < numElements; index++) { VcapPojo pojo = parseService(name, azureService, vcapServices, index); results.add(pojo); } } } } catch (JSONException e) { System.err.println("Error parsing " + vcapServices); e.printStackTrace(System.err); } } result.setPojos(results.toArray(new VcapPojo[results.size()])); return result; } }
VcapParser implements EnvironmentPostProcessor { VcapResult parse(String vcapServices) { VcapResult result = new VcapResult(); List<VcapPojo> results = new ArrayList<VcapPojo>(); log("VcapParser.parse: vcapServices = " + vcapServices); if (vcapServices != null) { try { JSONObject json = new JSONObject(vcapServices); JSONArray names = json.names(); for (int i = 0; i < names.length(); i++) { String name = (String) names.get(i); if (name.startsWith(AZURE)) { JSONArray azureService = json.getJSONArray(name); int numElements = azureService.length(); for (int index = 0; index < numElements; index++) { VcapPojo pojo = parseService(name, azureService, vcapServices, index); results.add(pojo); } } } } catch (JSONException e) { System.err.println("Error parsing " + vcapServices); e.printStackTrace(System.err); } } result.setPojos(results.toArray(new VcapPojo[results.size()])); return result; }  }
VcapParser implements EnvironmentPostProcessor { VcapResult parse(String vcapServices) { VcapResult result = new VcapResult(); List<VcapPojo> results = new ArrayList<VcapPojo>(); log("VcapParser.parse: vcapServices = " + vcapServices); if (vcapServices != null) { try { JSONObject json = new JSONObject(vcapServices); JSONArray names = json.names(); for (int i = 0; i < names.length(); i++) { String name = (String) names.get(i); if (name.startsWith(AZURE)) { JSONArray azureService = json.getJSONArray(name); int numElements = azureService.length(); for (int index = 0; index < numElements; index++) { VcapPojo pojo = parseService(name, azureService, vcapServices, index); results.add(pojo); } } } } catch (JSONException e) { System.err.println("Error parsing " + vcapServices); e.printStackTrace(System.err); } } result.setPojos(results.toArray(new VcapPojo[results.size()])); return result; }  @Override void postProcessEnvironment(ConfigurableEnvironment confEnv, SpringApplication app); }
VcapParser implements EnvironmentPostProcessor { VcapResult parse(String vcapServices) { VcapResult result = new VcapResult(); List<VcapPojo> results = new ArrayList<VcapPojo>(); log("VcapParser.parse: vcapServices = " + vcapServices); if (vcapServices != null) { try { JSONObject json = new JSONObject(vcapServices); JSONArray names = json.names(); for (int i = 0; i < names.length(); i++) { String name = (String) names.get(i); if (name.startsWith(AZURE)) { JSONArray azureService = json.getJSONArray(name); int numElements = azureService.length(); for (int index = 0; index < numElements; index++) { VcapPojo pojo = parseService(name, azureService, vcapServices, index); results.add(pojo); } } } } catch (JSONException e) { System.err.println("Error parsing " + vcapServices); e.printStackTrace(System.err); } } result.setPojos(results.toArray(new VcapPojo[results.size()])); return result; }  @Override void postProcessEnvironment(ConfigurableEnvironment confEnv, SpringApplication app); static final String VCAP_SERVICES; }