This repository has been archived by the owner on Dec 13, 2021. It is now read-only.
/
ServiceBrokerServiceProviderSyncFunctionalSpec.groovy
133 lines (107 loc) · 5.52 KB
/
ServiceBrokerServiceProviderSyncFunctionalSpec.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
* Copyright (c) 2018 Swisscom (Switzerland) Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/
package com.swisscom.cloud.sb.broker.functional
import com.swisscom.cloud.sb.broker.model.CFService
import com.swisscom.cloud.sb.broker.model.Plan
import com.swisscom.cloud.sb.broker.services.common.ServiceProviderLookup
import com.swisscom.cloud.sb.broker.services.genericserviceprovider.TestableServiceBrokerServiceProvider
import com.swisscom.cloud.sb.broker.util.test.DummySynchronousServiceProvider
import org.springframework.http.HttpStatus
import org.springframework.web.client.HttpClientErrorException
class ServiceBrokerServiceProviderSyncFunctionalSpec extends BaseFunctionalSpec {
private
final String SYNC_SERVICE_BROKER_SERVICE_PROVIDER_SERVICE_INSTANCE_ID = "syncServiceBrokerServiceProviderInstanceId"
private final String BASE_URL = "baseUrl"
private final String USERNAME = "username"
private final String PASSWORD = "password"
private final String SERVICE_ID = "service-guid"
private final String PLAN_ID = "plan-guid"
private CFService dummySyncService
private final String dummySyncPlanId = "dummySyncPlanId"
private Plan dummySyncPlan
void addParameters() {
// parameters are added to plan which is used for the ServiceBrokerServiceProvider
serviceLifeCycler.createParameter(BASE_URL, "http://localhost:8080", serviceLifeCycler.plan)
serviceLifeCycler.createParameter(USERNAME, cfAdminUser.username, serviceLifeCycler.plan)
serviceLifeCycler.createParameter(PASSWORD, cfAdminUser.password, serviceLifeCycler.plan)
}
def setup() {
dummySyncPlan = new Plan(guid: dummySyncPlanId, name: "syncDummyServiceBrokerPlan", description: "Plan for SyncDummyServiceBroker", asyncRequired: false)
dummySyncService = serviceLifeCycler.createServiceIfDoesNotExist('SyncDummyServiceProvider', ServiceProviderLookup.findInternalName(DummySynchronousServiceProvider.class), null, null, null, 0, false, false, null, null, null, dummySyncPlan)
// creating service for TestableServiceBrokerServiceProvider
serviceLifeCycler.createServiceIfDoesNotExist('syncDummyServiceProvider', ServiceProviderLookup.findInternalName(TestableServiceBrokerServiceProvider.class))
}
def cleanupSpec() {
serviceLifeCycler.cleanup()
}
def "provision and bind sync service instance"() {
setup:
addParameters()
serviceLifeCycler.createParameter(SERVICE_ID, dummySyncService.guid, serviceLifeCycler.plan)
serviceLifeCycler.createParameter(PLAN_ID, dummySyncPlan.guid, serviceLifeCycler.plan)
serviceLifeCycler.setAsyncRequestInPlan(false)
when:
serviceLifeCycler.setServiceInstanceId(SYNC_SERVICE_BROKER_SERVICE_PROVIDER_SERVICE_INSTANCE_ID)
serviceLifeCycler.createServiceInstanceAndAssert(0, false, false)
and:
serviceLifeCycler.createServiceBindingAndAssert(0, false, false, null)
then:
noExceptionThrown()
cleanup:
serviceLifeCycler.removeParameters()
}
def "get usage of provisioned service"() {
given:
serviceLifeCycler.setAsyncRequestInPlan(false)
serviceLifeCycler.setServiceInstanceId(SYNC_SERVICE_BROKER_SERVICE_PROVIDER_SERVICE_INSTANCE_ID)
when:
def response = serviceBrokerClient.getUsage(SYNC_SERVICE_BROKER_SERVICE_PROVIDER_SERVICE_INSTANCE_ID)
then:
response.statusCode.'2xxSuccessful'
response.body.value.length() > 0
}
def "provision same sync service instance as above for conflict"() {
setup:
addParameters()
serviceLifeCycler.createParameter(SERVICE_ID, dummySyncService.guid, serviceLifeCycler.plan)
serviceLifeCycler.createParameter(PLAN_ID, dummySyncPlan.guid, serviceLifeCycler.plan)
serviceLifeCycler.setAsyncRequestInPlan(false)
when:
serviceLifeCycler.createServiceInstanceAndAssert(0, false, false)
then:
HttpClientErrorException e = thrown()
e.statusCode == HttpStatus.CONFLICT
cleanup:
//for cleanup the id of the service instance provisioned via the sbsp needs to be added to the set of serviceInstanceIds
serviceLifeCycler.setServiceInstanceId(SYNC_SERVICE_BROKER_SERVICE_PROVIDER_SERVICE_INSTANCE_ID)
serviceLifeCycler.removeParameters()
}
def "unbind and deprovision sync service instance"() {
setup:
addParameters()
serviceLifeCycler.createParameter(SERVICE_ID, dummySyncService.guid, serviceLifeCycler.plan)
serviceLifeCycler.createParameter(PLAN_ID, dummySyncPlan.guid, serviceLifeCycler.plan)
and:
serviceLifeCycler.setAsyncRequestInPlan(false)
serviceLifeCycler.setServiceInstanceId(SYNC_SERVICE_BROKER_SERVICE_PROVIDER_SERVICE_INSTANCE_ID)
serviceLifeCycler.deleteServiceBindingAndAssert(null)
when:
serviceLifeCycler.deleteServiceInstanceAndAssert()
then:
noExceptionThrown()
cleanup:
serviceLifeCycler.removeParameters()
}
}