diff options
author | Singal, Kapil (ks220y) <ks220y@att.com> | 2019-11-22 18:06:08 -0500 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2019-11-26 21:32:38 +0000 |
commit | 341db21b2ac0a14a1ed2b8bf7930914dda054bfe (patch) | |
tree | 113bba965b06cfe3a8af3a0a527d1a41c9faf0f9 /ms/blueprintsprocessor/functions/config-snapshots/src/test | |
parent | d274e5fc552cf9ae25500f504f0434981cf3accf (diff) |
Formatting Code base with ktlint
No Business logic change, just the code format.
Competible with IntelliJ: https://github.com/pinterest/ktlint#option-3
To format run: mvn process-sources -P format
Issue-ID: CCSDK-1947
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
Change-Id: Ic9e9209fb7023d77f434693ad5a01229f8d09331
Diffstat (limited to 'ms/blueprintsprocessor/functions/config-snapshots/src/test')
2 files changed, 167 insertions, 92 deletions
diff --git a/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutorTest.kt b/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutorTest.kt index f013e89a1..c472337ac 100644 --- a/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/ComponentConfigSnapshotsExecutorTest.kt @@ -47,9 +47,11 @@ import org.springframework.test.context.TestPropertySource import org.springframework.test.context.junit4.SpringRunner @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [ResourceConfigSnapshotService::class, - BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, - BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class]) +@ContextConfiguration( + classes = [ResourceConfigSnapshotService::class, + BluePrintPropertyConfiguration::class, BluePrintPropertiesService::class, + BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class] +) @TestPropertySource(locations = ["classpath:application-test.properties"]) @ComponentScan(basePackages = ["org.onap.ccsdk.cds.blueprintsprocessor", "org.onap.ccsdk.cds.controllerblueprints"]) @EnableAutoConfiguration @@ -57,10 +59,12 @@ import org.springframework.test.context.junit4.SpringRunner class ComponentConfigSnapshotsExecutorTest { @Autowired - lateinit var cfgSnapshotService : ResourceConfigSnapshotService - lateinit var cfgSnapshotComponent : ComponentConfigSnapshotsExecutor - private var bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("123456-1000", - "./../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts") + lateinit var cfgSnapshotService: ResourceConfigSnapshotService + lateinit var cfgSnapshotComponent: ComponentConfigSnapshotsExecutor + private var bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime( + "123456-1000", + "./../../../../components/model-catalog/blueprint-model/test-blueprint/remote_scripts" + ) private val resourceId = "1" private val resourceType = "ServiceInstance" @@ -75,7 +79,6 @@ class ComponentConfigSnapshotsExecutorTest { props[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_ID] = resourceId.asJsonPrimitive() props[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_TYPE] = resourceType.asJsonPrimitive() - cfgSnapshotComponent.operationInputs = props cfgSnapshotComponent.bluePrintRuntimeService = bluePrintRuntimeService cfgSnapshotComponent.nodeTemplateName = nodeTemplateName @@ -103,17 +106,27 @@ class ComponentConfigSnapshotsExecutorTest { cfgSnapshotComponent.processNB(executionRequest) } catch (e: BluePrintProcessorException) { - kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", - e.message) + kotlin.test.assertEquals( + "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", + e.message + ) return@runBlocking } // then; we should get success and the TEST1 payload in our output properties - assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_STATUS)) - assertEquals(snapshotConfig.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT)) + assertEquals( + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS + ) + ) + assertEquals( + snapshotConfig.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT + ) + ) } } @@ -127,22 +140,32 @@ class ComponentConfigSnapshotsExecutorTest { try { val resId = "121111" val resType = "PNF" - cfgSnapshotService.write(snapshotConfig, resId, resType, ResourceConfigSnapshot.Status.CANDIDATE) + cfgSnapshotService.write(snapshotConfig, resId, resType, ResourceConfigSnapshot.Status.CANDIDATE) prepareRequestProperties(OPERATION_FETCH, resId, resType, ResourceConfigSnapshot.Status.CANDIDATE.name) cfgSnapshotComponent.processNB(executionRequest) } catch (e: BluePrintProcessorException) { - kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", - e.message) + kotlin.test.assertEquals( + "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", + e.message + ) return@runBlocking } // then; we should get success and the TEST payload in our output properties - assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_STATUS)) - assertEquals(snapshotConfig.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT)) + assertEquals( + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS + ) + ) + assertEquals( + snapshotConfig.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT + ) + ) } } @@ -159,20 +182,29 @@ class ComponentConfigSnapshotsExecutorTest { prepareRequestProperties(OPERATION_STORE, resId, resType, snapshotConfig) cfgSnapshotComponent.processNB(executionRequest) - } catch (e: BluePrintProcessorException) { - kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", - e.message) + kotlin.test.assertEquals( + "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", + e.message + ) return@runBlocking } // then; we should get success and the PAYLOAD payload in our output properties - assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_STATUS)) - assertEquals(snapshotConfig.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT)) + assertEquals( + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS + ) + ) + assertEquals( + snapshotConfig.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT + ) + ) } } @@ -182,19 +214,24 @@ class ComponentConfigSnapshotsExecutorTest { runBlocking { // when; asking for unknown resource Id/ resource Type combo; should get an error response try { - prepareRequestProperties(OPERATION_FETCH, "asdasd", "PNF", ResourceConfigSnapshot.Status.RUNNING.name) + prepareRequestProperties(OPERATION_FETCH, "asdasd", "PNF", ResourceConfigSnapshot.Status.RUNNING.name) cfgSnapshotComponent.processNB(executionRequest) - } catch (e: BluePrintProcessorException) { - kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", - e.message) + kotlin.test.assertEquals( + "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", + e.message + ) return@runBlocking } - assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_STATUS)) + assertEquals( + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS + ) + ) } } @@ -204,25 +241,34 @@ class ComponentConfigSnapshotsExecutorTest { runBlocking { // when; asking for unknown operation update; should get an error response try { - prepareRequestProperties("update", "asdasd", "PNF", ResourceConfigSnapshot.Status.RUNNING.name) + prepareRequestProperties("update", "asdasd", "PNF", ResourceConfigSnapshot.Status.RUNNING.name) cfgSnapshotComponent.processNB(executionRequest) - } catch (e: BluePrintProcessorException) { - kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", - e.message) + kotlin.test.assertEquals( + "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", + e.message + ) return@runBlocking } // then; we should get error in our output properties - assertTrue( bluePrintRuntimeService.getBluePrintError().errors.size == 1 ) - assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_ERROR.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_STATUS)) + assertTrue(bluePrintRuntimeService.getBluePrintError().errors.size == 1) + assertEquals( + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_ERROR.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS + ) + ) val msg = "Operation parameter must be fetch, store or diff" - assertEquals(msg.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_MESSAGE)) + assertEquals( + msg.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_MESSAGE + ) + ) } } @@ -234,25 +280,34 @@ class ComponentConfigSnapshotsExecutorTest { try { val resId = "121111" val resType = "PNF" - cfgSnapshotService.write("snapshotConfig", resId, resType, ResourceConfigSnapshot.Status.CANDIDATE) - prepareRequestProperties(OPERATION_DIFF, resId, resType, "YANG") + cfgSnapshotService.write("snapshotConfig", resId, resType, ResourceConfigSnapshot.Status.CANDIDATE) + prepareRequestProperties(OPERATION_DIFF, resId, resType, "YANG") cfgSnapshotComponent.processNB(executionRequest) - } catch (e: BluePrintProcessorException) { - kotlin.test.assertEquals("Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", - e.message) + kotlin.test.assertEquals( + "Can't proceed with the cfg snapshot lookup: provide resource-id and resource-type.", + e.message + ) return@runBlocking } // then; we should get error in our output properties - assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_ERROR.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_STATUS)) + assertEquals( + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_ERROR.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS + ) + ) val message = "Could not compare config snapshots for type YANG" - assertEquals(message.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_MESSAGE)) + assertEquals( + message.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_MESSAGE + ) + ) } } @@ -270,27 +325,37 @@ class ComponentConfigSnapshotsExecutorTest { prepareRequestProperties(OPERATION_DIFF, resId, resType, DIFF_JSON) cfgSnapshotComponent.processNB(executionRequest) - } catch (e: BluePrintProcessorException) { - kotlin.test.assertEquals("Can't proceed with the cfg snapshot diff: provide resource-id and resource-type.", - e.message) + kotlin.test.assertEquals( + "Can't proceed with the cfg snapshot diff: provide resource-id and resource-type.", + e.message + ) return@runBlocking } // then; we should get success - assertTrue( bluePrintRuntimeService.getBluePrintError().errors.size == 0 ) - assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_STATUS)) + assertTrue(bluePrintRuntimeService.getBluePrintError().errors.size == 0) + assertEquals( + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS + ) + ) // then; we should get JSON-patches differences in our response property - val diffJson = "[{\"op\":\"add\",\"path\":\"/system-uptime-information/last-configured-time/new-child-object\",\"value\":{\"property\":\"value\"}}," + - "{\"op\":\"replace\",\"path\":\"/system-uptime-information/system-booted-time/time-length\",\"value\":\"14:52:54\"}," + - "{\"op\":\"replace\",\"path\":\"/system-uptime-information/time-source\",\"value\":\" DNS CLOCK \"}," + - "{\"op\":\"add\",\"path\":\"/system-uptime-information/uptime-information/load-average-10\",\"value\":\"0.05\"}]" - assertEquals(diffJson.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT)) + val diffJson = + "[{\"op\":\"add\",\"path\":\"/system-uptime-information/last-configured-time/new-child-object\",\"value\":{\"property\":\"value\"}}," + + "{\"op\":\"replace\",\"path\":\"/system-uptime-information/system-booted-time/time-length\",\"value\":\"14:52:54\"}," + + "{\"op\":\"replace\",\"path\":\"/system-uptime-information/time-source\",\"value\":\" DNS CLOCK \"}," + + "{\"op\":\"add\",\"path\":\"/system-uptime-information/uptime-information/load-average-10\",\"value\":\"0.05\"}]" + assertEquals( + diffJson.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT + ) + ) } } @@ -309,18 +374,23 @@ class ComponentConfigSnapshotsExecutorTest { prepareRequestProperties(OPERATION_DIFF, resId, resType, DIFF_XML) cfgSnapshotComponent.processNB(executionRequest) - } catch (e: BluePrintProcessorException) { - kotlin.test.assertEquals("Can't proceed with the cfg snapshot diff: provide resource-id and resource-type.", - e.message) + kotlin.test.assertEquals( + "Can't proceed with the cfg snapshot diff: provide resource-id and resource-type.", + e.message + ) return@runBlocking } // then; we should get success - assertTrue( bluePrintRuntimeService.getBluePrintError().errors.size == 0 ) - assertEquals(ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_STATUS)) + assertTrue(bluePrintRuntimeService.getBluePrintError().errors.size == 0) + assertEquals( + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS_SUCCESS.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_STATUS + ) + ) // then; we should get XML-patches differences in our response property val diffXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + @@ -331,18 +401,23 @@ class ComponentConfigSnapshotsExecutorTest { "<replace sel=\"/output[1]/interface-information[1]/traffic-statistics[1]/output-packets[1]/text()[1]\">2828828</replace>" + "<add sel=\"/output[1]/interface-information[1]/physical-interface[1]\"><interface-name>TEGig400-int01</interface-name></add>" + "</diff>" - assertEquals(diffXml.asJsonPrimitive(), - bluePrintRuntimeService.getNodeTemplateAttributeValue(nodeTemplateName, - ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT)) } + assertEquals( + diffXml.asJsonPrimitive(), + bluePrintRuntimeService.getNodeTemplateAttributeValue( + nodeTemplateName, + ComponentConfigSnapshotsExecutor.OUTPUT_SNAPSHOT + ) + ) + } } - private fun preparePayload(filename : String, resId : String, resType : String, status: ResourceConfigSnapshot.Status) { + private fun preparePayload(filename: String, resId: String, resType: String, status: ResourceConfigSnapshot.Status) { runBlocking { cfgSnapshotService.write(JacksonUtils.getClassPathFileContent("payload/requests/$filename"), resId, resType, status) } } - private fun prepareRequestProperties (oper : String, resId : String, resType : String, optional: String = "") { + private fun prepareRequestProperties(oper: String, resId: String, resType: String, optional: String = "") { cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_OPERATION] = oper.asJsonPrimitive() cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_ID] = resId.asJsonPrimitive() cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_TYPE] = resType.asJsonPrimitive() @@ -351,7 +426,7 @@ class ComponentConfigSnapshotsExecutorTest { cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_DIFF_CONTENT_TYPE] = "".asJsonPrimitive() cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_SNAPSHOT] = "".asJsonPrimitive() cfgSnapshotComponent.operationInputs[ComponentConfigSnapshotsExecutor.INPUT_RESOURCE_STATUS] = - ResourceConfigSnapshot.Status.RUNNING.name.asJsonPrimitive() + ResourceConfigSnapshot.Status.RUNNING.name.asJsonPrimitive() when (oper) { OPERATION_DIFF -> diff --git a/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotServiceTest.kt b/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotServiceTest.kt index 18ee8c9dc..f25b6f9c7 100644 --- a/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotServiceTest.kt +++ b/ms/blueprintsprocessor/functions/config-snapshots/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/config/snapshots/db/ResourceConfigSnapshotServiceTest.kt @@ -55,7 +55,7 @@ class ResourceConfigSnapshotServiceTest { every { cfgRepository.findByResourceIdAndResourceTypeAndStatus(any(), any(), any()) } returns null - val res = cfgService.write( configSnapshot, resourceId, resourceType, resourceStatus) + val res = cfgService.write(configSnapshot, resourceId, resourceType, resourceStatus) assertEquals(tr, res) } } @@ -71,7 +71,7 @@ class ResourceConfigSnapshotServiceTest { every { cfgRepository.deleteByResourceIdAndResourceTypeAndStatus(any(), any(), any()) } returns Unit - val res = cfgService.write( configSnapshot, resourceId, resourceType) + val res = cfgService.write(configSnapshot, resourceId, resourceType) verify { cfgRepository.deleteByResourceIdAndResourceTypeAndStatus(eq(resourceId), eq(resourceType), eq(resourceStatus)) } |