VcapServicesStringParser implements Function<String, Config> { @Override public Config apply(final String systemVcapServices) { checkNotNull(systemVcapServices, "system VCAP services string"); if (systemVcapServices.isEmpty()) { return ConfigFactory.empty(); } final Config vcapServicesConfig = tryToParseString(systemVcapServices); final Set<Map.Entry<String, ConfigValue>> vcapServicesConfigEntries = vcapServicesConfig.entrySet(); final Map<String, Object> result = new HashMap<>(vcapServicesConfigEntries.size()); for (final Map.Entry<String, ConfigValue> serviceConfigEntry : vcapServicesConfigEntries) { result.put(serviceConfigEntry.getKey(), convertConfigListToConfigObject(serviceConfigEntry.getValue())); } return ConfigFactory.parseMap(result); } private  VcapServicesStringParser(); @Override Config apply(final String systemVcapServices);  }
@Test public void tryToParseNullString() { assertThatNullPointerException() .isThrownBy(() -> underTest.apply(null)) .withMessage("The system VCAP services string must not be null!") .withNoCause(); }
@Test public void parseEmptyString() { final Config actual = underTest.apply(""); assertThat(actual.isEmpty()).isTrue(); }
@Test public void getReturnsExpected() { final JsonObject expectedMongoDbServiceConfigJsonObject = JsonObject.newBuilder() .set("ditto-mongodb-staging", JsonObject.newBuilder() .set("binding_name", JsonValue.nullLiteral()) .set("credentials", JsonObject.newBuilder() .set("readonly", false) .set("replicaset", "stretched-0815") .build()) .set("instance_name", "ditto-mongodb-staging") .set("label", "MongoDB-Service") .set("name", "ditto-mongodb-staging") .set("plan", "Database on Dedicated Replica Set - Stretched") .set("provider", JsonValue.nullLiteral()) .set("syslog_drain_url", JsonValue.nullLiteral()) .set("tags", JsonArray.newBuilder() .add("mongodb", "mongo", "database", "db", "mongoose") .build()) .set("volume_mounts", JsonArray.empty()) .build()) .build(); final ConfigValue expectedMongoDbServiceConfig = ConfigFactory.parseString(expectedMongoDbServiceConfigJsonObject.toString()).root(); final Config actual = underTest.apply(knownSystemVcapServicesString); assertThat(actual.getValue("MongoDB-Service")).isEqualTo(expectedMongoDbServiceConfig); }