@Test public void testVcapSingleService() { Resource resource = new ClassPathResource("/vcap1.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(1, pojos.length); VcapPojo pojo = pojos[0]; LOG.debug("pojo = " + pojo); assertEquals(5, pojo.getCredentials().size()); assertEquals(2, pojo.getTags().length); assertEquals(0, pojo.getVolumeMounts().length); assertEquals("azure-sqldb", pojo.getLabel()); assertEquals("provider", pojo.getProvider()); assertEquals("azure-sqldb", pojo.getServiceBrokerName()); assertEquals("myazuredb-service", pojo.getServiceInstanceName()); assertEquals("basic", pojo.getServicePlan()); assertEquals("drain_url", pojo.getSyslogDrainUrl()); assertEquals("Azure", pojo.getTags()[0]); assertEquals("SQL", pojo.getTags()[1]); assertEquals("userid", pojo.getCredentials().get("administratorLogin")); assertEquals("password", pojo.getCredentials().get("administratorLoginPassword")); assertEquals("jdbc:sqlserver: assertEquals("sql-server-name", pojo.getCredentials().get("sqlServerName")); assertEquals("db-name", pojo.getCredentials().get("sqldbName")); } 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; }