From 35481027b3fdf251a3b520ab5b1ae89c7d2d0e34 Mon Sep 17 00:00:00 2001 From: Kavitha P Date: Wed, 25 Aug 2021 16:12:18 +0530 Subject: CCSDK-3434 CBA workflow status store Change-Id: Iaeac6fa534c569bbc152e6c8a78c2dd23b6c4b1a Signed-off-by: Kavitha P Issue-ID: CCSDK-3434 --- .../modules/inbounds/workflow-api/pom.xml | 56 +++++ .../workflow/api/ErrorHandling.kt | 35 +++ .../workflow/api/WorkflowController.kt | 109 +++++++++ .../workflow/api/WorkflowExceptionHandler.kt | 29 +++ .../workflow/api/ErrorCatalogTestConfiguration.kt | 28 +++ .../workflow/api/TestDatabaseConfiguration.kt | 62 +++++ .../workflow/api/WorkflowControllerTest.kt | 268 +++++++++++++++++++++ .../src/test/resources/application-test.properties | 39 +++ 8 files changed, 626 insertions(+) create mode 100644 ms/blueprintsprocessor/modules/inbounds/workflow-api/pom.xml create mode 100644 ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/ErrorHandling.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowController.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowExceptionHandler.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/ErrorCatalogTestConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/TestDatabaseConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowControllerTest.kt create mode 100644 ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/resources/application-test.properties (limited to 'ms/blueprintsprocessor/modules/inbounds/workflow-api') diff --git a/ms/blueprintsprocessor/modules/inbounds/workflow-api/pom.xml b/ms/blueprintsprocessor/modules/inbounds/workflow-api/pom.xml new file mode 100644 index 000000000..7e5ebecb8 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/workflow-api/pom.xml @@ -0,0 +1,56 @@ + + + + + 4.0.0 + + + org.onap.ccsdk.cds.blueprintsprocessor + modules-inbounds + 1.2.0-SNAPSHOT + + + org.onap.ccsdk.cds.blueprintsprocessor.modules + workflow-api + jar + + MS Blueprints Processor Modules - Inbounds - Workflow API + + + + org.springframework.security + spring-security-core + + + org.onap.ccsdk.cds.blueprintsprocessor.modules + blueprint-core + + + org.onap.ccsdk.cds.error.catalog + error-catalog-services + + + org.onap.ccsdk.cds.blueprintsprocessor.functions + blueprint-audit-status + ${project.version} + + + org.onap.ccsdk.cds.blueprintsprocessor.modules + db-lib + + + diff --git a/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/ErrorHandling.kt b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/ErrorHandling.kt new file mode 100644 index 000000000..5e4289e7b --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/ErrorHandling.kt @@ -0,0 +1,35 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.workflow.api + +object WorkflowApiDomains { + + // Workflow Api Domains Constants + const val WORKFLOW_API = "org.onap.ccsdk.cds.blueprintsprocessor.workflow.api" +} + +object WorkflowApiHttpErrorCodes { + init { + // Register HttpErrorCodes + } +} + +object WorkflowGrpcErrorCodes { + init { + // Register GrpcErrorCodes + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowController.kt b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowController.kt new file mode 100644 index 000000000..e131bf378 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowController.kt @@ -0,0 +1,109 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.workflow.api + +import com.fasterxml.jackson.databind.JsonNode +import io.swagger.annotations.Api +import io.swagger.annotations.ApiOperation +import io.swagger.annotations.ApiParam +import kotlinx.coroutines.runBlocking +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintWorkflowAuditStatus +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.StoreAuditService +import org.onap.ccsdk.cds.controllerblueprints.core.httpProcessorException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.error.catalog.core.ErrorCatalogCodes +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.http.MediaType +import org.springframework.http.ResponseEntity +import org.springframework.security.access.prepost.PreAuthorize +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.ResponseBody +import org.springframework.web.bind.annotation.RestController + +/** + * Rest API which handles retrieving the workflow store records + */ +@RestController +@RequestMapping("/api/v1/workflow") +@Api( + value = "/api/v1/workflow", + description = "Interaction with blueprint workflow status resources" +) +class WorkflowController { + private val log = + LoggerFactory.getLogger(WorkflowController::class.toString()) + + @Autowired + lateinit var databaseStoreAuditService: StoreAuditService + + private val JSON_MIME_TYPE = "application/json" + + /** + * workflow healthcheck api + */ + @RequestMapping( + path = ["/health-check"], + method = [RequestMethod.GET], + produces = [MediaType.APPLICATION_JSON_VALUE] + ) + @ResponseBody + @ApiOperation(value = "Health Check", hidden = true) + fun workflowControllerHealthCheck(): JsonNode = runBlocking { + JacksonUtils.getJsonNode("Success") + } + + /** + * API to retreive records based on request and subrequest ID * + */ + @GetMapping( + "/audit-status/{requestId}/{subRequestId}", + produces = [MediaType.APPLICATION_JSON_VALUE] + ) + @ApiOperation( + value = "Get all workflow status records using request and Subrequest", + notes = "Retrieve all stored workflow audit records based on " + + "requestId and SubrequestId", + response = BlueprintWorkflowAuditStatus::class, + responseContainer = "List", + produces = MediaType.APPLICATION_JSON_VALUE + ) + @ResponseBody + @PreAuthorize("hasRole('USER')") + suspend fun getWorkFlowByRequestAndSubRequest( + @ApiParam(value = "request ID", required = true) + @PathVariable(value = "requestId") requestId: String, + @ApiParam(value = "sub request ID", required = true) + @PathVariable(value = "subRequestId") subRequestId: String + ): ResponseEntity> = runBlocking { + var requestIdResults: List + if (requestId.isNotEmpty()) { + requestIdResults = databaseStoreAuditService + .getWorkflowStatusByRequestIdAndSubRequestId(requestId, subRequestId) + } else { + throw httpProcessorException( + ErrorCatalogCodes.REQUEST_NOT_FOUND, WorkflowApiDomains.WORKFLOW_API, + "Missing param." + ) + } + val expectedMediaType: MediaType = MediaType.valueOf(JSON_MIME_TYPE) + ResponseEntity.ok().contentType(expectedMediaType).body(requestIdResults) + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowExceptionHandler.kt b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowExceptionHandler.kt new file mode 100644 index 000000000..18dfe085b --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowExceptionHandler.kt @@ -0,0 +1,29 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.cds.blueprintsprocessor.workflow.api + +import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogExceptionHandler +import org.onap.ccsdk.cds.error.catalog.services.ErrorCatalogService +import org.springframework.web.bind.annotation.RestControllerAdvice + +/** + * Handle exceptions in Workflow API and provide relevant HTTP status codes and + * messages + * + */ +@RestControllerAdvice("org.onap.ccsdk.cds.blueprintsprocessor.workflow.api") +open class WorkflowExceptionHandler(private val errorCatalogService: ErrorCatalogService) : + ErrorCatalogExceptionHandler(errorCatalogService) diff --git a/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/ErrorCatalogTestConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/ErrorCatalogTestConfiguration.kt new file mode 100644 index 000000000..a05f569c0 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/ErrorCatalogTestConfiguration.kt @@ -0,0 +1,28 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.workflow.api + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration + +@Configuration +@ComponentScan( + basePackages = ["org.onap.ccsdk.cds.error.catalog"] +) +@EnableAutoConfiguration +open class ErrorCatalogTestConfiguration diff --git a/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/TestDatabaseConfiguration.kt b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/TestDatabaseConfiguration.kt new file mode 100644 index 000000000..7ca90e9ec --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/TestDatabaseConfiguration.kt @@ -0,0 +1,62 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.workflow.api + +import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibConfiguration +import org.onap.ccsdk.cds.blueprintsprocessor.db.PrimaryDataSourceProperties +import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDatabaseConfiguration +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Import +import org.springframework.data.jpa.repository.config.EnableJpaAuditing +import org.springframework.data.jpa.repository.config.EnableJpaRepositories +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean +import org.springframework.transaction.PlatformTransactionManager +import javax.sql.DataSource + +@Configuration +@Import(BluePrintDBLibConfiguration::class) +@EnableJpaRepositories( + basePackages = [ + "org.onap.ccsdk.cds.blueprintsprocessor.db.primary", + "org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit" + ], + entityManagerFactoryRef = "primaryEntityManager", + transactionManagerRef = "primaryTransactionManager" +) +@EnableJpaAuditing +open class TestDatabaseConfiguration(primaryDataSourceProperties: PrimaryDataSourceProperties) : + PrimaryDatabaseConfiguration(primaryDataSourceProperties) { + + @Bean("primaryEntityManager") + open fun primaryEntityManager(): LocalContainerEntityManagerFactoryBean { + return primaryEntityManager( + "org.onap.ccsdk.cds.blueprintsprocessor.db.primary", + "org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db" + ) + } + + @Bean("primaryDataSource") + override fun primaryDataSource(): DataSource { + return super.primaryDataSource() + } + + @Bean("primaryTransactionManager") + override fun primaryTransactionManager(): PlatformTransactionManager { + return super.primaryTransactionManager() + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowControllerTest.kt b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowControllerTest.kt new file mode 100644 index 000000000..bf6960f02 --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/workflow/api/WorkflowControllerTest.kt @@ -0,0 +1,268 @@ +/* + * Copyright © 2021 Aarna Networks, Inc. + * All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.workflow.api + +import kotlinx.coroutines.runBlocking +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.DatabaseStoreAuditService +import org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit.db.BlueprintWorkflowAuditStatus +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.test.web.reactive.server.WebTestClient +import java.text.SimpleDateFormat +import java.util.List + +@RunWith(SpringRunner::class) +@WebFluxTest +@ContextConfiguration( + classes = [ + TestDatabaseConfiguration::class, ErrorCatalogTestConfiguration::class, + WorkflowController::class, DatabaseStoreAuditService::class + ] +) +@ComponentScan( + basePackages = [ + "org.onap.ccsdk.cds.controllerblueprints.core.service", + "org.onap.ccsdk.cds.blueprintsprocessor.functions.workflow.audit", + "org.onap.ccsdk.cds.blueprintsprocessor.workflow.api" + ] +) +@TestPropertySource(locations = ["classpath:application-test.properties"]) +class WorkflowControllerTest { + + @Autowired + lateinit var databaseStoreAuditService: DatabaseStoreAuditService + @Autowired + lateinit var testWebClient: WebTestClient + + @Test + fun testWorkflowControllerHealthCheck() { + runBlocking { + testWebClient.get().uri("/api/v1/workflow/health-check") + .exchange() + .expectStatus().isOk + .expectBody() + .equals("Success") + } + } + + @Test + fun testGetWorkFlowByRequestAndSubRequest() { + + val wfAudit1 = createWorkflowAuditStatusRecord(1000) + val wfAudit2 = createWorkflowAuditStatusRecord(1001) + runBlocking { + + storeToDB(wfAudit1) + storeToDB(wfAudit2) + val testRequestId: String = "ab543-3asd4" + val testSubRequestId: String = "81c9-4910" + testWebClient + .get() + .uri("/api/v1/workflow/audit-status/$testRequestId/$testSubRequestId") + .exchange() + .expectStatus().isOk + .expectBody() + .consumeWith { + val json = String(it.responseBody!!) + val typeFactory = JacksonUtils.objectMapper.typeFactory + val list: List = JacksonUtils.objectMapper.readValue( + json, + typeFactory.constructCollectionType(List::class.java, BlueprintWorkflowAuditStatus::class.java) + ) + Assert.assertEquals(2, list.size) + assertEqual(list[0]) + assertEqual(list[1]) + } + } + } + + @Test + fun testEmptyRequestAndSubRequest() { + + val wfAudit1 = createWorkflowAuditStatusRecordSetTwo(1002) + val wfAudit2 = createWorkflowAuditStatusRecordSetTwo(1003) + runBlocking { + + storeToDB(wfAudit1) + storeToDB(wfAudit2) + val testRequestId: String = "" + val testSubRequestId: String = "" + testWebClient + .get() + .uri("/api/v1/workflow/audit-status/$testRequestId/$testSubRequestId") + .exchange() + .expectStatus().is4xxClientError + .expectBody() + } + } + + @Test + @Throws(BluePrintException::class) + fun testErrorRequestAndSubRequest() { + + val wfAudit1 = createWorkflowAuditStatusRecordSetTwo(1002) + val wfAudit2 = createWorkflowAuditStatusRecordSetTwo(1003) + runBlocking { + + storeToDB(wfAudit1) + storeToDB(wfAudit2) + val testRequestId: String = "" + val testSubRequestId: String = "" + testWebClient + .get() + .uri("/api/v1/workflow/audit-status/$testRequestId/$testSubRequestId") + .exchange() + .expectStatus().is4xxClientError + .expectBody() + .consumeWith { + Assert.assertTrue( + "Cause: request Id and requesy sub Id is empty. \n " + + "Action : Please verify your request.", + it.status.is4xxClientError + ) + } + } + } + + private fun assertEqual(blueprintWorkflowAuditStatus: BlueprintWorkflowAuditStatus) { + Assert.assertEquals(blueprintWorkflowAuditStatus.status, "In progress") + Assert.assertEquals(blueprintWorkflowAuditStatus.requestId, "ab543-3asd4") + Assert.assertEquals(blueprintWorkflowAuditStatus.subRequestId, "81c9-4910") + Assert.assertEquals(blueprintWorkflowAuditStatus.blueprintName, "multi-steps") + Assert.assertEquals(blueprintWorkflowAuditStatus.blueprintVersion, "1.0.0") + Assert.assertEquals(blueprintWorkflowAuditStatus.requestMode, "sync") + Assert.assertEquals(blueprintWorkflowAuditStatus.workflowName, "multi-steps-workflow") + Assert.assertEquals(blueprintWorkflowAuditStatus.originatorId, "SDNC_DG") + } + + private fun createWorkflowAuditStatusRecord( + id: Long + ): BlueprintWorkflowAuditStatus { + + var blueprintWorkflowAuditStatus: BlueprintWorkflowAuditStatus = + BlueprintWorkflowAuditStatus() + blueprintWorkflowAuditStatus.id = id + blueprintWorkflowAuditStatus.originatorId = "SDNC_DG" + blueprintWorkflowAuditStatus.requestMode = "sync" + blueprintWorkflowAuditStatus.requestId = "ab543-3asd4" + blueprintWorkflowAuditStatus.subRequestId = "81c9-4910" + blueprintWorkflowAuditStatus.status = "In progress" + blueprintWorkflowAuditStatus.blueprintName = "multi-steps" + blueprintWorkflowAuditStatus.blueprintVersion = "1.0.0" + blueprintWorkflowAuditStatus.workflowName = "multi-steps-workflow" + blueprintWorkflowAuditStatus.updatedBy = "CBA" + blueprintWorkflowAuditStatus.requestMode = "sync" + blueprintWorkflowAuditStatus.workflowTaskContent = "{\n" + + " \"multi-steps-workflow-request\": {\n" + + " \"multi-steps-workflow-properties\": {\n" + + " \"prop1\": \"testing\",\n" + + " \"prop2\": \"testing description\",\n" + + " \"prop3\": \"user name \",\n" + + " \"prop4\" : \"test project\"\n" + + " }\n" + + " }\n" + + " }" + blueprintWorkflowAuditStatus.workflowResponseContent = " " + return blueprintWorkflowAuditStatus + } + + private fun createWorkflowAuditStatusRecordSetTwo( + id: Long + ): BlueprintWorkflowAuditStatus { + + var blueprintWorkflowAuditStatus: BlueprintWorkflowAuditStatus = + BlueprintWorkflowAuditStatus() + blueprintWorkflowAuditStatus.id = id + blueprintWorkflowAuditStatus.originatorId = "SDNC_DG" + blueprintWorkflowAuditStatus.requestMode = "sync" + blueprintWorkflowAuditStatus.requestId = "ab543-3asd5" + blueprintWorkflowAuditStatus.subRequestId = "81c9-4911" + blueprintWorkflowAuditStatus.status = "In progress" + blueprintWorkflowAuditStatus.blueprintName = "multi-steps" + blueprintWorkflowAuditStatus.blueprintVersion = "1.0.0" + blueprintWorkflowAuditStatus.workflowName = "multi-steps-workflow" + blueprintWorkflowAuditStatus.updatedBy = "CBA" + blueprintWorkflowAuditStatus.requestMode = "sync" + blueprintWorkflowAuditStatus.workflowTaskContent = "{\n" + + " \"multi-steps-workflow-request\": {\n" + + " \"multi-steps-workflow-properties\": {\n" + + " \"prop1\": \"testing\",\n" + + " \"prop2\": \"testing description\",\n" + + " \"prop3\": \"user name \",\n" + + " \"prop4\" : \"test project\"\n" + + " }\n" + + " }\n" + + " }" + blueprintWorkflowAuditStatus.workflowResponseContent = " " + return blueprintWorkflowAuditStatus + } + + private suspend fun store( + id: Long + ) { + val formatter = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'") + val dateString = "2021-08-08T18:25:43.511Z" + val dateForTest = formatter.parse(dateString) + databaseStoreAuditService.write( + id, "SDNC_DG", "ab543-3asd4", + "81c9-4910", + "multi-steps-workflow", "multi-steps", "1.0.0", + "{\n" + + " \"multi-steps-workflow-request\": {\n" + + " \"multi-steps-workflow-properties\": {\n" + + " \"prop1\": \"testing\",\n" + + " \"prop2\": \"testing description\",\n" + + " \"prop3\": \"user name \",\n" + + " \"prop4\" : \"test project\"\n" + + " }\n" + + " }\n" + + " }", + "In progress", dateForTest, dateForTest, dateForTest, "CBA", "sync", " " + ) + } + + private suspend fun storeToDB( + blueprintWorkflowAuditStatus: BlueprintWorkflowAuditStatus + ) { + databaseStoreAuditService.write( + blueprintWorkflowAuditStatus.id, + blueprintWorkflowAuditStatus.originatorId, + blueprintWorkflowAuditStatus.requestId, + blueprintWorkflowAuditStatus.subRequestId, + blueprintWorkflowAuditStatus.workflowName, + blueprintWorkflowAuditStatus.blueprintName, + blueprintWorkflowAuditStatus.blueprintVersion, + blueprintWorkflowAuditStatus.workflowTaskContent, + blueprintWorkflowAuditStatus.status, + blueprintWorkflowAuditStatus.startDate, + blueprintWorkflowAuditStatus.endDate, + blueprintWorkflowAuditStatus.updatedDate, + blueprintWorkflowAuditStatus.updatedBy, + blueprintWorkflowAuditStatus.requestMode, + blueprintWorkflowAuditStatus.workflowResponseContent + ) + } +} diff --git a/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/resources/application-test.properties b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/resources/application-test.properties new file mode 100644 index 000000000..b970c53ef --- /dev/null +++ b/ms/blueprintsprocessor/modules/inbounds/workflow-api/src/test/resources/application-test.properties @@ -0,0 +1,39 @@ +# +# Copyright © 2021 Aarna Networks, Inc. +# All rights reserved. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +blueprintsprocessor.db.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 +blueprintsprocessor.db.username=sa +blueprintsprocessor.db.password= +blueprintsprocessor.db.driverClassName=org.h2.Driver +blueprintsprocessor.db.hibernateHbm2ddlAuto=create-drop +blueprintsprocessor.db.hibernateDDLAuto=update +blueprintsprocessor.db.hibernateNamingStrategy=org.hibernate.cfg.ImprovedNamingStrategy +blueprintsprocessor.db.hibernateDialect=org.hibernate.dialect.H2Dialect +# Controller Blueprints Core Configuration +blueprintsprocessor.blueprintDeployPath=./target/blueprints/deploy +blueprintsprocessor.blueprintWorkingPath=./target/blueprints/work +blueprintsprocessor.blueprintArchivePath=./target/blueprints/archive + +# Error Managements +error.catalog.applicationId=cds +error.catalog.type=properties +error.catalog.errorDefinitionDir=./../../../application/src/test/resources/ + +# Python executor +blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints +blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints + +#Workflow Audit store enable +blueprintsprocessor.workflow.self-service-api.audit.storeEnable=true -- cgit 1.2.3-korg