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)
51 @Test(expected = NoSuchElementException::class)
52 fun notFoundEntryReturnsExceptionTest() {
53 val tr = ResourceConfigSnapshot()
56 cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any())
58 val snap = cfgService.findByResourceIdAndResourceTypeAndStatus("MISSING_ID", "UNKNOWN_TYPE")
59 assertTrue ( snap.isBlank(), "Not found but returned a non empty string" )
64 fun createNewResourceConfigSnapshotTest() {
65 val tr = ResourceConfigSnapshot()
67 every { cfgRepository.saveAndFlush(any<ResourceConfigSnapshot>()) } returns tr
69 cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any())
71 val res = cfgService.write( configSnapshot, resourceId, resourceType, resourceStatus)
77 fun updateExistingResourceConfigSnapshotTest() {
78 val tr = ResourceConfigSnapshot()
80 every { cfgRepository.saveAndFlush(any<ResourceConfigSnapshot>()) } returns tr
82 cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any())
85 cfgRepository.deleteByResourceIdAndResourceTypeAndStatus(any(), any(), any())
87 val res = cfgService.write( configSnapshot, resourceId, resourceType)
89 cfgRepository.deleteByResourceIdAndResourceTypeAndStatus(eq(resourceId), eq(resourceType), eq(resourceStatus))