summaryrefslogtreecommitdiffstats
path: root/cps-rest/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'cps-rest/src/test')
-rw-r--r--cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy39
1 files changed, 26 insertions, 13 deletions
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
index 9919649cb0..078253a64e 100644
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
@@ -25,9 +25,9 @@ import org.onap.cps.api.CpsAdminService
import org.onap.cps.api.CpsModuleService
import org.onap.cps.spi.model.Anchor
import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException
+import org.onap.cps.spi.model.SchemaSet
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
@@ -57,6 +57,8 @@ class AdminRestControllerSpec extends Specification {
MockMvc mvc
def anchorsEndpoint = '/v1/dataspaces/my_dataspace/anchors'
+ def schemaSetsEndpoint = '/v1/dataspaces/test-dataspace/schema-sets'
+ def schemaSetEndpoint = schemaSetsEndpoint + '/my_schema_set'
def anchor = new Anchor(name: 'my_anchor')
def anchorList = [anchor]
@@ -66,7 +68,7 @@ class AdminRestControllerSpec extends Specification {
def response = performCreateDataspaceRequest("new-dataspace")
then: 'Service method is invoked with expected parameters'
1 * mockCpsAdminService.createDataspace("new-dataspace")
- and:
+ and: 'Dataspace is create successfully'
response.status == HttpStatus.CREATED.value()
}
@@ -76,7 +78,7 @@ class AdminRestControllerSpec extends Specification {
mockCpsAdminService.createDataspace("existing-dataspace") >> { throw thrownException }
when:
def response = performCreateDataspaceRequest("existing-dataspace")
- then:
+ then: 'Dataspace creation fails'
response.status == HttpStatus.BAD_REQUEST.value()
}
@@ -99,7 +101,7 @@ class AdminRestControllerSpec extends Specification {
def multipartFile = createMultipartFile("filename.doc", "content")
when:
def response = performCreateSchemaSetRequest(multipartFile)
- then:
+ then: 'Create schema fails'
response.status == HttpStatus.BAD_REQUEST.value()
}
@@ -118,13 +120,24 @@ class AdminRestControllerSpec extends Specification {
def performCreateSchemaSetRequest(multipartFile) {
return mvc.perform(
MockMvcRequestBuilders
- .multipart('/v1/dataspaces/test-dataspace/schema-sets')
+ .multipart(schemaSetsEndpoint)
.file(multipartFile)
.param('schemaSetName', 'test-schema-set')
).andReturn().response
}
- def 'when createAnchor API is called, the response status is 201. '() {
+ def 'Get existing schema set'() {
+ given:
+ mockCpsModuleService.getSchemaSet('test-dataspace', 'my_schema_set') >>
+ new SchemaSet(name: 'my_schema_set', dataspaceName: 'test-dataspace')
+ when: 'get schema set API is invoked'
+ def response = mvc.perform(get(schemaSetEndpoint)).andReturn().response
+ then: 'the correct schema set is returned'
+ response.status == HttpStatus.OK.value()
+ response.getContentAsString().contains('my_schema_set')
+ }
+
+ def 'Create Anchor'() {
given:
def requestParams = new LinkedMultiValueMap<>()
requestParams.add('schema-set-name', 'my_schema-set')
@@ -132,19 +145,19 @@ class AdminRestControllerSpec extends Specification {
when: 'post is invoked'
def response = mvc.perform(post(anchorsEndpoint).contentType(MediaType.APPLICATION_JSON)
.params(requestParams as MultiValueMap)).andReturn().response
- then: 'Status is 201 and the response is the name of the created anchor -> my_anchor'
+ then: 'Anchor is created successfully'
1 * mockCpsAdminService.createAnchor('my_dataspace', 'my_schema-set', 'my_anchor')
- assert response.status == HttpStatus.CREATED.value()
- assert response.getContentAsString().contains('my_anchor')
+ response.status == HttpStatus.CREATED.value()
+ response.getContentAsString().contains('my_anchor')
}
- def 'when get all anchors for a dataspace API is called, the response status is 200 '() {
+ def 'Get existing anchor'() {
given:
mockCpsAdminService.getAnchors('my_dataspace') >> anchorList
when: 'get all anchors API is invoked'
def response = mvc.perform(get(anchorsEndpoint)).andReturn().response
- then: 'Status is 200 and the response is Collection of Anchors containing anchor name -> my_anchor'
- assert response.status == HttpStatus.OK.value()
- assert response.getContentAsString().contains('my_anchor')
+ then: 'the correct anchor is returned'
+ response.status == HttpStatus.OK.value()
+ response.getContentAsString().contains('my_anchor')
}
}