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.functions.config.snapshots.db
21 import io.mockk.verify
22 import kotlinx.coroutines.runBlocking
24 import kotlin.test.assertEquals
25 import kotlin.test.assertTrue
27 class ResourceConfigSnapshotServiceTest {
29 private val cfgRepository = mockk<ResourceConfigSnapshotRepository>()
31 private val cfgService = ResourceConfigSnapshotService(cfgRepository)
33 private val resourceId = "1"
34 private val resourceType = "PNF"
35 private val configSnapshot = "config_snapshot"
36 private val resourceStatus = ResourceConfigSnapshot.Status.RUNNING
39 fun findByResourceIdAndResourceTypeTest() {
40 val tr = ResourceConfigSnapshot()
41 tr.config_snapshot = "res"
44 cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any())
46 val res = cfgService.findByResourceIdAndResourceTypeAndStatus(resourceId, resourceType)
47 assertEquals(tr.config_snapshot, res)
52 fun createNewResourceConfigSnapshotTest() {
53 val tr = ResourceConfigSnapshot()
55 every { cfgRepository.saveAndFlush(any<ResourceConfigSnapshot>()) } returns tr
57 cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any())
59 val res = cfgService.write( configSnapshot, resourceId, resourceType, resourceStatus)
65 fun updateExistingResourceConfigSnapshotTest() {
66 val tr = ResourceConfigSnapshot()
68 every { cfgRepository.saveAndFlush(any<ResourceConfigSnapshot>()) } returns tr
70 cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any())
73 cfgRepository.deleteByResourceIdAndResourceTypeAndStatus(any(), any(), any())
75 val res = cfgService.write( configSnapshot, resourceId, resourceType)
77 cfgRepository.deleteByResourceIdAndResourceTypeAndStatus(eq(resourceId), eq(resourceType), eq(resourceStatus))