summaryrefslogtreecommitdiffstats
path: root/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy')
-rw-r--r--src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
index b42eb4d2..2f200cfa 100644
--- a/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
+++ b/src/test/groovy/org/onap/cps/ncmp/dmi/rest/controller/DmiRestControllerSpec.groovy
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2021 Nordix Foundation
+ * Copyright (C) 2021-2022 Nordix Foundation
* Modifications Copyright (C) 2021-2022 Bell Canada
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,7 +21,6 @@
package org.onap.cps.ncmp.dmi.rest.controller
-import com.fasterxml.jackson.databind.ObjectMapper
import org.onap.cps.ncmp.dmi.TestUtils
import org.onap.cps.ncmp.dmi.exception.DmiException
import org.onap.cps.ncmp.dmi.exception.ModuleResourceNotFoundException
@@ -36,7 +35,6 @@ import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
-import org.springframework.context.annotation.Import
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.security.test.context.support.WithMockUser
@@ -56,15 +54,14 @@ import static org.springframework.http.HttpStatus.OK
@WebMvcTest(DmiRestController)
@WithMockUser
-@Import(ObjectMapper)
class DmiRestControllerSpec extends Specification {
- @SpringBean
- DmiService mockDmiService = Mock()
-
@Autowired
private MockMvc mvc
+ @SpringBean
+ DmiService mockDmiService = Mock()
+
@Value('${rest.api.dmi-base-path}/v1')
def basePathV1
@@ -95,18 +92,19 @@ class DmiRestControllerSpec extends Specification {
def getModuleUrl = "$basePathV1/ch/node1/modules"
and: 'given request body and get modules for cm-handle throws #exceptionClass'
def json = '{"cmHandleProperties" : {}}'
- mockDmiService.getModulesForCmHandle('node1') >> { throw Mock(exceptionClass) }
+ mockDmiService.getModulesForCmHandle('node1') >> { throw exception }
when: 'post is invoked'
def response = mvc.perform( post(getModuleUrl)
.contentType(MediaType.APPLICATION_JSON).content(json))
.andReturn().response
then: 'response status is #expectedResponse'
- response.status == expectedResponse
+ response.status == expectedResponse.value()
where: 'the scenario is #scenario'
- scenario | exceptionClass || expectedResponse
- 'dmi service exception' | DmiException.class || HttpStatus.INTERNAL_SERVER_ERROR.value()
- 'no modules found' | ModulesNotFoundException.class || HttpStatus.NOT_FOUND.value()
- 'any other runtime exception' | RuntimeException.class || HttpStatus.INTERNAL_SERVER_ERROR.value()
+ scenario | exception || expectedResponse
+ 'dmi service exception' | new DmiException('','') || HttpStatus.INTERNAL_SERVER_ERROR
+ 'no modules found' | new ModulesNotFoundException('','') || HttpStatus.NOT_FOUND
+ 'any other runtime exception' | new RuntimeException() || HttpStatus.INTERNAL_SERVER_ERROR
+ 'runtime exception with cause' | new RuntimeException('', new RuntimeException()) || HttpStatus.INTERNAL_SERVER_ERROR
}
def 'Register given list.'() {