diff options
author | puthuparambil.aditya <aditya.puthuparambil@bell.ca> | 2021-01-06 11:28:08 +0000 |
---|---|---|
committer | puthuparambil.aditya <aditya.puthuparambil@bell.ca> | 2021-01-06 11:41:16 +0000 |
commit | ec3e17505d12785586fc2418438c3d45b63d7dbd (patch) | |
tree | 4c65f9fd52ddae219f2af36dbb6460f6d96e3111 | |
parent | 69fc5b35d884afaea6cd4d96734a4f7607723997 (diff) |
WebMVC groovy test cases for AdminRestController
Issue-ID: CPS-129
Signed-off-by: puthuparambil.aditya <aditya.puthuparambil@bell.ca>
Change-Id: Id4bdfb7b6602244ae5abac646a9ec9f68f63cad2
-rw-r--r-- | cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy | 39 |
1 files changed, 38 insertions, 1 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 f0d5b3fa22..ed87e3c95a 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 @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Pantheon.tech + * Modifications Copyright (C) 2020 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,15 +23,23 @@ package org.onap.cps.rest.controller import org.modelmapper.ModelMapper import org.onap.cps.api.CpsAdminService import org.onap.cps.api.CpsModuleService +import org.onap.cps.spi.model.Anchor 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 import org.springframework.mock.web.MockMultipartFile import org.springframework.test.web.servlet.MockMvc import org.springframework.test.web.servlet.request.MockMvcRequestBuilders +import org.springframework.util.LinkedMultiValueMap +import org.springframework.util.MultiValueMap import spock.lang.Specification +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post + @WebMvcTest class AdminRestControllerSpec extends Specification { @@ -41,11 +50,16 @@ class AdminRestControllerSpec extends Specification { CpsAdminService mockCpsAdminService = Mock() @SpringBean - ModelMapper modelMapper = Mock(); + ModelMapper modelMapper = Mock() @Autowired MockMvc mvc + def anchorsEndpoint = '/v1/dataspaces/my_dataspace/anchors' + + def anchor = new Anchor(name: 'my_anchor') + def anchorList = [anchor] + def 'Create schema set from yang file'() { def yangResourceMapCapture given: @@ -82,4 +96,27 @@ class AdminRestControllerSpec extends Specification { ).andReturn().response } + def 'when createAnchor API is called, the response status is 201. '() { + given: + def requestParams = new LinkedMultiValueMap<>() + requestParams.add('schema-set-name', 'my_schema-set') + requestParams.add('anchor-name', 'my_anchor') + 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' + 1 * mockCpsAdminService.createAnchor('my_dataspace', 'my_schema-set', 'my_anchor') + assert response.status == HttpStatus.CREATED.value() + assert response.getContentAsString().contains('my_anchor') + } + + def 'when get all anchors for a dataspace API is called, the response status is 200 '() { + 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') + } } |