From ba75d2fad2b0111a510f4ee4cc87e658fb32ac4b Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Tue, 31 Dec 2019 10:53:59 -0500 Subject: Flexible DSL Types and Templates definition. Easy search definitions Types and Templates inside ServiceTemplate DSL builder. Unit test modifications to support this change. Issue-ID: CCSDK-1054 Signed-off-by: Brinda Santh Change-Id: Ie944ff5f75f80c852555306e1a4e0fa7f5b803d7 --- .../db/DatabasePropertiesDSL.kt | 7 ++++++ .../db/DatabasePropertiesDSLTest.kt | 25 +++++++++++++++------- 2 files changed, 24 insertions(+), 8 deletions(-) (limited to 'ms/blueprintsprocessor/modules/commons/db-lib') diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt index 2bf56f482..34dd0a417 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSL.kt @@ -24,10 +24,17 @@ import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive import org.onap.ccsdk.cds.controllerblueprints.core.data.RelationshipType import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertiesAssignmentBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.RelationshipTemplateBuilder +import org.onap.ccsdk.cds.controllerblueprints.core.dsl.ServiceTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.TopologyTemplateBuilder import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipType /** Relationships Types DSL for Database Producer */ +fun ServiceTemplateBuilder.relationshipTypeConnectsToDb() { + val relationshipType = BluePrintTypes.relationshipTypeConnectsToDb() + if (this.relationshipTypes == null) this.relationshipTypes = hashMapOf() + this.relationshipTypes!![relationshipType.id!!] = relationshipType +} + fun BluePrintTypes.relationshipTypeConnectsToDb(): RelationshipType { return relationshipType( id = BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB, diff --git a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt index b0c7d8b3c..dd84e5b02 100644 --- a/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt +++ b/ms/blueprintsprocessor/modules/commons/db-lib/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/db/DatabasePropertiesDSLTest.kt @@ -17,7 +17,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.db import org.junit.Test -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.cds.controllerblueprints.core.dsl.relationshipTypeConnectsTo import org.onap.ccsdk.cds.controllerblueprints.core.dsl.serviceTemplate import kotlin.test.assertEquals @@ -52,19 +52,28 @@ class DatabasePropertiesDSLTest { } } } - relationshipTypes( - arrayListOf( - BluePrintTypes.relationshipTypeConnectsToDb(), - BluePrintTypes.relationshipTypeConnectsTo() - ) - ) + relationshipTypeConnectsToDb() + relationshipTypeConnectsTo() } + + // println(serviceTemplate.asJsonString(true)) assertNotNull(serviceTemplate, "failed to create service template") val relationshipTemplates = serviceTemplate.topologyTemplate?.relationshipTemplates assertNotNull(relationshipTemplates, "failed to get relationship templates") assertEquals(2, relationshipTemplates.size, "relationshipTemplates doesn't match") assertNotNull(relationshipTemplates["sample-maria-db"], "failed to get sample-maria-db") assertNotNull(relationshipTemplates["sample-mysql-db"], "failed to get sample-mysql-db") - // println(serviceTemplate.asJsonString(true)) + + val relationshipTypes = serviceTemplate.relationshipTypes + assertNotNull(relationshipTypes, "failed to get relationship types") + assertEquals(2, relationshipTypes.size, "relationshipTypes doesn't match") + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO}" + ) + assertNotNull( + relationshipTypes[BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB], + "failed to get ${BluePrintConstants.MODEL_TYPE_RELATIONSHIPS_CONNECTS_TO_DB}" + ) } } -- cgit 1.2.3-korg