Replace gson mapper with jackson mapper
[cps.git] / cps-ncmp-service / src / test / groovy / org / onap / cps / ncmp / api / impl / operations / DmiModelOperationsSpec.groovy
index 335bc06..2efd6c2 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2021 Nordix Foundation
+ *  Copyright (C) 2021-2022 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
 package org.onap.cps.ncmp.api.impl.operations
 
 import com.fasterxml.jackson.core.JsonProcessingException
+import com.fasterxml.jackson.databind.ObjectMapper
 import org.onap.cps.ncmp.api.impl.config.NcmpConfiguration
-import org.onap.cps.ncmp.api.impl.exception.NcmpException
 import org.onap.cps.spi.model.ModuleReference
+import org.onap.cps.utils.JsonObjectMapper
+import org.spockframework.spring.SpringBean
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.boot.test.context.SpringBootTest
 import org.springframework.http.HttpStatus
@@ -41,6 +43,9 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
     @Autowired
     DmiModelOperations objectUnderTest
 
+    @SpringBean
+    JsonObjectMapper spiedJsonObjectMapper = Spy(new JsonObjectMapper(new ObjectMapper()))
+
     def 'Retrieving module references.'() {
         given: 'a persistence cm handle'
             mockPersistenceCmHandleRetrieval([])
@@ -158,11 +163,11 @@ class DmiModelOperationsSpec extends DmiOperationsBaseSpec {
         given: 'a persistence cm handle'
             mockPersistenceCmHandleRetrieval([])
         and: 'a Json processing exception occurs'
-            spyObjectMapper.writeValueAsString(_) >> {throw (new JsonProcessingException(''))}
+            spiedJsonObjectMapper.asJsonString(_) >> {throw (new JsonProcessingException('parsing error'))}
         when: 'a dmi operation is executed'
             objectUnderTest.getModuleReferences(persistenceCmHandle)
         then: 'an ncmp exception is thrown'
-            def exceptionThrown = thrown(NcmpException)
+            def exceptionThrown = thrown(JsonProcessingException)
         and: 'the message indicates a parsing error'
             exceptionThrown.message.toLowerCase().contains('parsing error')
     }