aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin
diff options
context:
space:
mode:
authorJozsef Csongvai <jozsef.csongvai@bell.ca>2020-01-07 13:30:24 -0500
committerJozsef Csongvai <jozsef.csongvai@bell.ca>2020-01-08 14:22:24 -0500
commitcc969006532a1e1994ab6609b2c4ddcb0dc49d87 (patch)
treeccd23eab4814af59a746a3ce580a34af61be247a /ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin
parent5e5718c9191f125ad65bd9ab15334147bedd79cc (diff)
Add new endpoint for posting data-dictinary as ResourceDefinition
Starter-dictionaries and examples in the documentation have the type ResourceDefinition. The existing endpoint accepts ResourceDictionary which is the wrapping entity of ResourceDefinition. Issue-ID: CCSDK-1725 Change-Id: I07f925ba4f607a6eaecf5907ac6e08691578c3b5 Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandlerTest.kt71
1 files changed, 71 insertions, 0 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandlerTest.kt
new file mode 100644
index 000000000..db25b6c35
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/designer-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/designer/api/handler/ResourceDictionaryHandlerTest.kt
@@ -0,0 +1,71 @@
+/*
+ * Copyright © 2019 Bell Canada.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler
+
+import kotlinx.coroutines.runBlocking
+import org.hamcrest.Matchers.samePropertyValuesAs
+import org.junit.Assert
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.mockito.ArgumentCaptor
+import org.mockito.ArgumentMatchers.any
+import org.mockito.Mockito
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
+import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ResourceDictionaryRepository
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
+import org.springframework.test.context.junit4.SpringRunner
+
+@RunWith(SpringRunner::class)
+class ResourceDictionaryHandlerTest {
+
+ private val mockRepository = Mockito.mock(ResourceDictionaryRepository::class.java)
+ private val resourceDictionaryHandler = ResourceDictionaryHandler(mockRepository)
+
+ @Test
+ fun testSaveResourceDictionary() {
+ val resourceDefinition: ResourceDefinition = JacksonUtils
+ .readValueFromFile(
+ "./../../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-db-source.json",
+ ResourceDefinition::class.java
+ )!!
+
+ val expectedResourceDictionary = ResourceDictionary()
+ expectedResourceDictionary.name = resourceDefinition.name
+ expectedResourceDictionary.updatedBy = resourceDefinition.updatedBy
+ expectedResourceDictionary.resourceDictionaryGroup = resourceDefinition.group
+ expectedResourceDictionary.tags = resourceDefinition.tags!!
+ expectedResourceDictionary.description = resourceDefinition.property.description!!
+ expectedResourceDictionary.dataType = resourceDefinition.property.type
+ expectedResourceDictionary.definition = resourceDefinition
+
+ // Mock save success
+ val mockReturnValue = ResourceDictionary()
+ mockReturnValue.definition = ResourceDefinition()
+ Mockito.`when`(mockRepository.save(any(ResourceDictionary::class.java)))
+ .thenReturn(mockReturnValue)
+
+ runBlocking {
+ resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
+ }
+
+ val argumentCaptor = ArgumentCaptor.forClass(ResourceDictionary::class.java)
+ Mockito.verify(mockRepository).save(argumentCaptor.capture())
+
+ Assert.assertThat(argumentCaptor.value, samePropertyValuesAs(expectedResourceDictionary))
+ }
+}