Skip to content

Commit add2d3c

Browse files
Merge pull request cloudfoundry#167 from scottfrederick/service-plans
Added checking for optional service plan fields before unboxing.
2 parents 8e25c88 + c66af16 commit add2d3c

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

cloudfoundry-client-lib/src/main/java/org/cloudfoundry/client/lib/util/CloudEntityResourceMapper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,14 @@ private CloudServiceOffering mapServiceResource(Map<String, Object> resource) {
195195
List<Map<String, Object>> servicePlanList = getEmbeddedResourceList(getEntity(resource), "service_plans");
196196
if (servicePlanList != null) {
197197
for (Map<String, Object> servicePlanResource : servicePlanList) {
198+
Boolean publicPlan = getEntityAttribute(servicePlanResource, "public", Boolean.class);
198199
CloudServicePlan servicePlan =
199200
new CloudServicePlan(
200201
getMeta(servicePlanResource),
201202
getEntityAttribute(servicePlanResource, "name", String.class),
202203
getEntityAttribute(servicePlanResource, "description", String.class),
203204
getEntityAttribute(servicePlanResource, "free", Boolean.class),
204-
getEntityAttribute(servicePlanResource, "public", Boolean.class),
205+
publicPlan == null ? true : publicPlan,
205206
getEntityAttribute(servicePlanResource, "extra", String.class),
206207
getEntityAttribute(servicePlanResource, "unique_id", String.class),
207208
cloudServiceOffering);

cloudfoundry-client-lib/src/test/java/org/cloudfoundry/client/lib/CloudFoundryClientTest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import static org.junit.Assert.assertFalse;
99
import static org.junit.Assert.assertNotNull;
1010
import static org.junit.Assert.assertNull;
11+
import static org.junit.Assert.assertSame;
1112
import static org.junit.Assert.assertTrue;
1213
import static org.junit.Assert.fail;
1314
import static org.junit.Assume.assumeTrue;
@@ -41,6 +42,7 @@
4142
import org.cloudfoundry.client.lib.domain.CloudRoute;
4243
import org.cloudfoundry.client.lib.domain.CloudService;
4344
import org.cloudfoundry.client.lib.domain.CloudServiceOffering;
45+
import org.cloudfoundry.client.lib.domain.CloudServicePlan;
4446
import org.cloudfoundry.client.lib.domain.CloudSpace;
4547
import org.cloudfoundry.client.lib.domain.CloudStack;
4648
import org.cloudfoundry.client.lib.domain.CrashInfo;
@@ -1087,11 +1089,14 @@ public void getServiceOfferings() {
10871089
assertNotNull(offering.getName());
10881090
assertNotNull(offering.getDescription());
10891091
assertNotNull(offering.getLabel());
1090-
assertNotNull(offering.getProvider());
1091-
assertNotNull(offering.getUrl());
1092-
assertNotNull(offering.getDocumentationUrl());
10931092
assertNotNull(offering.getUniqueId());
10941093
assertNotNull(offering.getExtra());
1094+
1095+
CloudServicePlan plan = offering.getCloudServicePlans().get(0);
1096+
assertNotNull(plan.getName());
1097+
assertNotNull(plan.getUniqueId());
1098+
assertNotNull(plan.getDescription());
1099+
assertSame(offering, plan.getServiceOffering());
10951100
}
10961101

10971102
@Test

0 commit comments

Comments
 (0)