2 * Copyright © 2019 Bell Canada.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.cds.blueprintsprocessor.designer.api.handler
19 import kotlinx.coroutines.runBlocking
20 import org.hamcrest.Matchers.samePropertyValuesAs
21 import org.junit.Assert
23 import org.junit.runner.RunWith
24 import org.mockito.ArgumentCaptor
25 import org.mockito.ArgumentMatchers.any
26 import org.mockito.Mockito
27 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.domain.ResourceDictionary
28 import org.onap.ccsdk.cds.blueprintsprocessor.designer.api.repository.ResourceDictionaryRepository
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
30 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
31 import org.springframework.test.context.junit4.SpringRunner
33 @RunWith(SpringRunner::class)
34 class ResourceDictionaryHandlerTest {
36 private val mockRepository = Mockito.mock(ResourceDictionaryRepository::class.java)
37 private val resourceDictionaryHandler = ResourceDictionaryHandler(mockRepository)
40 fun testSaveResourceDictionary() {
41 val resourceDefinition: ResourceDefinition = JacksonUtils
43 "./../../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-db-source.json",
44 ResourceDefinition::class.java
47 val expectedResourceDictionary = ResourceDictionary()
48 expectedResourceDictionary.name = resourceDefinition.name
49 expectedResourceDictionary.updatedBy = resourceDefinition.updatedBy
50 expectedResourceDictionary.resourceDictionaryGroup = resourceDefinition.group
51 expectedResourceDictionary.tags = resourceDefinition.tags!!
52 expectedResourceDictionary.description = resourceDefinition.property.description!!
53 expectedResourceDictionary.dataType = resourceDefinition.property.type
54 expectedResourceDictionary.definition = resourceDefinition
57 val mockReturnValue = ResourceDictionary()
58 mockReturnValue.definition = ResourceDefinition()
59 Mockito.`when`(mockRepository.save(any(ResourceDictionary::class.java)))
60 .thenReturn(mockReturnValue)
63 resourceDictionaryHandler.saveResourceDefinition(resourceDefinition)
66 val argumentCaptor = ArgumentCaptor.forClass(ResourceDictionary::class.java)
67 Mockito.verify(mockRepository).save(argumentCaptor.capture())
69 Assert.assertThat(argumentCaptor.value, samePropertyValuesAs(expectedResourceDictionary))