Upgrade Swager Codegen-maven-plugin
[cps.git] / cps-rest / src / test / groovy / org / onap / cps / rest / controller / DataRestControllerSpec.groovy
index b64b561..8675f42 100755 (executable)
@@ -9,6 +9,7 @@
  *  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.
@@ -33,10 +34,6 @@ import org.onap.cps.api.CpsAdminService
 import org.onap.cps.api.CpsDataService
 import org.onap.cps.api.CpsModuleService
 import org.onap.cps.api.CpsQueryService
-import org.onap.cps.spi.exceptions.AlreadyDefinedException
-import org.onap.cps.spi.exceptions.AnchorNotFoundException
-import org.onap.cps.spi.exceptions.DataNodeNotFoundException
-import org.onap.cps.spi.exceptions.DataspaceNotFoundException
 import org.onap.cps.spi.model.DataNode
 import org.onap.cps.spi.model.DataNodeBuilder
 import org.spockframework.spring.SpringBean
@@ -49,24 +46,12 @@ import org.springframework.test.web.servlet.MockMvc
 import spock.lang.Shared
 import spock.lang.Specification
 
-@WebMvcTest
+@WebMvcTest(DataRestController)
 class DataRestControllerSpec extends Specification {
 
     @SpringBean
     CpsDataService mockCpsDataService = Mock()
 
-    @SpringBean
-    CpsModuleService mockCpsModuleService = Mock()
-
-    @SpringBean
-    CpsAdminService mockCpsAdminService = Mock()
-
-    @SpringBean
-    CpsQueryService mockCpsQueryService = Mock()
-
-    @SpringBean
-    ModelMapper modelMapper = Mock()
-
     @Autowired
     MockMvc mvc
 
@@ -131,6 +116,23 @@ class DataRestControllerSpec extends Specification {
             1 * mockCpsDataService.saveData(dataspaceName, anchorName, parentNodeXpath, json)
     }
 
+    def 'Create list node child elements.'() {
+        given: 'parent node xpath and json data inputs'
+            def parentNodeXpath = 'parent node xpath'
+            def jsonData = 'json data'
+        when: 'post is invoked list-node endpoint'
+            def response = mvc.perform(
+                    post("$dataNodeBaseEndpoint/anchors/$anchorName/list-node")
+                            .contentType(MediaType.APPLICATION_JSON)
+                            .param('xpath', parentNodeXpath)
+                            .content(jsonData)
+            ).andReturn().response
+        then: 'a created response is returned'
+            response.status == HttpStatus.CREATED.value()
+        then: 'the java API was called with the correct parameters'
+            1 * mockCpsDataService.saveListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData)
+    }
+
     def 'Get data node with leaves'() {
         given: 'the service returns data node leaves'
             def xpath = 'some xPath'
@@ -216,4 +218,21 @@ class DataRestControllerSpec extends Specification {
             'root node by choice'  | '/'           || '/'
             'some xpath by parent' | '/some/xpath' || '/some/xpath'
     }
+
+    def 'Replace list node child elements.'() {
+        given: 'parent node xpath and json data inputs'
+            def parentNodeXpath = 'parent node xpath'
+            def jsonData = 'json data'
+        when: 'patch is invoked list-node endpoint'
+            def response = mvc.perform(
+                    patch("$dataNodeBaseEndpoint/anchors/$anchorName/list-node")
+                            .contentType(MediaType.APPLICATION_JSON)
+                            .param('xpath', parentNodeXpath)
+                            .content(jsonData)
+            ).andReturn().response
+        then: 'a success response is returned'
+            response.status == HttpStatus.OK.value()
+        then: 'the java API was called with the correct parameters'
+            1 * mockCpsDataService.replaceListNodeData(dataspaceName, anchorName, parentNodeXpath, jsonData)
+    }
 }