From fb0b3dc943bca0346271e0889ff2e7dbf3c77eeb Mon Sep 17 00:00:00 2001 From: Jozsef Csongvai Date: Tue, 11 Aug 2020 16:17:55 -0400 Subject: Add test-blueprint-kotlin-parent This parent project is intended for inheritence in CBA pom.xml. It provides dependencies for testing and mocking kotlin scripts. By turning a CBA into a maven project which inherits this parent, users will be able to debug and unit test their kotlin scripts. The parent also includes a profile (-Pdeploy-cba) which will enrich and publish the CBA to a running instance of CDS, defined by properties in the CBA pom.xml. This patch also adds a common assembly descriptor for resuse in maven-assembly-plugin where it is used to package CBA into zip. Issue-ID: CCSDK-2642 Signed-off-by: Jozsef Csongvai Change-Id: I160c3c3e982ad4ed46f0704d6dc27dadfb0dfdc8 --- .../test-blueprint-kotlin-parent/pom.xml | 393 +++++++++++++++++++++ 1 file changed, 393 insertions(+) create mode 100644 components/model-catalog/blueprint-model/test-blueprint-kotlin-parent/pom.xml (limited to 'components/model-catalog/blueprint-model/test-blueprint-kotlin-parent') diff --git a/components/model-catalog/blueprint-model/test-blueprint-kotlin-parent/pom.xml b/components/model-catalog/blueprint-model/test-blueprint-kotlin-parent/pom.xml new file mode 100644 index 000000000..1459531ec --- /dev/null +++ b/components/model-catalog/blueprint-model/test-blueprint-kotlin-parent/pom.xml @@ -0,0 +1,393 @@ + + + + + 4.0.0 + + + org.onap.ccsdk.cds.blueprintsprocessor + cba-parent + 1.0.0-SNAPSHOT + + + test-blueprint-kotlin-parent + 1.0.0-SNAPSHOT + pom + + CBA - Test Kotlin scripts + CBA - Test Kotlin scripts + + + + org.onap.ccsdk.cds.blueprintsprocessor + execution-service + + + org.onap.ccsdk.cds.blueprintsprocessor.functions + resource-resolution + + + org.onap.ccsdk.cds.blueprintsprocessor.functions + netconf-executor + + + org.onap.ccsdk.cds.blueprintsprocessor.functions + cli-executor + + + org.onap.ccsdk.cds.blueprintsprocessor.functions + message-prioritizaion + + + org.jetbrains.kotlin + kotlin-stdlib + + + org.jetbrains.kotlin + kotlin-test-junit + test + + + org.jetbrains.kotlinx + kotlinx-coroutines-test + test + + + + junit + junit + 4.12 + test + + + io.mockk + mockk + 1.10.0 + test + + + com.squareup.okhttp3 + okhttp + 3.14.0 + + + + + ${project.basedir}/Scripts/kotlin + ${project.basedir}/Tests/kotlin + + + ${project.basedir}/Environments + + + + + maven-antrun-plugin + + + validate-kotlin + validate + + + + + + + ${format.skipValidate} + + + run + + + + + format-kotlin + process-sources + + + + + + + + ${format.skipExecute} + + + run + + + + + + org.jacoco + jacoco-maven-plugin + + + pre-unit-test + none + + + default-prepare-agent + none + + + post-unit-test + none + + + default-report + none + + + pre-integration-test + none + + + post-integration-test + none + + + default-check + none + + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + default + none + + + integration-tests + none + + + + + org.jetbrains.kotlin + kotlin-maven-plugin + ${kotlin.maven.version} + + + compile + compile + + compile + + + + ${project.basedir}/Scripts/kotlin + + + + + test-compile + test-compile + + test-compile + + + + ${project.basedir}/Tests/kotlin + + + + + + + maven-surefire-plugin + + + default-test + test + + test + + + + + + org.apache.maven.plugins + maven-site-plugin + + + attach-descriptor + none + + + + + maven-checkstyle-plugin + + + check-license + none + + + check-style + none + + + + + maven-assembly-plugin + + + org.onap.ccsdk.cds.blueprintsprocessor + cba-assembly-descriptor + 1.0.0-SNAPSHOT + + + + + make-assembly + package + + single + + + + cba_zip + + + + + + + + + + + deploy-cba + + + + org.codehaus.gmaven + groovy-maven-plugin + + + com.squareup.okhttp3 + okhttp + 3.14.0 + + + commons-io + commons-io + ${commons-io-version} + + + + + deploy-cba + install + + execute + + + + import okhttp3.Credentials + import okhttp3.MediaType + import okhttp3.MultipartBody + import okhttp3.OkHttpClient + import okhttp3.Request + import okhttp3.RequestBody + import org.apache.commons.io.IOUtils + + import java.io.File + + target = "${basedir.absolutePath}/target" + userName = throwIfPropMissing('cds.username') + password = throwIfPropMissing('cds.password') + protocol = properties['cds.protocol'] ?: 'http' + host = properties['cds.host'] ?: 'localhost' + port = properties['cds.port'] ?: '8081' + + def cba = "${project.artifact.artifactId}-${project.artifact.version}-cba.zip" + def enrichedCba = "${project.artifact.artifactId}-${project.artifact.version}-enriched-cba.zip" + def enrichEndpoint = properties['cds.enrich.endpoint'] ?: 'api/v1/blueprint-model/enrich' + def publishEndpoint = properties['cds.publish.endpoint'] ?: 'api/v1/blueprint-model/publish' + + def throwIfPropMissing(prop) { + value = properties[prop] + if (!value || "".equals(value)) { + throw new RuntimeException("Property missing: $prop") + } + return value + } + + def buildRequest(endpoint, fileName) { + body = new MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart("file", + fileName, + RequestBody.create(MediaType.parse('application/zip'), new File(target, fileName))) + .build() + + return new Request.Builder() + .url("$protocol://$host:$port/$endpoint") + .addHeader('Authorization', Credentials.basic(userName, password)) + .post(body) + .build() + } + + def logAndThrow(msg) { + if(response) { + log.error(response.body().string()) + } + throw new RuntimeException(msg) + } + + response = null + try { + def client = new OkHttpClient() + + response = client.newCall(buildRequest(enrichEndpoint, cba)).execute() + if (!response || !response.isSuccessful()) { + logAndThrow("Failed to enrich CBA") + } + + IOUtils.copy( + response.body().byteStream(), + new FileOutputStream(new File(target, enrichedCba)) + ) + log.info("Created enriched cba: $enrichedCba") + + response = client.newCall(buildRequest(publishEndpoint, enrichedCba)).execute() + if (!response || !response.isSuccessful()) { + logAndThrow("Failed to publish CBA") + } + + log.info("CBA Deployed") + log.info(response.body().string()) + } finally { + if (response) { + response.close() + } + } + + + + + + + + + + -- cgit 1.2.3-korg