aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-21 08:35:36 -0500
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-01-21 08:49:33 -0500
commite4b48721c4a8b5f65add9e2d00025ecd54585e07 (patch)
treea71686030d5016264ab82558d5d4ef8a59e2a77c /ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin
parenta651a74ef5d0be67855b367f1569bdc1521bbedd (diff)
Map proto to pojo. implement blueprint processing
Change-Id: I16b06b4700a42d4a7066eb8c0779677fa28cd94b Issue-ID: CCSDK-951 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin')
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt5
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt55
-rw-r--r--ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt172
3 files changed, 223 insertions, 9 deletions
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt
index a48e699cb..668d3dbf0 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintManagementGRPCHandlerTest.kt
@@ -23,9 +23,9 @@ import org.apache.commons.io.FileUtils
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader
import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementInput
import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementServiceGrpc
-import org.onap.ccsdk.apps.controllerblueprints.management.api.CommonHeader
import org.onap.ccsdk.apps.controllerblueprints.management.api.FileChunk
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
@@ -87,7 +87,8 @@ class BluePrintManagementGRPCHandlerTest {
val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
- val commonHeader = CommonHeader.newBuilder()
+ val commonHeader = CommonHeader
+ .newBuilder()
.setTimestamp("2012-04-23T18:25:43.511Z")
.setOriginatorId("System")
.setRequestId(id)
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt
index 280227d06..01984b21d 100644
--- a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/BluePrintProcessingGRPCHandlerTest.kt
@@ -19,15 +19,20 @@ package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
import com.google.protobuf.util.JsonFormat
+import io.grpc.stub.StreamObserver
import io.grpc.testing.GrpcServerRule
+import org.junit.Assert
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers
+import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
-import org.onap.ccsdk.apps.controllerblueprints.processing.api.CommonHeader
import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput
+import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceOutput
+import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.context.annotation.ComponentScan
@@ -43,6 +48,7 @@ import kotlin.test.BeforeTest
@ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
@TestPropertySource(locations = ["classpath:application-test.properties"])
class BluePrintProcessingGRPCHandlerTest {
+ private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)
@get:Rule
val grpcServerRule = GrpcServerRule().directExecutor()
@@ -50,17 +56,35 @@ class BluePrintProcessingGRPCHandlerTest {
@Autowired
lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler
+ lateinit var requestObs: StreamObserver<ExecutionServiceInput>
+
@BeforeTest
fun init() {
- // Create a server, add service, start, and register for automatic graceful shutdown.
grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler)
+
+ val blockingStub = BluePrintProcessingServiceGrpc.newStub(grpcServerRule.channel)
+
+ requestObs = blockingStub.process(object : StreamObserver<ExecutionServiceOutput> {
+ override fun onNext(executionServiceOuput: ExecutionServiceOutput) {
+ log.debug("onNext {}", executionServiceOuput)
+ if ("1234".equals(executionServiceOuput.commonHeader.requestId)) {
+ Assert.assertEquals("Failed to process request, \'actionIdentifiers.mode\' not specified. Valid value are: \'sync\' or \'async\'.", executionServiceOuput.status.errorMessage)
+ }
+ }
+
+ override fun onError(error: Throwable) {
+ log.debug("Fail to process message", error)
+ Assert.assertEquals("INTERNAL: Could not find blueprint : from database", error.message)
+ }
+
+ override fun onCompleted() {
+ log.info("Done")
+ }
+ })
}
@Test
fun testSelfServiceGRPCHandler() {
-
- val blockingStub = BluePrintProcessingServiceGrpc.newBlockingStub(grpcServerRule.channel)
-
val commonHeader = CommonHeader.newBuilder()
.setTimestamp("2012-04-23T18:25:43.511Z")
.setOriginatorId("System")
@@ -76,8 +100,25 @@ class BluePrintProcessingGRPCHandlerTest {
.setPayload(payloadBuilder.build())
.build()
-// val response = blockingStub.process(input)
-// assertNotNull(response, "Response is null")
+ requestObs.onNext(input)
+
+ val commonHeader2 = CommonHeader.newBuilder()
+ .setTimestamp("2012-04-23T18:25:43.511Z")
+ .setOriginatorId("System")
+ .setRequestId("2345")
+ .setSubRequestId("1234-56").build()
+
+ val actionIdentifier = ActionIdentifiers.newBuilder().setMode("sync").build()
+
+ val input2 = ExecutionServiceInput.newBuilder()
+ .setCommonHeader(commonHeader2)
+ .setActionIdentifiers(actionIdentifier)
+ .setPayload(payloadBuilder.build())
+ .build()
+
+ requestObs.onNext(input2)
+
+ requestObs.onCompleted()
}
} \ No newline at end of file
diff --git a/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt
new file mode 100644
index 000000000..f2048c391
--- /dev/null
+++ b/ms/blueprintsprocessor/modules/inbounds/selfservice-api/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/selfservice/api/utils/BluePrintMappingTests.kt
@@ -0,0 +1,172 @@
+package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.utils
+
+import com.fasterxml.jackson.databind.ObjectMapper
+import com.google.protobuf.ListValue
+import com.google.protobuf.NullValue
+import com.google.protobuf.Struct
+import com.google.protobuf.Value
+import com.google.protobuf.util.JsonFormat
+import org.junit.Assert
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Flags
+import org.onap.ccsdk.apps.controllerblueprints.common.api.ActionIdentifiers
+import org.onap.ccsdk.apps.controllerblueprints.common.api.CommonHeader
+import org.onap.ccsdk.apps.controllerblueprints.common.api.Flag
+import org.springframework.test.context.junit4.SpringRunner
+import java.text.SimpleDateFormat
+
+@RunWith(SpringRunner::class)
+class BluePrintMappingsTest {
+
+ val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
+ val dateString = "2019-01-16T18:25:43.511Z"
+ val dateForTest = formatter.parse(dateString)
+
+ val flag = Flag.newBuilder().setIsForce(false).setTtl(1).build()
+
+ fun createFlag(): Flags {
+ val flag = Flags()
+ flag.isForce = false
+ flag.ttl = 1
+ return flag
+ }
+
+ @Test
+ fun flagToJavaTest() {
+ val flag2 = flag.toJava()
+
+ Assert.assertEquals(flag.isForce, flag2.isForce)
+ Assert.assertEquals(flag.ttl, flag2.ttl)
+ }
+
+ @Test
+ fun flagToProtoTest() {
+ val flag = createFlag()
+ val flag2 = flag.toProto()
+
+ Assert.assertEquals(flag.isForce, flag2.isForce)
+ Assert.assertEquals(flag.ttl, flag2.ttl)
+ }
+
+ fun createStatus(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status {
+ val status = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.Status()
+ status.code = 400
+ status.errorMessage = "Concurrent modification exception"
+ status.eventType = "Update"
+ status.message = "Error uploading data"
+ status.timestamp = dateForTest
+ return status
+ }
+
+ @Test
+ fun statusToProtoTest() {
+ val status = createStatus()
+ val status2 = status.toProto()
+
+ Assert.assertEquals(status.code, status2.code)
+ Assert.assertEquals(status.errorMessage, status2.errorMessage)
+ Assert.assertEquals(status.eventType, status2.eventType)
+ Assert.assertEquals(status.message, status2.message)
+ Assert.assertEquals(status.timestamp.toString(), status2.timestamp)
+ }
+
+ @Test
+ fun commonHeaderToJavaTest() {
+ val flag = Flag.newBuilder().setIsForce(true).setTtl(2).build()
+
+ val commonHeader = CommonHeader.newBuilder().setOriginatorId("Origin").setRequestId("requestID").setSubRequestId("subRequestID").setTimestamp(dateString).setFlag(flag).build()
+ val commonHeader2 = commonHeader.toJava()
+
+ Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId)
+ Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId)
+ Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId)
+ Assert.assertEquals(commonHeader.timestamp, formatter.format(commonHeader2.timestamp))
+ }
+
+ fun createCommonHeader(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader {
+ val commonHeader = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader()
+ commonHeader.flags = createFlag()
+ commonHeader.originatorId = "1234"
+ commonHeader.requestId = "2345"
+ commonHeader.subRequestId = "0123"
+ commonHeader.timestamp = dateForTest
+ return commonHeader
+ }
+
+ @Test
+ fun commonHeaderToProtoTest() {
+ val commonHeader = createCommonHeader()
+ val commonHeader2 = commonHeader.toProto()
+ Assert.assertEquals(commonHeader.originatorId, commonHeader2.originatorId)
+ Assert.assertEquals(commonHeader.requestId, commonHeader2.requestId)
+ Assert.assertEquals(commonHeader.subRequestId, commonHeader2.subRequestId)
+ Assert.assertEquals(commonHeader.timestamp.toString(), commonHeader2.timestamp)
+ }
+
+ @Test
+ fun actionIdentifierToJavaTest() {
+ val actionIdentifiers = ActionIdentifiers.newBuilder().setActionName("Process Action").setBlueprintName("BlueprintName").setBlueprintVersion("3.0").setMode("Execution").build()
+ val actionIdentifiers2 = actionIdentifiers.toJava()
+
+ Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName)
+ Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName)
+ Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion)
+ Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode)
+ }
+
+ fun createActionIdentifier(): org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers {
+ val ac = org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers()
+ ac.mode = "mode"
+ ac.blueprintVersion = "version"
+ ac.blueprintName = "name"
+ ac.actionName = "action"
+ return ac
+ }
+
+ @Test
+ fun actionIdentifierToProtoTest() {
+ val actionIdentifiers = createActionIdentifier()
+ val actionIdentifiers2 = actionIdentifiers.toProto()
+
+ Assert.assertEquals(actionIdentifiers.actionName, actionIdentifiers2.actionName)
+ Assert.assertEquals(actionIdentifiers.blueprintName, actionIdentifiers2.blueprintName)
+ Assert.assertEquals(actionIdentifiers.blueprintVersion, actionIdentifiers2.blueprintVersion)
+ Assert.assertEquals(actionIdentifiers.mode, actionIdentifiers2.mode)
+ }
+
+ @Test
+ fun testStructToJava() {
+ val struct = Struct.newBuilder().putAllFields(createValues()).build()
+ val struct2 = struct.toJava()
+
+ val mapper = ObjectMapper()
+
+ Assert.assertEquals(JsonFormat.printer().print(struct).replace(" ", ""),
+ mapper.writerWithDefaultPrettyPrinter().writeValueAsString(struct2).replace(" ", ""))
+ }
+
+ fun createValues(): Map<String, Value> {
+ val map = mutableMapOf<String, Value>()
+
+ val boolValue = Value.newBuilder().setBoolValue(true).build()
+ val stringValue = Value.newBuilder().setStringValue("string").build()
+ val doubleValue = Value.newBuilder().setNumberValue(Double.MAX_VALUE).build()
+ val jsonValue = Value.newBuilder().setStringValue("{\"bblah\": \"bbblo\"}").build()
+ val listValue = Value.newBuilder().setListValue(ListValue.newBuilder().addValues(boolValue).addValues(boolValue).build()).build()
+ val nullValue = Value.newBuilder().setNullValue(NullValue.NULL_VALUE).build()
+
+ map.put("bool", boolValue)
+ map.put("string", stringValue)
+ map.put("doublbe", doubleValue)
+ map.put("json", jsonValue)
+ map.put("list", listValue)
+ map.put("null", nullValue)
+
+ val structValue = Value.newBuilder().setStructValue(Struct.newBuilder().putAllFields(map).build()).build()
+
+ map.put("struct", structValue)
+
+ return map
+ }
+} \ No newline at end of file