diff options
author | ToineSiebelink <toine.siebelink@est.tech> | 2023-12-18 12:25:41 +0000 |
---|---|---|
committer | ToineSiebelink <toine.siebelink@est.tech> | 2023-12-18 16:58:16 +0000 |
commit | a966bab93a17fcba4e7fc28354c01b3f0878fbbe (patch) | |
tree | 0e267217d3871727c1440569faaf52b25bbea4dc /cps-rest/src/test | |
parent | 597d4ef72e5388092cc80ae662af6711f735369f (diff) |
Remove the dependency-cycle between beans
- Splitting admin service into AnchorService and DataspaceService
(this resolves the cyclic dependency)
- Improved Delete dataspace integration error tests
(were depending on execution order, now independent)
Issue-ID: CPS-871
Change-Id: I47efedb6eb4bd2900f72d689616b7b7b62df2938
Signed-off-by: halil.cakal <halil.cakal@est.tech>
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Diffstat (limited to 'cps-rest/src/test')
-rwxr-xr-x | cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy | 44 | ||||
-rw-r--r-- | cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy | 10 |
2 files changed, 32 insertions, 22 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 f81efd6698..81ac511a9f 100755 --- 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 @@ -23,6 +23,8 @@ package org.onap.cps.rest.controller +import org.onap.cps.api.CpsAnchorService + import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get @@ -30,7 +32,7 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post import org.mapstruct.factory.Mappers -import org.onap.cps.api.CpsAdminService +import org.onap.cps.api.CpsDataspaceService import org.onap.cps.api.CpsModuleService import org.onap.cps.spi.exceptions.AlreadyDefinedException import org.onap.cps.spi.exceptions.SchemaSetInUseException @@ -56,7 +58,10 @@ class AdminRestControllerSpec extends Specification { CpsModuleService mockCpsModuleService = Mock() @SpringBean - CpsAdminService mockCpsAdminService = Mock() + CpsDataspaceService mockCpsDataspaceService = Mock() + + @SpringBean + CpsAnchorService mockCpsAnchorService = Mock() @SpringBean CpsRestInputMapper cpsRestInputMapper = Mappers.getMapper(CpsRestInputMapper) @@ -76,26 +81,27 @@ class AdminRestControllerSpec extends Specification { def 'Create new dataspace with #scenario.'() { when: 'post is invoked' def response = - mvc.perform( - post("/cps/api/${apiVersion}/dataspaces") - .param('dataspace-name', dataspaceName)) - .andReturn().response + mvc.perform( + post("/cps/api/${apiVersion}/dataspaces") + .param('dataspace-name', dataspaceName)) + .andReturn().response then: 'service method is invoked with expected parameters' - 1 * mockCpsAdminService.createDataspace(dataspaceName) + 1 * mockCpsDataspaceService.createDataspace(dataspaceName) and: 'dataspace is create successfully' response.status == HttpStatus.CREATED.value() assert response.getContentAsString() == expectedResponseBody where: 'following cases are tested' - scenario | apiVersion || expectedResponseBody - 'V1 API' | 'v1' || 'my_dataspace' - 'V2 API' | 'v2' || '' - } + scenario | apiVersion || expectedResponseBody + 'V1 API' | 'v1' || 'my_dataspace' + 'V2 API' | 'v2' || '' + } + def 'Create dataspace over existing with same name.'() { given: 'an endpoint' def createDataspaceEndpoint = "$basePath/v1/dataspaces" and: 'the service method throws an exception indicating the dataspace is already defined' def thrownException = new AlreadyDefinedException(dataspaceName, new RuntimeException()) - mockCpsAdminService.createDataspace(dataspaceName) >> { throw thrownException } + mockCpsDataspaceService.createDataspace(dataspaceName) >> { throw thrownException } when: 'post is invoked' def response = mvc.perform( @@ -108,7 +114,7 @@ class AdminRestControllerSpec extends Specification { def 'Get a dataspace.'() { given: 'service method returns a dataspace' - mockCpsAdminService.getDataspace(dataspaceName) >> dataspace + mockCpsDataspaceService.getDataspace(dataspaceName) >> dataspace and: 'an endpoint' def getDataspaceEndpoint = "$basePath/v1/admin/dataspaces/$dataspaceName" when: 'get dataspace API is invoked' @@ -120,7 +126,7 @@ class AdminRestControllerSpec extends Specification { def 'Get all dataspaces.'() { given: 'service method returns all dataspace' - mockCpsAdminService.getAllDataspaces() >> [dataspace, new Dataspace(name: "dataspace-test2")] + mockCpsDataspaceService.getAllDataspaces() >> [dataspace, new Dataspace(name: "dataspace-test2")] and: 'an endpoint' def getAllDataspaceEndpoint = "$basePath/v1/admin/dataspaces" when: 'get all dataspace API is invoked' @@ -317,7 +323,7 @@ class AdminRestControllerSpec extends Specification { .params(requestParams as MultiValueMap)) .andReturn().response then: 'anchor is created successfully' - 1 * mockCpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorName) + 1 * mockCpsAnchorService.createAnchor(dataspaceName, schemaSetName, anchorName) assert response.status == HttpStatus.CREATED.value() assert response.getContentAsString() == expectedResponseBody where: 'following cases are tested' @@ -328,7 +334,7 @@ class AdminRestControllerSpec extends Specification { def 'Get existing anchor.'() { given: 'service method returns a list of anchors' - mockCpsAdminService.getAnchors(dataspaceName) >> [anchor] + mockCpsAnchorService.getAnchors(dataspaceName) >> [anchor] and: 'an endpoint' def anchorEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors" when: 'get all anchors API is invoked' @@ -340,7 +346,7 @@ class AdminRestControllerSpec extends Specification { def 'Get existing anchor by dataspace and anchor name.'() { given: 'service method returns an anchor' - mockCpsAdminService.getAnchor(dataspaceName, anchorName) >> + mockCpsAnchorService.getAnchor(dataspaceName, anchorName) >> new Anchor(name: anchorName, dataspaceName: dataspaceName, schemaSetName: schemaSetName) and: 'an endpoint' def anchorEndpoint = "$basePath/v1/dataspaces/$dataspaceName/anchors/$anchorName" @@ -360,7 +366,7 @@ class AdminRestControllerSpec extends Specification { when: 'delete method is invoked on anchor endpoint' def response = mvc.perform(delete(anchorEndpoint)).andReturn().response then: 'associated service method is invoked with expected parameters' - 1 * mockCpsAdminService.deleteAnchor(dataspaceName, anchorName) + 1 * mockCpsAnchorService.deleteAnchor(dataspaceName, anchorName) and: 'response code indicates success' response.status == HttpStatus.NO_CONTENT.value() } @@ -373,7 +379,7 @@ class AdminRestControllerSpec extends Specification { .param('dataspace-name', dataspaceName)) .andReturn().response then: 'associated service method is invoked with expected parameter' - 1 * mockCpsAdminService.deleteDataspace(dataspaceName) + 1 * mockCpsDataspaceService.deleteDataspace(dataspaceName) and: 'response code indicates success' response.status == HttpStatus.NO_CONTENT.value() } diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy index 535b83df76..ff2bed4347 100644 --- a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy +++ b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy @@ -26,7 +26,8 @@ package org.onap.cps.rest.exceptions import com.fasterxml.jackson.databind.ObjectMapper import groovy.json.JsonSlurper -import org.onap.cps.api.CpsAdminService +import org.onap.cps.api.CpsDataspaceService +import org.onap.cps.api.CpsAnchorService import org.onap.cps.api.CpsDataService import org.onap.cps.api.CpsModuleService import org.onap.cps.api.CpsQueryService @@ -63,7 +64,10 @@ import static org.springframework.test.web.servlet.request.MockMvcRequestBuilder class CpsRestExceptionHandlerSpec extends Specification { @SpringBean - CpsAdminService mockCpsAdminService = Stub() + CpsDataspaceService mockCpsAdminService = Stub() + + @SpringBean + CpsAnchorService mockCpsAnchorService = Stub() @SpringBean CpsModuleService mockCpsModuleService = Stub() @@ -198,7 +202,7 @@ class CpsRestExceptionHandlerSpec extends Specification { */ def setupTestException(exception) { - mockCpsAdminService.getAnchors(_) >> { throw exception } + mockCpsAnchorService.getAnchors(_) >> { throw exception } } def performTestRequest() { |