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
26 class ResourceConfigSnapshotServiceTest {
28 private val cfgRepository = mockk<ResourceConfigSnapshotRepository>()
30 private val cfgService = ResourceConfigSnapshotService(cfgRepository)
32 private val resourceId = "1"
33 private val resourceType = "PNF"
34 private val configSnapshot = "config_snapshot"
35 private val resourceStatus = ResourceConfigSnapshot.Status.RUNNING
38 fun findByResourceIdAndResourceTypeTest() {
39 val tr = ResourceConfigSnapshot()
40 tr.config_snapshot = "res"
43 cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any())
45 val res = cfgService.findByResourceIdAndResourceTypeAndStatus(resourceId, resourceType)
46 assertEquals(tr.config_snapshot, res)
51 fun createNewResourceConfigSnapshotTest() {
52 val tr = ResourceConfigSnapshot()
54 every { cfgRepository.saveAndFlush(any<ResourceConfigSnapshot>()) } returns tr
56 cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any())
58 val res = cfgService.write( configSnapshot, resourceId, resourceType, resourceStatus)
64 fun updateExistingResourceConfigSnapshotTest() {
65 val tr = ResourceConfigSnapshot()
67 every { cfgRepository.saveAndFlush(any<ResourceConfigSnapshot>()) } returns tr
69 cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any())
72 cfgRepository.deleteByResourceIdAndResourceTypeAndStatus(any(), any(), any())
74 val res = cfgService.write( configSnapshot, resourceId, resourceType)
76 cfgRepository.deleteByResourceIdAndResourceTypeAndStatus(eq(resourceId), eq(resourceType), eq(resourceStatus))