org.springframework.cloud.servicebroker.model.catalog.Plan Java Examples

The following examples show how to use org.springframework.cloud.servicebroker.model.catalog.Plan. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CatalogConfiguration.java    From tutorials with MIT License 6 votes vote down vote up
@Bean
public Catalog catalog() {
    Plan mailFreePlan = Plan.builder()
        .id("fd81196c-a414-43e5-bd81-1dbb082a3c55")
        .name("mail-free-plan")
        .description("Mail Service Free Plan")
        .free(true)
        .build();

    ServiceDefinition serviceDefinition = ServiceDefinition.builder()
        .id("b92c0ca7-c162-4029-b567-0d92978c0a97")
        .name("mail-service")
        .description("Mail Service")
        .bindable(true)
        .tags("mail", "service")
        .plans(mailFreePlan)
        .build();

    return Catalog.builder()
        .serviceDefinitions(serviceDefinition)
        .build();
}
 
Example #2
Source File: AbstractBasePathIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Bean
protected CatalogService catalogService() {
	return new CatalogService() {

		@Override
		public Mono<ServiceDefinition> getServiceDefinition(String serviceId) {
			return this.getCatalog()
					.flatMapIterable(Catalog::getServiceDefinitions)
					.filter(service -> serviceId.equals(service.getId()))
					.next();
		}

		@Override
		public Mono<Catalog> getCatalog() {
			return Mono.just(Catalog.builder()
					.serviceDefinitions(ServiceDefinition.builder()
							.id("default-service")
							.plans(Plan.builder()
									.id("default-plan")
									.build())
							.build())
					.build()
			);
		}
	};
}
 
Example #3
Source File: ExampleCatalogConfiguration.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Bean
public Catalog catalog() {
	Plan plan = Plan.builder()
			.id("simple-plan")
			.name("standard")
			.description("A simple plan")
			.free(true)
			.build();

	ServiceDefinition serviceDefinition = ServiceDefinition.builder()
			.id("example-service")
			.name("example")
			.description("A simple example")
			.bindable(true)
			.tags("example", "tags")
			.plans(plan)
			.build();

	return Catalog.builder()
	  .serviceDefinitions(serviceDefinition)
	  .build();
}
 
Example #4
Source File: CatalogConfigTest.java    From ecs-cf-service-broker with Apache License 2.0 6 votes vote down vote up
private void testPlan(Plan plan, String id, String name, String description,
                      Double usdCost, String unit, List<String> bullets) {
    assertEquals(id, plan.getId());
    assertEquals(name, plan.getName());
    assertEquals(description, plan.getDescription());

    Map<String, Object> metadata = plan.getMetadata();
    @SuppressWarnings("unchecked")
    List<Map<String, Object>> costs = (List<Map<String, Object>>) metadata
            .get("costs");
    Map<String, Object> cost = costs.get(0);
    @SuppressWarnings("unchecked")
    Map<String, Object> amount = (Map<String, Object>) cost.get("amount");
    assertEquals(usdCost, amount.get("usd"));
    assertEquals(unit, cost.get("unit"));
    assertEquals(bullets, metadata.get("bullets"));
}
 
Example #5
Source File: CatalogConfigTest.java    From ecs-cf-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
public void testEcsBucketPlans() {
    // Service Definition Plans
    ServiceDefinition service = catalog.getServiceDefinitions().get(1);
    List<Plan> ecsBucketPlans = service.getPlans();
    Plan plan0 = ecsBucketPlans.get(0);

    testPlan(plan0, "8e777d49-0a78-4cf4-810a-b5f5173b019d", "5gb",
            "Free Trial", 0.0, "MONTHLY",
            Arrays.asList("Shared object storage", "5 GB Storage",
                    "S3 protocol access"));

    Plan plan1 = ecsBucketPlans.get(1);
    testPlan(plan1, "89d20694-9ab0-4a98-bc6a-868d6d4ecf31", "unlimited",
            "Pay per GB for Month", 0.03, "PER GB PER MONTH",
            Arrays.asList("Shared object storage", "Unlimited Storage",
                    "S3 protocol access"));
}
 
Example #6
Source File: ServiceDefinitionProxy.java    From ecs-cf-service-broker with Apache License 2.0 6 votes vote down vote up
public ServiceDefinition unproxy() {
    List<Plan> realPlans = null;
    if (plans != null)
        realPlans = plans.stream().map(PlanProxy::unproxy)
                .collect(Collectors.toList());

    DashboardClient realDashboardClient = null;
    if (dashboardClient != null)
        realDashboardClient = dashboardClient.unproxy();

    if ((boolean) this.getServiceSettings().getOrDefault("file-accessible", false))
        requires.add("volume_mount");

   return  new ServiceDefinition(id, name, description, bindable, planUpdatable,
            instancesRetrievable, bindingsRetrievable, allowContextUpdates, realPlans, tags, metadata, requires,
            realDashboardClient);
}
 
Example #7
Source File: ServiceCatalogConfiguration.java    From bookstore-service-broker with Apache License 2.0 6 votes vote down vote up
@Bean
public Catalog catalog() {
	Plan plan = Plan.builder()
			.id("b973fb78-82f3-49ef-9b8b-c1876974a6cd")
			.name("standard")
			.description("A simple book store plan")
			.free(true)
			.build();

	ServiceDefinition serviceDefinition = ServiceDefinition.builder()
			.id("bdb1be2e-360b-495c-8115-d7697f9c6a9e")
			.name("bookstore")
			.description("A simple book store service")
			.bindable(true)
			.tags("book-store", "books", "sample")
			.plans(plan)
			.metadata("displayName", "bookstore")
			.metadata("longDescription", "A simple book store service")
			.metadata("providerDisplayName", "Acme Books")
			.build();

	return Catalog.builder()
			.serviceDefinitions(serviceDefinition)
			.build();
}
 
Example #8
Source File: AppDeploymentUpdateServiceInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private UpdateServiceInstanceRequest buildRequest(String serviceName, String planName,
	Map<String, Object> parameters) {
	return UpdateServiceInstanceRequest
		.builder()
		.serviceInstanceId("service-instance-id")
		.serviceDefinitionId(serviceName + "-id")
		.planId(planName + "-id")
		.serviceDefinition(ServiceDefinition.builder()
			.id(serviceName + "-id")
			.name(serviceName)
			.plans(Plan.builder()
				.id(planName + "-id")
				.name(planName)
				.build())
			.build())
		.plan(Plan.builder()
			.id(planName + "-id")
			.name(planName)
			.build())
		.parameters(parameters == null ? new HashMap<>() : parameters)
		.build();
}
 
Example #9
Source File: AppDeploymentCreateServiceInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private CreateServiceInstanceRequest buildRequest(String serviceName, String planName,
	Map<String, Object> parameters) {
	return CreateServiceInstanceRequest
		.builder()
		.serviceInstanceId("service-instance-id")
		.serviceDefinitionId(serviceName + "-id")
		.planId(planName + "-id")
		.serviceDefinition(ServiceDefinition
			.builder()
			.id(serviceName + "-id")
			.name(serviceName)
			.plans(Plan.builder()
				.id(planName + "-id")
				.name(planName)
				.build())
			.build())
		.plan(Plan.builder()
			.id(planName + "-id")
			.name(planName)
			.build())
		.parameters(parameters == null ? new HashMap<>() : parameters)
		.build();
}
 
Example #10
Source File: AppDeploymentDeleteServiceInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private DeleteServiceInstanceRequest buildRequest(String serviceName, String planName) {
	return DeleteServiceInstanceRequest
		.builder()
		.serviceDefinitionId(serviceName + "-id")
		.serviceInstanceId("service-instance-id")
		.planId(planName + "-id")
		.serviceDefinition(ServiceDefinition.builder()
			.id(serviceName + "-id")
			.name(serviceName)
			.plans(Plan.builder()
				.id(planName + "-id")
				.name(planName)
				.build())
			.build())
		.plan(Plan.builder()
			.id(planName + "-id")
			.name(planName)
			.build())
		.build();
}
 
Example #11
Source File: CreateServiceInstanceBindingRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void requestSerializesToJsonExcludingTransients() {
	CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
			.platformInstanceId("platform-instance-id")
			.apiInfoLocation("api-info-location")
			.originatingIdentity(PlatformContext.builder()
					.platform("sample-platform").build())
			.asyncAccepted(true)
			.serviceDefinitionId("definition-id")
			.serviceDefinition(ServiceDefinition.builder().build())
			.plan(Plan.builder().build())
			.build();

	DocumentContext json = JsonUtils.toJsonPath(request);

	// Fields present in OSB Json body should be present, but no unspecified optional ones.
	JsonPathAssert.assertThat(json).hasPath("$.service_id").isEqualTo("definition-id");

	// other fields mapped outside of json body (typically http headers or request paths)
	// should be excluded
	JsonPathAssert.assertThat(json).hasMapAtPath("$").hasSize(1);
}
 
Example #12
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
	controller = new ServiceInstanceBindingController(catalogService, bindingService);
	ServiceDefinition serviceDefinition = mock(ServiceDefinition.class);
	List<Plan> plans = new ArrayList<>();
	plans.add(Plan.builder().id("service-definition-plan-id").build());
	given(serviceDefinition.getPlans()).willReturn(plans);
	given(serviceDefinition.getId()).willReturn("service-definition-id");
	given(catalogService.getServiceDefinition(any())).willReturn(Mono.just(serviceDefinition));
}
 
Example #13
Source File: ControllerRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUpControllerRequestTest() {
	initMocks(this);

	plan = Plan.builder()
			.id("plan-id")
			.build();

	serviceDefinition = ServiceDefinition.builder()
			.id("service-definition-id")
			.plans(plan)
			.build();

	lenient().when(catalogService.getServiceDefinition(anyString()))
			.thenReturn(Mono.empty());

	lenient().when(catalogService.getServiceDefinition("service-definition-id"))
			.thenReturn(Mono.just(serviceDefinition));

	identityContext = PlatformContext.builder()
			.platform("test-platform")
			.property("user", "user-id")
			.build();

	requestContext = PlatformContext.builder()
			.platform("test-platform")
			.property("request-property", "value")
			.build();
}
 
Example #14
Source File: ServiceInstanceControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
	controller = new ServiceInstanceController(catalogService, serviceInstanceService);
	ServiceDefinition serviceDefinition = mock(ServiceDefinition.class);
	List<Plan> plans = new ArrayList<>();
	plans.add(Plan.builder().id("service-definition-plan-id").build());
	given(serviceDefinition.getPlans()).willReturn(plans);
	given(serviceDefinition.getId()).willReturn("service-definition-id");
	given(catalogService.getServiceDefinition(any())).willReturn(Mono.just(serviceDefinition));
}
 
Example #15
Source File: DeleteServiceInstanceRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void serializesAccordingToOsbSpecs() {
	Context originatingIdentity = PlatformContext.builder()
			.platform("test-platform")
			.build();

	DeleteServiceInstanceRequest request = DeleteServiceInstanceRequest.builder()
			.serviceInstanceId("service-instance-id")
			.serviceDefinitionId("service-definition-id")
			.planId("plan-id")
			.asyncAccepted(true)
			.platformInstanceId("platform-instance-id")
			.apiInfoLocation("https://api.app.local")
			.originatingIdentity(originatingIdentity)
			.requestIdentity("request-id")
			.plan(Plan.builder().build())
			.serviceDefinition(ServiceDefinition.builder().build())
			.build();

	DocumentContext json = JsonUtils.toJsonPath(request);

	//OSB fields
	JsonPathAssert.assertThat(json).hasPath("$.service_id").isEqualTo("service-definition-id");
	JsonPathAssert.assertThat(json).hasPath("$.plan_id").isEqualTo("plan-id");
	JsonPathAssert.assertThat(json).hasPath("$.accepts_incomplete").isEqualTo(true);
	//Other internals should not be polluting the JSON representation
	JsonPathAssert.assertThat(json).hasMapAtPath("$").hasSize(3);
	JsonPathAssert.assertThat(json).hasNoPath("$.request_identity");
}
 
Example #16
Source File: CreateServiceInstanceRequest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
private CreateServiceInstanceRequest(String serviceDefinitionId, String serviceInstanceId, String planId,
		ServiceDefinition serviceDefinition, Plan plan, Map<String, Object> parameters, Context context,
		boolean asyncAccepted, String platformInstanceId, String apiInfoLocation, Context originatingIdentity,
		String requestIdentity, String organizationGuid, String spaceGuid, MaintenanceInfo maintenanceInfo) {
	super(parameters, context, asyncAccepted, platformInstanceId, apiInfoLocation, originatingIdentity,
			requestIdentity);
	this.serviceDefinitionId = serviceDefinitionId;
	this.serviceInstanceId = serviceInstanceId;
	this.planId = planId;
	this.serviceDefinition = serviceDefinition;
	this.plan = plan;
	this.organizationGuid = organizationGuid;
	this.spaceGuid = spaceGuid;
	this.maintenanceInfo = maintenanceInfo;
}
 
Example #17
Source File: AppDeploymentInstanceWorkflow.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
protected Mono<Boolean> accept(ServiceDefinition serviceDefinition, Plan plan) {
	return getBackingApplicationsForService(serviceDefinition, plan)
		.map(backingApplications -> !backingApplications.isEmpty())
		.filter(Boolean::booleanValue) // filter out Boolean.False to proceed with flux, see https://stackoverflow.com/questions/49860558/project-reactor-conditional-execution
		.switchIfEmpty(
			getBackingServicesForService(serviceDefinition, plan)
			.map(backingServices -> !backingServices.isEmpty())
			.defaultIfEmpty(false)
		);
}
 
Example #18
Source File: ExampleCatalogService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
private Plan getPlan() {
	return Plan.builder()
	   .id("simple-plan")
	   .name("standard")
	   .description("A simple plan")
	   .free(true)
	   .build();
}
 
Example #19
Source File: DeleteServiceInstanceBindingRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void serializesAccordingToOsbSpecs() {
	Context originatingIdentity = PlatformContext.builder()
			.platform("test-platform")
			.build();

	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
			.serviceInstanceId("service-instance-id")
			.serviceDefinitionId("service-definition-id")
			.planId("plan-id")
			.bindingId("binding-id")
			.asyncAccepted(true)
			.platformInstanceId("platform-instance-id")
			.apiInfoLocation("https://api.app.local")
			.originatingIdentity(originatingIdentity)
			.requestIdentity("request-id")
			.plan(Plan.builder().build())
			.serviceDefinition(ServiceDefinition.builder().build())
			.build();

	DocumentContext json = JsonUtils.toJsonPath(request);

	// 3 OSB Fields should be present
	JsonPathAssert.assertThat(json).hasPath("$.plan_id").isEqualTo("plan-id");
	JsonPathAssert.assertThat(json).hasPath("$.service_id").isEqualTo("service-definition-id");
	JsonPathAssert.assertThat(json).hasPath("$.accepts_incomplete").isEqualTo(true);


	// fields mapped outside of json body (typically http headers or request paths)
	// should be excluded
	JsonPathAssert.assertThat(json).hasMapAtPath("$").hasSize(3);
}
 
Example #20
Source File: BaseController.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
/**
 * Find the Plan for the Service Definition and Plan ID, or empty if not found.
 *
 * @param serviceDefinition the Service Definition
 * @param planId the plan ID
 * @return the Plan
 */
protected Mono<Plan> getServiceDefinitionPlan(ServiceDefinition serviceDefinition, String planId) {
	return Mono.justOrEmpty(serviceDefinition)
			.flatMap(serviceDef -> Mono.justOrEmpty(serviceDef.getPlans())
					.flatMap(plans -> Flux.fromIterable(plans)
							.filter(plan -> plan.getId().equals(planId))
							.singleOrEmpty()));
}
 
Example #21
Source File: ServiceFixture.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
private static Plan getPlanThree() {
	return Plan.builder()
			.id("plan-three-id")
			.name("Plan Three")
			.description("Description for Plan Three")
			.build();
}
 
Example #22
Source File: ServiceFixture.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
private static Plan getPlanTwo() {
	Schemas schemas = Schemas.builder()
			.serviceInstanceSchema(ServiceInstanceSchema.builder()
					.createMethodSchema(MethodSchema.builder()
							.parameters("$schema", "http://json-schema.org/draft-04/schema#")
							.parameters("type", "object")
							.build())
					.updateMethodSchema(MethodSchema.builder()
							.parameters("$schema", "http://json-schema.org/draft-04/schema#")
							.parameters("type", "object")
							.build())
					.build())
			.serviceBindingSchema(ServiceBindingSchema.builder()
					.createMethodSchema(MethodSchema.builder()
							.parameters("$schema", "http://json-schema.org/draft-04/schema#")
							.parameters("type", "object")
							.build())
					.build())
			.build();

	return Plan.builder()
			.id("plan-two-id")
			.name("Plan Two")
			.description("Description for Plan Two")
			.metadata("key1", "value1")
			.metadata("key2", "value2")
			.bindable(false)
			.free(true)
			.planUpdateable(true)
			.schemas(schemas)
			.maximumPollingDuration(180)
			.build();
}
 
Example #23
Source File: ServiceFixture.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
private static Plan getPlanOne() {
	return Plan.builder()
			.id("plan-one-id")
			.name("Plan One")
			.description("Description for Plan One")
			.maintenanceInfo(MaintenanceInfo.builder()
					.version("1.0.0-alpha+001")
					.description("Description for maintenance info")
					.build())
			.build();
}
 
Example #24
Source File: AppDeploymentInstanceWorkflow.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
protected Mono<List<BackingApplication>> getBackingApplicationsForService(ServiceDefinition serviceDefinition,
	Plan plan) {
	return findBrokeredService(serviceDefinition, plan)
		.flatMap(brokeredService -> Mono.justOrEmpty(brokeredService.getApps()))
		.map(backingApplications -> BackingApplications.builder()
			.backingApplications(backingApplications)
			.build());
}
 
Example #25
Source File: AppDeploymentInstanceWorkflow.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
protected Mono<List<BackingService>> getBackingServicesForService(ServiceDefinition serviceDefinition, Plan plan) {
	return findBrokeredService(serviceDefinition, plan)
		.flatMap(brokeredService -> Mono.justOrEmpty(brokeredService.getServices()))
		.map(backingServices -> BackingServices.builder()
			.backingServices(backingServices)
			.build());
}
 
Example #26
Source File: AppDeploymentInstanceWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private ServiceDefinition buildServiceDefinition(String serviceName, String planName) {
	return ServiceDefinition.builder()
		.id(serviceName + "-id")
		.name(serviceName)
		.plans(Plan.builder()
			.id(planName + "-id")
			.name(planName)
			.build())
		.build();
}
 
Example #27
Source File: ServiceDefinitionProxyTest.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
public void testUnproxy() {
    ServiceDefinitionProxy service = catalog
            .findServiceDefinition("f3cbab6a-5172-4ff1-a5c7-72990f0ce2aa");
    assertEquals(PlanProxy.class, service.getPlans().get(0).getClass());
    ServiceDefinition service2 = service.unproxy();
    assertEquals(Plan.class, service2.getPlans().get(0).getClass());
}
 
Example #28
Source File: AppDeploymentInstanceWorkflow.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
protected Mono<TargetSpec> getTargetForService(ServiceDefinition serviceDefinition, Plan plan) {
	return findBrokeredService(serviceDefinition, plan)
		.flatMap(brokeredService -> Mono.justOrEmpty(brokeredService.getTarget()));
}
 
Example #29
Source File: CatalogControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
private void assertCatalog(final String uri) {
	List<Plan> plans = serviceDefinition.getPlans();
	Schemas schemas = plans.get(1).getSchemas();
	Map<String, Object> createServiceInstanceSchema = schemas.getServiceInstanceSchema().getCreateMethodSchema()
			.getParameters();
	Map<String, Object> updateServiceInstanceSchema = schemas.getServiceInstanceSchema().getUpdateMethodSchema()
			.getParameters();
	Map<String, Object> createServiceBindingSchema = schemas.getServiceBindingSchema().getCreateMethodSchema()
			.getParameters();

	client.get().uri(uri)
			.accept(MediaType.APPLICATION_JSON)
			.exchange()
			.expectStatus().isOk()
			.expectHeader().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)
			.expectBody()
			.jsonPath("$.services").isNotEmpty()
			.jsonPath("$.services").isArray()
			.jsonPath("$.services[0]").isNotEmpty()
			.jsonPath("$.services[0].id").isEqualTo(serviceDefinition.getId())
			.jsonPath("$.services[0].name").isEqualTo(serviceDefinition.getName())
			.jsonPath("$.services[0].description").isEqualTo(serviceDefinition.getDescription())
			.jsonPath("$.services[0].bindable").isEqualTo(serviceDefinition.isBindable())
			.jsonPath("$.services[0].plan_updateable").doesNotExist()
			.jsonPath("$.services[0].instances_retrievable").doesNotExist()
			.jsonPath("$.services[0].bindings_retrievable").doesNotExist()
			.jsonPath("$.services[0].requires").isNotEmpty()
			.jsonPath("$.services[0].requires").isArray()
			.jsonPath("$.services[0].requires[0]").isEqualTo(SERVICE_REQUIRES_SYSLOG_DRAIN.toString())
			.jsonPath("$.services[0].requires[1]").isEqualTo(SERVICE_REQUIRES_ROUTE_FORWARDING.toString())
			.jsonPath("$.services[0].requires[2]").doesNotExist()
			.jsonPath("$.services[0].plans").isNotEmpty()
			.jsonPath("$.services[0].plans").isArray()
			.jsonPath("$.services[0].plans[0].id").isEqualTo(plans.get(0).getId())
			.jsonPath("$.services[0].plans[0].name").isEqualTo(plans.get(0).getName())
			.jsonPath("$.services[0].plans[0].description").isEqualTo(plans.get(0).getDescription())
			.jsonPath("$.services[0].plans[0].free").isEqualTo(plans.get(0).isFree())
			.jsonPath("$.services[0].plans[0].maintenance_info").isNotEmpty()
			.jsonPath("$.services[0].plans[0].maintenance_info.version").isEqualTo("1.0.0-alpha+001")
			.jsonPath("$.services[0].plans[0].maintenance_info.description")
			.isEqualTo("Description for maintenance info")
			.jsonPath("$.services[0].plans[1].id").isEqualTo(plans.get(1).getId())
			.jsonPath("$.services[0].plans[1].name").isEqualTo(plans.get(1).getName())
			.jsonPath("$.services[0].plans[1].description").isEqualTo(plans.get(1).getDescription())
			.jsonPath("$.services[0].plans[1].metadata").isEqualTo(plans.get(1).getMetadata())
			.jsonPath("$.services[0].plans[1].bindable").isEqualTo(plans.get(1).isBindable())
			.jsonPath("$.services[0].plans[1].free").isEqualTo(plans.get(1).isFree())
			.jsonPath("$.services[0].plans[1].plan_updateable").isEqualTo(plans.get(1).isPlanUpdateable())
			.jsonPath("$.services[0].plans[1].schemas.service_instance.create.parameters")
			.isEqualTo(createServiceInstanceSchema)
			.jsonPath("$.services[0].plans[1].schemas.service_instance.update.parameters")
			.isEqualTo(updateServiceInstanceSchema)
			.jsonPath("$.services[0].plans[1].schemas.service_binding.create.parameters")
			.isEqualTo(createServiceBindingSchema)
			.jsonPath("$.services[0].plans[1].maximum_polling_duration")
			.isEqualTo(plans.get(1).getMaximumPollingDuration())
			.jsonPath("$.services[0].plans[1].maintenance_info").doesNotExist()
			.jsonPath("$.services[0].plans[2].id").isEqualTo(plans.get(2).getId())
			.jsonPath("$.services[0].plans[2].name").isEqualTo(plans.get(2).getName())
			.jsonPath("$.services[0].plans[2].description").isEqualTo(plans.get(2).getDescription())
			.jsonPath("$.services[0].plans[2].free").isEqualTo(plans.get(2).isFree())
			.jsonPath("$.services[0].plans[2].maintenance_info").doesNotExist()
			.jsonPath("$.services[0].plans[3]").doesNotExist()
			.jsonPath("$.services[1]").doesNotExist();
}
 
Example #30
Source File: CreateServiceInstanceRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Test
void serializesAccordingToOsbSpecs() {
	Map<String, Object> parameters = new HashMap<>();
	parameters.put("field4", "value4");
	parameters.put("field5", "value5");

	Context context = CloudFoundryContext.builder()
			.organizationGuid("org-guid")
			.spaceGuid("space-guid").build();

	Context originatingIdentity = CloudFoundryContext.builder()
			.property("user_id", "user-id").build();

	CreateServiceInstanceRequest request = CreateServiceInstanceRequest.builder()
			.serviceInstanceId("service-instance-id")
			.serviceDefinitionId("service-definition-id")
			.planId("plan-id")
			.context(context)
			.parameters("field1", "value1")
			.parameters("field2", 2)
			.parameters("field3", true)
			.parameters(parameters)
			.asyncAccepted(true)
			.platformInstanceId("platform-instance-id")
			.apiInfoLocation("https://api.app.local")
			.originatingIdentity(originatingIdentity)
			.requestIdentity("request-id")
			.plan(Plan.builder().build())
			.serviceDefinition(ServiceDefinition.builder().build())
			.maintenanceInfo(
				new MaintenanceInfo("1.1.0", "Patch for CVE-x"))
			.build();

	DocumentContext json = JsonUtils.toJsonPath(request);

	// 6 OSB Fields should be present
	JsonPathAssert.assertThat(json).hasPath("$.plan_id").isEqualTo("plan-id");
	JsonPathAssert.assertThat(json).hasPath("$.service_id").isEqualTo("service-definition-id");
	JsonPathAssert.assertThat(json).hasMapAtPath("$.parameters").hasSize(5);
	JsonPathAssert.assertThat(json).hasPath("$.parameters.field1").isEqualTo("value1");
	JsonPathAssert.assertThat(json).hasMapAtPath("$.context").hasSize(3);
	JsonPathAssert.assertThat(json).hasMapAtPath("$.maintenance_info").hasSize(2);
	JsonPathAssert.assertThat(json).hasPath("$.maintenance_info.version").isEqualTo("1.1.0");
	JsonPathAssert.assertThat(json).hasPath("$.maintenance_info.description").isEqualTo("Patch for CVE-x");
	JsonPathAssert.assertThat(json).hasPath("$.space_guid").isEqualTo("space-guid");
	JsonPathAssert.assertThat(json).hasPath("$.organization_guid").isEqualTo("org-guid");
	JsonPathAssert.assertThat(json).hasNoPath("$.request_identity");


	// fields mapped outside of json body (typically http headers or request paths)
	// should be excluded
	JsonPathAssert.assertThat(json).hasMapAtPath("$").hasSize(7);
}