Controller Design Studio: Blueprint Manager
authorSingal, Kapil (ks220y) <ks220y@att.com>
Thu, 24 Jan 2019 20:15:56 +0000 (15:15 -0500)
committerSingal, Kapil (ks220y) <ks220y@att.com>
Thu, 24 Jan 2019 20:15:56 +0000 (15:15 -0500)
Blueprint Manager JUnit Test Case Enhacements

Change-Id: Icb59df8435585ac6b9725fbd6e9e74d93ce829ff
Issue-ID: CCSDK-1005
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandler.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt
ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt

index 2cd7a81..b80f990 100644 (file)
@@ -79,15 +79,16 @@ class BluePrintManagementGRPCHandler(private val bluePrintCoreConfiguration: Blu
     }
 
     private fun saveToDisk(request: BluePrintManagementInput, blueprintDir: File) {
-        log.debug("request(${request.commonHeader.requestId}): Writing CBA File under :${blueprintDir.absolutePath}")
+        log.info("request(${request.commonHeader.requestId}): Writing CBA File under :${blueprintDir.absolutePath}")
         if (blueprintDir.exists()) {
-            log.debug("request(${request.commonHeader.requestId}): Re-creating blueprint directory(${blueprintDir.absolutePath})")
+            log.info("request(${request.commonHeader.requestId}): Re-creating blueprint directory(${blueprintDir.absolutePath})")
             FileUtils.deleteDirectory(blueprintDir.parentFile)
         }
         FileUtils.forceMkdir(blueprintDir.parentFile)
         blueprintDir.writeBytes(request.fileChunk.chunk.toByteArray()).apply {
-            log.debug("request(${request.commonHeader.requestId}): CBA file(${blueprintDir.absolutePath} written successfully")
+            log.info("request(${request.commonHeader.requestId}): CBA file(${blueprintDir.absolutePath} written successfully")
         }
+
     }
 
     private fun successStatus(message: String, header: CommonHeader): BluePrintManagementOutput =
index 668d3db..4da3b74 100644 (file)
@@ -59,16 +59,21 @@ class BluePrintManagementGRPCHandlerTest {
         grpcServerRule.serviceRegistry.addService(bluePrintManagementGRPCHandler)
     }
 
-    @AfterTest
+    //@AfterTest
     fun cleanDir() {
+        //TODO It's giving fluctuating results, need to look for another way to cleanup
+        // works sometimes otherwise results IO Exception
+        // Most probably bufferReader stream is not getting closed when cleanDir is getting invoked
         FileUtils.deleteDirectory(File("./target/blueprints"))
     }
 
     @Test
     fun `test upload blueprint`() {
         val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel)
-        val id = "123"
-        val output = blockingStub.uploadBlueprint(createInputRequest(id))
+        val id = "123_upload"
+        val req = createInputRequest(id)
+        val output = blockingStub.uploadBlueprint(req)
+
         assertEquals(200, output.status.code)
         assertTrue(output.status.message.contains("Successfully uploaded blueprint sample:1.0.0 with id("))
         assertEquals(id, output.commonHeader.requestId)
@@ -77,10 +82,16 @@ class BluePrintManagementGRPCHandlerTest {
     @Test
     fun `test delete blueprint`() {
         val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel)
-        val id = "123"
+        val id = "123_delete"
         val req = createInputRequest(id)
-        blockingStub.uploadBlueprint(req)
-        blockingStub.removeBlueprint(req)
+
+        var output = blockingStub.uploadBlueprint(req)
+        assertEquals(200, output.status.code)
+        assertTrue(output.status.message.contains("Successfully uploaded blueprint sample:1.0.0 with id("))
+        assertEquals(id, output.commonHeader.requestId)
+
+        output = blockingStub.removeBlueprint(req)
+        assertEquals(200, output.status.code)
     }
 
     private fun createInputRequest(id: String): BluePrintManagementInput {
@@ -104,4 +115,4 @@ class BluePrintManagementGRPCHandlerTest {
                 .setFileChunk(fileChunk)
                 .build()
     }
-}
\ No newline at end of file
+}
index f2048c3..2e4ba27 100644 (file)
@@ -142,8 +142,8 @@ class BluePrintMappingsTest {
 
         val mapper = ObjectMapper()
 
-        Assert.assertEquals(JsonFormat.printer().print(struct).replace(" ", ""),
-                mapper.writerWithDefaultPrettyPrinter().writeValueAsString(struct2).replace(" ", ""))
+        Assert.assertEquals(JsonFormat.printer().print(struct).replace(" ", "").replace("\r",""),
+                mapper.writerWithDefaultPrettyPrinter().writeValueAsString(struct2).replace(" ", "").replace("\r",""))
     }
 
     fun createValues(): Map<String, Value> {