From c90edac236dffb7c495e266dd04991de7e8f04b7 Mon Sep 17 00:00:00 2001 From: Alexis de Talhouët Date: Mon, 25 Mar 2019 13:04:18 -0400 Subject: Migrate ccsdk/apps to ccsdk/cds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue-ID: CCSDK-1177 Issue-ID: CCSDK-1178 Change-Id: I0c02702fbec52211ca367abbba72aebecee8cbaa Signed-off-by: Alexis de Talhouët --- .../apps/controllerblueprints/DatabaseConfig.java | 61 ------- .../apps/controllerblueprints/TestApplication.java | 34 ---- .../service/ModelTypeServiceTest.java | 127 -------------- .../service/common/SchemaGeneratorServiceTest.java | 50 ------ .../repository/ModelTypeReactRepositoryTest.java | 110 ------------ .../ResourceDictionaryReactRepositoryTest.java | 103 ----------- .../cds/controllerblueprints/DatabaseConfig.java | 61 +++++++ .../cds/controllerblueprints/TestApplication.java | 34 ++++ .../service/ModelTypeServiceTest.java | 127 ++++++++++++++ .../service/common/SchemaGeneratorServiceTest.java | 50 ++++++ .../repository/ModelTypeReactRepositoryTest.java | 110 ++++++++++++ .../ResourceDictionaryReactRepositoryTest.java | 103 +++++++++++ .../controller/BlueprintModelControllerTest.kt | 193 --------------------- .../service/controller/ModelTypeControllerTest.kt | 120 ------------- .../controller/ResourceDictionaryControllerTest.kt | 43 ----- .../service/controller/mock/MockFilePart.kt | 53 ------ .../enhancer/BluePrintEnhancerServiceImplTest.kt | 111 ------------ .../service/utils/BluePrintEnhancerUtilsTest.kt | 66 ------- .../service/validator/ModelTypeValidatorTest.kt | 40 ----- .../controller/BlueprintModelControllerTest.kt | 193 +++++++++++++++++++++ .../service/controller/ModelTypeControllerTest.kt | 120 +++++++++++++ .../controller/ResourceDictionaryControllerTest.kt | 43 +++++ .../service/controller/mock/MockFilePart.kt | 53 ++++++ .../enhancer/BluePrintEnhancerServiceImplTest.kt | 111 ++++++++++++ .../service/utils/BluePrintEnhancerUtilsTest.kt | 66 +++++++ .../service/validator/ModelTypeValidatorTest.kt | 40 +++++ .../modules/service/src/test/resources/logback.xml | 2 +- 27 files changed, 1112 insertions(+), 1112 deletions(-) delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/DatabaseConfig.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/TestApplication.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SchemaGeneratorServiceTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelControllerTest.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeControllerTest.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt delete mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelControllerTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeControllerTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/mock/MockFilePart.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidatorTest.kt (limited to 'ms/controllerblueprints/modules/service/src/test') diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java deleted file mode 100644 index db35fe661..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.apps.controllerblueprints; - -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -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.orm.jpa.vendor.HibernateJpaVendorAdapter; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.sql.DataSource; - -/** - * DatabaseConfig.java Purpose: Provide Configuration Generator DatabaseConfig Information - * - * @author Brinda Santh - * @version 1.0 - */ -@Configuration -@EntityScan("org.onap.ccsdk.apps.controllerblueprints.service.domain") -@EnableTransactionManagement -@EnableJpaRepositories("org.onap.ccsdk.apps.controllerblueprints.service.repository") -@EnableJpaAuditing -public class DatabaseConfig { - /** - * This is a entityManagerFactory method - * - * @param dataSource - * @return LocalContainerEntityManagerFactoryBean - */ - - @Bean - public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { - HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); - vendorAdapter.setGenerateDdl(true); - vendorAdapter.setShowSql(false); - LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); - factory.setJpaVendorAdapter(vendorAdapter); - factory.setPackagesToScan("org.onap.ccsdk.apps.controllerblueprints.service.domain"); - factory.setDataSource(dataSource); - return factory; - } - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java deleted file mode 100644 index 537429f0b..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.apps.controllerblueprints; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; - - -@SpringBootApplication -@ComponentScan(basePackages = {"org.onap.ccsdk.apps.controllerblueprints"}) -@EnableAutoConfiguration -public class TestApplication { - - public static void main(String[] args) { - SpringApplication.run(TestApplication.class, args); - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java deleted file mode 100644 index a94df6aec..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright © 2018 IBM. - * - * 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.apps.controllerblueprints.service; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.onap.ccsdk.apps.controllerblueprints.service.handler.ModelTypeHandler; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.annotation.Commit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.transaction.annotation.Propagation; -import org.springframework.transaction.annotation.Transactional; - -import java.util.List; - -@RunWith(SpringRunner.class) -@DataJpaTest -@Transactional(propagation = Propagation.NOT_SUPPORTED) -@ContextConfiguration(classes = {TestApplication.class}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ModelTypeServiceTest { - private static EELFLogger log = EELFManager.getInstance().getLogger(ModelTypeServiceTest.class); - @Autowired - private ModelTypeHandler modelTypeHandler; - - String modelName = "test-datatype"; - - @Test - @Commit - public void test01SaveModelType() throws Exception { - log.info("**************** test01SaveModelType ********************"); - - String content = JacksonUtils.Companion.getClassPathFileContent("model_type/data_type/datatype-property.json"); - ModelType modelType = new ModelType(); - modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); - modelType.setDescription("Definition for Sample Datatype "); - modelType.setDefinition(JacksonUtils.Companion.jsonNode(content)); - modelType.setModelName(modelName); - modelType.setVersion("1.0.0"); - modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelType.setUpdatedBy("xxxxxx@xxx.com"); - modelType = modelTypeHandler.saveModel(modelType); - log.info("Saved Mode {}", modelType.toString()); - Assert.assertNotNull("Failed to get Saved ModelType", modelType); - Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.getModelName()); - - ModelType dbModelType = modelTypeHandler.getModelTypeByName(modelType.getModelName()); - Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")", - dbModelType); - - // Model Update - modelType.setUpdatedBy("bs2796@xxx.com"); - modelType = modelTypeHandler.saveModel(modelType); - Assert.assertNotNull("Failed to get Saved ModelType", modelType); - Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.getUpdatedBy()); - - } - - @Test - public void test02SearchModelTypes() throws Exception { - log.info("*********************** test02SearchModelTypes ***************************"); - - String tags = "test-datatype"; - - List dbModelTypes = modelTypeHandler.searchModelTypes(tags); - Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes); - Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size() > 0); - - } - - @Test - public void test03GetModelType() throws Exception { - log.info("************************* test03GetModelType *********************************"); - ModelType dbModelType = modelTypeHandler.getModelTypeByName(modelName); - Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType); - Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType.getModelName()); - - List dbDatatypeModelTypes = - modelTypeHandler.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes); - Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size() > 0); - - List dbModelTypeByDerivedFroms = - modelTypeHandler.getModelTypeByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); - Assert.assertNotNull("Failed to find getModelTypeByDerivedFrom by tags", dbModelTypeByDerivedFroms); - Assert.assertTrue("Failed to find getModelTypeByDerivedFrom by count", dbModelTypeByDerivedFroms.size() > 0); - - } - - @Test - public void test04DeleteModelType() throws Exception { - log.info( - "************************ test03DeleteModelType ***********************"); - ModelType dbResourceMapping = modelTypeHandler.getModelTypeByName(modelName); - Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping); - Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping.getModelName()); - - modelTypeHandler.deleteByModelName(dbResourceMapping.getModelName()); - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java deleted file mode 100644 index ed208db97..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.apps.controllerblueprints.service.common; - -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.apps.controllerblueprints.service.SchemaGeneratorService; - -import java.io.File; -import java.nio.charset.Charset; - - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class SchemaGeneratorServiceTest { - - private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorServiceTest.class); - - @Test - public void test01GenerateSwaggerData() throws Exception { - log.info("******************* test01GenerateSwaggerData ******************************"); - - String file = "src/test/resources/enhance/enhanced-template.json"; - String serviceTemplateContent = FileUtils.readFileToString(new File(file), Charset.defaultCharset()); - SchemaGeneratorService schemaGeneratorService = new SchemaGeneratorService(); - String schema = schemaGeneratorService.generateSchema(serviceTemplateContent); - log.trace("Generated Schema " + schema); - Assert.assertNotNull("failed to generate Sample Data", schema); - - } - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java deleted file mode 100644 index 739ce51bb..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright © 2018 IBM. - * - * 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.apps.controllerblueprints.service.repository; - -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.annotation.Commit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Arrays; -import java.util.List; - -/** - * ModelTypeReactRepositoryTest. - * - * @author Brinda Santh - */ - -@RunWith(SpringRunner.class) -@DataJpaTest -@ContextConfiguration(classes = {TestApplication.class}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ModelTypeReactRepositoryTest { - - @Autowired - private ModelTypeReactRepository modelTypeReactRepository; - - String modelName = "test-datatype"; - - @Test - @Commit - public void test01Save() { - String content = JacksonUtils.Companion.getClassPathFileContent("model_type/data_type/datatype-property.json"); - ModelType modelType = new ModelType(); - modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); - modelType.setDescription("Definition for Sample Datatype "); - modelType.setDefinition(JacksonUtils.Companion.jsonNode(content)); - modelType.setModelName(modelName); - modelType.setVersion("1.0.0"); - modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); - modelType.setUpdatedBy("xxxxxx@xxx.com"); - - ModelType dbModelType = modelTypeReactRepository.save(modelType).block(); - Assert.assertNotNull("Failed to get Saved ModelType", dbModelType); - } - - @Test - public void test02Finds() { - ModelType dbFindByModelName = modelTypeReactRepository.findByModelName(modelName).block(); - Assert.assertNotNull("Failed to findByModelName ", dbFindByModelName); - - List dbFindByDefinitionType = - modelTypeReactRepository.findByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE).collectList().block(); - Assert.assertNotNull("Failed to findByDefinitionType ", dbFindByDefinitionType); - Assert.assertTrue("Failed to findByDefinitionType count", dbFindByDefinitionType.size() > 0); - - List dbFindByDerivedFrom = - modelTypeReactRepository.findByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT).collectList().block(); - Assert.assertNotNull("Failed to find findByDerivedFrom", dbFindByDerivedFrom); - Assert.assertTrue("Failed to find findByDerivedFrom by count", dbFindByDerivedFrom.size() > 0); - - List dbFindByModelNameIn = - modelTypeReactRepository.findByModelNameIn(Arrays.asList(modelName)).collectList().block(); - Assert.assertNotNull("Failed to findByModelNameIn ", dbFindByModelNameIn); - Assert.assertTrue("Failed to findByModelNameIn by count", dbFindByModelNameIn.size() > 0); - - List dbFindByDefinitionTypeIn = - modelTypeReactRepository.findByDefinitionTypeIn(Arrays.asList(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)).collectList().block(); - Assert.assertNotNull("Failed to findByDefinitionTypeIn", dbFindByDefinitionTypeIn); - Assert.assertTrue("Failed to findByDefinitionTypeIn by count", dbFindByDefinitionTypeIn.size() > 0); - - List dbFindByDerivedFromIn = - modelTypeReactRepository.findByDerivedFromIn(Arrays.asList(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT)).collectList().block(); - Assert.assertNotNull("Failed to find findByDerivedFromIn", dbFindByDerivedFromIn); - Assert.assertTrue("Failed to find findByDerivedFromIn by count", dbFindByDerivedFromIn.size() > 0); - } - - @Test - @Commit - public void test03Delete() { - modelTypeReactRepository.deleteByModelName(modelName).block(); - } - -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java deleted file mode 100644 index 330eaa844..000000000 --- a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright © 2018 IBM. - * Modifications Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.apps.controllerblueprints.service.repository; - -import org.junit.Assert; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.apps.controllerblueprints.TestApplication; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition; -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.annotation.Commit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Arrays; -import java.util.List; - -/** - * ResourceDictionaryReactRepositoryTest. - * - * @author Brinda Santh - */ - -@RunWith(SpringRunner.class) -@DataJpaTest -@ContextConfiguration(classes = {TestApplication.class}) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class ResourceDictionaryReactRepositoryTest { - - private String sourceName = "test-source"; - - @Autowired - protected ResourceDictionaryReactRepository resourceDictionaryReactRepository; - - @Test - @Commit - public void test01Save() { - ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile("./../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-primary-db-source.json", ResourceDefinition.class); - Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition); - resourceDefinition.setName(sourceName); - - ResourceDictionary resourceDictionary = transformResourceDictionary(resourceDefinition); - ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.save(resourceDictionary).block(); - Assert.assertNotNull("Failed to save ResourceDictionary", dbResourceDictionary); - } - - @Test - public void test02FindByNameReact() { - ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName(sourceName).block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary); - } - - @Test - public void test03FindByNameInReact() { - List dbResourceDictionaries = - resourceDictionaryReactRepository.findByNameIn(Arrays.asList(sourceName)).collectList().block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries); - } - - @Test - public void test04FindByTagsContainingIgnoreCaseReact() { - List dbTagsResourceDictionaries = - resourceDictionaryReactRepository.findByTagsContainingIgnoreCase(sourceName).collectList().block(); - Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries); - } - - @Test - @Commit - public void test05Delete() { - resourceDictionaryReactRepository.deleteByName(sourceName).block(); - } - - private ResourceDictionary transformResourceDictionary(ResourceDefinition resourceDefinition) { - ResourceDictionary resourceDictionary = new ResourceDictionary(); - resourceDictionary.setName(resourceDefinition.getName()); - resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); - resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); - resourceDictionary.setTags(resourceDefinition.getTags()); - resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); - resourceDictionary.setDefinition(resourceDefinition); - return resourceDictionary; - } -} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/DatabaseConfig.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/DatabaseConfig.java new file mode 100644 index 000000000..658d3072f --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/DatabaseConfig.java @@ -0,0 +1,61 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.controllerblueprints; + +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +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.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; + +/** + * DatabaseConfig.java Purpose: Provide Configuration Generator DatabaseConfig Information + * + * @author Brinda Santh + * @version 1.0 + */ +@Configuration +@EntityScan("org.onap.ccsdk.cds.controllerblueprints.service.domain") +@EnableTransactionManagement +@EnableJpaRepositories("org.onap.ccsdk.cds.controllerblueprints.service.repository") +@EnableJpaAuditing +public class DatabaseConfig { + /** + * This is a entityManagerFactory method + * + * @param dataSource + * @return LocalContainerEntityManagerFactoryBean + */ + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) { + HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); + vendorAdapter.setGenerateDdl(true); + vendorAdapter.setShowSql(false); + LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); + factory.setJpaVendorAdapter(vendorAdapter); + factory.setPackagesToScan("org.onap.ccsdk.cds.controllerblueprints.service.domain"); + factory.setDataSource(dataSource); + return factory; + } + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/TestApplication.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/TestApplication.java new file mode 100644 index 000000000..d5ea7bc5d --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/TestApplication.java @@ -0,0 +1,34 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.controllerblueprints; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + + +@SpringBootApplication +@ComponentScan(basePackages = {"org.onap.ccsdk.cds.controllerblueprints"}) +@EnableAutoConfiguration +public class TestApplication { + + public static void main(String[] args) { + SpringApplication.run(TestApplication.class, args); + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java new file mode 100644 index 000000000..12652c916 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/ModelTypeServiceTest.java @@ -0,0 +1,127 @@ +/* + * Copyright © 2018 IBM. + * + * 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.controllerblueprints.service; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.cds.controllerblueprints.TestApplication; +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType; +import org.onap.ccsdk.cds.controllerblueprints.service.handler.ModelTypeHandler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.annotation.Commit; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +@RunWith(SpringRunner.class) +@DataJpaTest +@Transactional(propagation = Propagation.NOT_SUPPORTED) +@ContextConfiguration(classes = {TestApplication.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ModelTypeServiceTest { + private static EELFLogger log = EELFManager.getInstance().getLogger(ModelTypeServiceTest.class); + @Autowired + private ModelTypeHandler modelTypeHandler; + + String modelName = "test-datatype"; + + @Test + @Commit + public void test01SaveModelType() throws Exception { + log.info("**************** test01SaveModelType ********************"); + + String content = JacksonUtils.Companion.getClassPathFileContent("model_type/data_type/datatype-property.json"); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); + modelType.setDescription("Definition for Sample Datatype "); + modelType.setDefinition(JacksonUtils.Companion.jsonNode(content)); + modelType.setModelName(modelName); + modelType.setVersion("1.0.0"); + modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setUpdatedBy("xxxxxx@xxx.com"); + modelType = modelTypeHandler.saveModel(modelType); + log.info("Saved Mode {}", modelType.toString()); + Assert.assertNotNull("Failed to get Saved ModelType", modelType); + Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.getModelName()); + + ModelType dbModelType = modelTypeHandler.getModelTypeByName(modelType.getModelName()); + Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")", + dbModelType); + + // Model Update + modelType.setUpdatedBy("bs2796@xxx.com"); + modelType = modelTypeHandler.saveModel(modelType); + Assert.assertNotNull("Failed to get Saved ModelType", modelType); + Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.getUpdatedBy()); + + } + + @Test + public void test02SearchModelTypes() throws Exception { + log.info("*********************** test02SearchModelTypes ***************************"); + + String tags = "test-datatype"; + + List dbModelTypes = modelTypeHandler.searchModelTypes(tags); + Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes); + Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.size() > 0); + + } + + @Test + public void test03GetModelType() throws Exception { + log.info("************************* test03GetModelType *********************************"); + ModelType dbModelType = modelTypeHandler.getModelTypeByName(modelName); + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbModelType); + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType.getModelName()); + + List dbDatatypeModelTypes = + modelTypeHandler.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes); + Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.size() > 0); + + List dbModelTypeByDerivedFroms = + modelTypeHandler.getModelTypeByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); + Assert.assertNotNull("Failed to find getModelTypeByDerivedFrom by tags", dbModelTypeByDerivedFroms); + Assert.assertTrue("Failed to find getModelTypeByDerivedFrom by count", dbModelTypeByDerivedFroms.size() > 0); + + } + + @Test + public void test04DeleteModelType() throws Exception { + log.info( + "************************ test03DeleteModelType ***********************"); + ModelType dbResourceMapping = modelTypeHandler.getModelTypeByName(modelName); + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping); + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping.getModelName()); + + modelTypeHandler.deleteByModelName(dbResourceMapping.getModelName()); + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SchemaGeneratorServiceTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SchemaGeneratorServiceTest.java new file mode 100644 index 000000000..56a92fe0a --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/common/SchemaGeneratorServiceTest.java @@ -0,0 +1,50 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.controllerblueprints.service.common; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.cds.controllerblueprints.service.SchemaGeneratorService; + +import java.io.File; +import java.nio.charset.Charset; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class SchemaGeneratorServiceTest { + + private static EELFLogger log = EELFManager.getInstance().getLogger(SchemaGeneratorServiceTest.class); + + @Test + public void test01GenerateSwaggerData() throws Exception { + log.info("******************* test01GenerateSwaggerData ******************************"); + + String file = "src/test/resources/enhance/enhanced-template.json"; + String serviceTemplateContent = FileUtils.readFileToString(new File(file), Charset.defaultCharset()); + SchemaGeneratorService schemaGeneratorService = new SchemaGeneratorService(); + String schema = schemaGeneratorService.generateSchema(serviceTemplateContent); + log.trace("Generated Schema " + schema); + Assert.assertNotNull("failed to generate Sample Data", schema); + + } + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java new file mode 100644 index 000000000..26b162494 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java @@ -0,0 +1,110 @@ +/* + * Copyright © 2018 IBM. + * + * 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.controllerblueprints.service.repository; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.cds.controllerblueprints.TestApplication; +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.annotation.Commit; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Arrays; +import java.util.List; + +/** + * ModelTypeReactRepositoryTest. + * + * @author Brinda Santh + */ + +@RunWith(SpringRunner.class) +@DataJpaTest +@ContextConfiguration(classes = {TestApplication.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ModelTypeReactRepositoryTest { + + @Autowired + private ModelTypeReactRepository modelTypeReactRepository; + + String modelName = "test-datatype"; + + @Test + @Commit + public void test01Save() { + String content = JacksonUtils.Companion.getClassPathFileContent("model_type/data_type/datatype-property.json"); + ModelType modelType = new ModelType(); + modelType.setDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT); + modelType.setDescription("Definition for Sample Datatype "); + modelType.setDefinition(JacksonUtils.Companion.jsonNode(content)); + modelType.setModelName(modelName); + modelType.setVersion("1.0.0"); + modelType.setTags("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + modelType.setUpdatedBy("xxxxxx@xxx.com"); + + ModelType dbModelType = modelTypeReactRepository.save(modelType).block(); + Assert.assertNotNull("Failed to get Saved ModelType", dbModelType); + } + + @Test + public void test02Finds() { + ModelType dbFindByModelName = modelTypeReactRepository.findByModelName(modelName).block(); + Assert.assertNotNull("Failed to findByModelName ", dbFindByModelName); + + List dbFindByDefinitionType = + modelTypeReactRepository.findByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE).collectList().block(); + Assert.assertNotNull("Failed to findByDefinitionType ", dbFindByDefinitionType); + Assert.assertTrue("Failed to findByDefinitionType count", dbFindByDefinitionType.size() > 0); + + List dbFindByDerivedFrom = + modelTypeReactRepository.findByDerivedFrom(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT).collectList().block(); + Assert.assertNotNull("Failed to find findByDerivedFrom", dbFindByDerivedFrom); + Assert.assertTrue("Failed to find findByDerivedFrom by count", dbFindByDerivedFrom.size() > 0); + + List dbFindByModelNameIn = + modelTypeReactRepository.findByModelNameIn(Arrays.asList(modelName)).collectList().block(); + Assert.assertNotNull("Failed to findByModelNameIn ", dbFindByModelNameIn); + Assert.assertTrue("Failed to findByModelNameIn by count", dbFindByModelNameIn.size() > 0); + + List dbFindByDefinitionTypeIn = + modelTypeReactRepository.findByDefinitionTypeIn(Arrays.asList(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE)).collectList().block(); + Assert.assertNotNull("Failed to findByDefinitionTypeIn", dbFindByDefinitionTypeIn); + Assert.assertTrue("Failed to findByDefinitionTypeIn by count", dbFindByDefinitionTypeIn.size() > 0); + + List dbFindByDerivedFromIn = + modelTypeReactRepository.findByDerivedFromIn(Arrays.asList(BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT)).collectList().block(); + Assert.assertNotNull("Failed to find findByDerivedFromIn", dbFindByDerivedFromIn); + Assert.assertTrue("Failed to find findByDerivedFromIn by count", dbFindByDerivedFromIn.size() > 0); + } + + @Test + @Commit + public void test03Delete() { + modelTypeReactRepository.deleteByModelName(modelName).block(); + } + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java new file mode 100644 index 000000000..37e0549fa --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/cds/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java @@ -0,0 +1,103 @@ +/* + * Copyright © 2018 IBM. + * Modifications Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.controllerblueprints.service.repository; + +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.cds.controllerblueprints.TestApplication; +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition; +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ResourceDictionary; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.test.annotation.Commit; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.Arrays; +import java.util.List; + +/** + * ResourceDictionaryReactRepositoryTest. + * + * @author Brinda Santh + */ + +@RunWith(SpringRunner.class) +@DataJpaTest +@ContextConfiguration(classes = {TestApplication.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ResourceDictionaryReactRepositoryTest { + + private String sourceName = "test-source"; + + @Autowired + protected ResourceDictionaryReactRepository resourceDictionaryReactRepository; + + @Test + @Commit + public void test01Save() { + ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile("./../../../../components/model-catalog/resource-dictionary/starter-dictionary/sample-primary-db-source.json", ResourceDefinition.class); + Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition); + resourceDefinition.setName(sourceName); + + ResourceDictionary resourceDictionary = transformResourceDictionary(resourceDefinition); + ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.save(resourceDictionary).block(); + Assert.assertNotNull("Failed to save ResourceDictionary", dbResourceDictionary); + } + + @Test + public void test02FindByNameReact() { + ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName(sourceName).block(); + Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary); + } + + @Test + public void test03FindByNameInReact() { + List dbResourceDictionaries = + resourceDictionaryReactRepository.findByNameIn(Arrays.asList(sourceName)).collectList().block(); + Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries); + } + + @Test + public void test04FindByTagsContainingIgnoreCaseReact() { + List dbTagsResourceDictionaries = + resourceDictionaryReactRepository.findByTagsContainingIgnoreCase(sourceName).collectList().block(); + Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries); + } + + @Test + @Commit + public void test05Delete() { + resourceDictionaryReactRepository.deleteByName(sourceName).block(); + } + + private ResourceDictionary transformResourceDictionary(ResourceDefinition resourceDefinition) { + ResourceDictionary resourceDictionary = new ResourceDictionary(); + resourceDictionary.setName(resourceDefinition.getName()); + resourceDictionary.setDataType(resourceDefinition.getProperty().getType()); + resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription()); + resourceDictionary.setTags(resourceDefinition.getTags()); + resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy()); + resourceDictionary.setDefinition(resourceDefinition); + return resourceDictionary; + } +} diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelControllerTest.kt deleted file mode 100644 index d504c293e..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/BlueprintModelControllerTest.kt +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright © 2019 Bell Canada Intellectual Property. - * Modifications Copyright © 2019 IBM. - * - * 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.apps.controllerblueprints.service.controller - -import com.google.gson.Gson -import org.json.JSONException -import org.json.JSONObject -import org.junit.After -import org.junit.Before -import org.junit.FixMethodOrder -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.MethodSorters -import org.onap.ccsdk.apps.controllerblueprints.TestApplication -import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintArchiveUtils -import org.onap.ccsdk.apps.controllerblueprints.service.domain.BlueprintModelSearch -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.EnableAutoConfiguration -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.context.annotation.ComponentScan -import org.springframework.core.io.ByteArrayResource -import org.springframework.http.HttpMethod -import org.springframework.http.HttpStatus -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner -import org.springframework.test.web.reactive.server.WebTestClient -import org.springframework.util.Base64Utils -import org.springframework.web.reactive.function.BodyInserters -import java.io.File -import java.io.IOException -import java.nio.charset.StandardCharsets.UTF_8 -import java.nio.file.Files -import java.nio.file.Paths - -/** - * BlueprintModelControllerTest Purpose: Integration test at API level - * - * @author Vinal Patel - * @version 1.0 - */ - -@RunWith(SpringRunner::class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ContextConfiguration(classes = [TestApplication::class]) -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.controllerblueprints"]) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@EnableAutoConfiguration -class BlueprintModelControllerTest { - - companion object { - - private var id: String? = null - private var name: String? = null - private var version: String? = null - private var tag: String? = null - private var result: String? = null - } - - @Value("\${controllerblueprints.loadBluePrintPaths}") - private val loadBluePrintPaths: String? = null - - @Autowired - private val webTestClient: WebTestClient? = null - - @Value("\${controllerblueprints.loadBlueprintsExamplesPath}") - private val blueprintArchivePath: String? = null - - private val filename = "test.zip" - private var blueprintFile: File? = null - private var zipBlueprintFile: File? = null - - @Before - @Throws(Exception::class) - fun setUp() { - blueprintFile = File(loadBluePrintPaths+"/baseconfiguration") - if (blueprintFile!!.isDirectory) { - zipBlueprintFile = File(Paths.get(blueprintArchivePath).resolve(filename).toString()) - BluePrintArchiveUtils.compress(blueprintFile!!, zipBlueprintFile!!, true) - } - } - - @After - @Throws(Exception::class) - fun tearDown() { - zipBlueprintFile!!.delete() - } - - @Test - @Throws(IOException::class, JSONException::class) - fun test1_saveBluePrint() { - webTestClient(HttpMethod.POST, - BodyInserters.fromMultipartData("file", object : ByteArrayResource(Files.readAllBytes(zipBlueprintFile!!.toPath())) { - override fun getFilename(): String? { - return "test.zip" - } - }), - "/api/v1/blueprint-model", - HttpStatus.OK, true) - } - - @Test - @Throws(JSONException::class) - fun test2_getBluePrintByNameAndVersion() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/by-name/$name/version/$version", HttpStatus.OK, false) - } - - - @Test - @Throws(JSONException::class) - fun test3_getBlueprintModel() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/$id", HttpStatus.OK, false) - } - - @Test - @Throws(JSONException::class) - fun test4_getAllBlueprintModel() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model", HttpStatus.OK, false) - } - - @Test - @Throws(JSONException::class) - fun test5_downloadBluePrint() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/$id", HttpStatus.OK, false) - } - - @Test - fun test6_publishBlueprintModel() { - } - - @Test - @Throws(JSONException::class) - fun test7_searchBlueprintModels() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/search/$name", HttpStatus.OK, false) - } - - @Test - @Throws(JSONException::class) - fun test8_downloadBlueprintByNameAndVersion() { - webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/by-name/$name/version/$version", HttpStatus.OK, false) - } - - @Test - fun test9_deleteBluePrint() { - //TODO: Use webTestClient function - //webTestClient(HttpMethod.DELETE, null, "/api/v1/blueprint-model/" + id, HttpStatus.OK, false); - webTestClient!!.delete().uri("/api/v1/blueprint-model/$id") - .header("Authorization", "Basic " + Base64Utils - .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) - .exchange() - .expectStatus().is2xxSuccessful - } - - @Throws(JSONException::class) - private fun webTestClient(requestMethod: HttpMethod, body: BodyInserters.MultipartInserter?, uri: String, expectedResponceStatus: HttpStatus, setParam: Boolean) { - - result = String(webTestClient!!.method(requestMethod).uri(uri) - .header("Authorization", "Basic " + Base64Utils - .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) - .body(body) - .exchange() - .expectStatus().isEqualTo(expectedResponceStatus) - .expectBody() - .returnResult().responseBody!!) - - if (setParam) { - val jsonResponse = JSONObject(result) - val blueprintModelSearchJSON = jsonResponse.getJSONObject("blueprintModel") - val gson = Gson() - val blueprintModelSearch = gson.fromJson(blueprintModelSearchJSON.toString(), BlueprintModelSearch::class.java) - id = blueprintModelSearch.id - name = blueprintModelSearch.artifactName - version = blueprintModelSearch.artifactVersion - tag = blueprintModelSearch.tags - } - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeControllerTest.kt deleted file mode 100644 index 6fd0d1f04..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ModelTypeControllerTest.kt +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * 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.apps.controllerblueprints.service.controller - -import com.att.eelf.configuration.EELFManager -import org.junit.Assert -import org.junit.FixMethodOrder -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.MethodSorters -import org.onap.ccsdk.apps.controllerblueprints.TestApplication -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest -import org.springframework.test.annotation.Commit -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner - -@RunWith(SpringRunner::class) -@DataJpaTest -@ContextConfiguration(classes = [TestApplication::class]) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -class ModelTypeControllerTest { - - private val log = EELFManager.getInstance().getLogger(ModelTypeControllerTest::class.java)!! - - @Autowired - internal var modelTypeController: ModelTypeController? = null - - private var modelName = "test-datatype" - - @Test - @Commit - @Throws(Exception::class) - fun test01SaveModelType() { - log.info("**************** test01SaveModelType ********************") - - val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json") - var modelType = ModelType() - modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE - modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT - modelType.description = "Definition for Sample Datatype " - modelType.definition = JacksonUtils.jsonNode(content) - modelType.modelName = modelName - modelType.version = "1.0.0" - modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," - + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) - modelType.updatedBy = "xxxxxx@xxx.com" - modelType = modelTypeController!!.saveModelType(modelType) - log.info("Saved Mode {}", modelType.toString()) - Assert.assertNotNull("Failed to get Saved ModelType", modelType) - Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName) - - val dbModelType = modelTypeController!!.getModelTypeByName(modelType.modelName) - Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", - dbModelType) - - // Model Update - modelType.updatedBy = "bs2796@xxx.com" - modelType = modelTypeController!!.saveModelType(modelType) - Assert.assertNotNull("Failed to get Saved ModelType", modelType) - Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy) - - } - - @Test - @Throws(Exception::class) - fun test02SearchModelTypes() { - log.info("*********************** test02SearchModelTypes ***************************") - - val tags = "test-datatype" - - val dbModelTypes = modelTypeController!!.searchModelTypes(tags) - Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes) - Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty()) - - } - - @Test - @Throws(Exception::class) - fun test03GetModelType() { - log.info("************************* test03GetModelType *********************************") - val dbModelType = modelTypeController!!.getModelTypeByName(modelName) - Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType) - Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType!!.modelName) - - val dbDatatypeModelTypes = modelTypeController!!.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) - Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes) - Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.isNotEmpty()) - } - - @Test - @Commit - @Throws(Exception::class) - fun test04DeleteModelType() { - log.info( - "************************ test03DeleteModelType ***********************") - val dbResourceMapping = modelTypeController!!.getModelTypeByName(modelName) - Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping) - Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping!!.modelName) - - modelTypeController!!.deleteModelTypeByName(dbResourceMapping.modelName) - } -} diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt deleted file mode 100644 index 96c142613..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * 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.apps.controllerblueprints.service.controller - -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.controllerblueprints.TestApplication -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.context.annotation.ComponentScan -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.junit4.SpringRunner -import kotlin.test.assertNotNull - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = [TestApplication::class]) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ComponentScan(basePackages = ["org.onap.ccsdk.apps.controllerblueprints"]) -class ResourceDictionaryControllerTest { - - @Autowired - lateinit var resourceDictionaryController: ResourceDictionaryController - - @Test - fun testResourceDictionaryControllerPresence() { - assertNotNull(resourceDictionaryController, "failed to initialise ResourceDictionaryController") - } - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt deleted file mode 100644 index 60420aa64..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/controller/mock/MockFilePart.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * 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.apps.controllerblueprints.service.controller.mock - -import org.apache.commons.io.FilenameUtils -import org.slf4j.LoggerFactory -import org.springframework.core.io.buffer.DataBuffer -import org.springframework.http.HttpHeaders -import org.springframework.http.codec.multipart.FilePart -import org.springframework.util.FileCopyUtils -import reactor.core.publisher.Flux -import reactor.core.publisher.Mono -import java.io.File -import java.nio.file.Path - -class MockFilePart(private val fileName: String) : FilePart { - val log = LoggerFactory.getLogger(MockFilePart::class.java)!! - override fun content(): Flux { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun headers(): HttpHeaders { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - override fun filename(): String { - return FilenameUtils.getName(fileName) - } - - override fun name(): String { - return FilenameUtils.getBaseName(fileName) - } - - override fun transferTo(path: Path): Mono { - log.info("Copying file($fileName to ${path}") - FileCopyUtils.copy(File(fileName), path.toFile()) - return Mono.empty() - } -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt deleted file mode 100644 index 62a37bef1..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.apps.controllerblueprints.service.enhancer - -import kotlinx.coroutines.runBlocking -import org.junit.Assert -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.onap.ccsdk.apps.controllerblueprints.TestApplication -import org.onap.ccsdk.apps.controllerblueprints.core.deleteDir -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintEnhancerService -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintValidatorService -import org.onap.ccsdk.apps.controllerblueprints.core.normalizedPathName -import org.onap.ccsdk.apps.controllerblueprints.service.load.ModelTypeLoadService -import org.onap.ccsdk.apps.controllerblueprints.service.load.ResourceDictionaryLoadService -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.test.context.ContextConfiguration -import org.springframework.test.context.TestPropertySource -import org.springframework.test.context.junit4.SpringRunner - -@RunWith(SpringRunner::class) -@ContextConfiguration(classes = arrayOf(TestApplication::class)) -@TestPropertySource(locations = arrayOf("classpath:application.properties")) -class BluePrintEnhancerServiceImplTest { - - @Autowired - lateinit var modelTypeLoadService: ModelTypeLoadService - - @Autowired - lateinit var resourceDictionaryLoadService: ResourceDictionaryLoadService - - @Autowired - lateinit var bluePrintEnhancerService: BluePrintEnhancerService - - @Autowired - lateinit var bluePrintValidatorService: BluePrintValidatorService - - @Before - fun init() { - runBlocking { - modelTypeLoadService.loadPathModelType("./../../../../components/model-catalog/definition-type/starter-type") - resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/starter-dictionary") - resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/test-dictionary") - } - } - - @Test - @Throws(Exception::class) - fun testEnhancementAndValidation() { - - val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" - testComponentInvokeEnhancementAndValidation(basePath, "base-enhance") - } - - @Test - @Throws(Exception::class) - fun testComponentInvokeEnhancementAndValidation() { - val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/component_invoke" - testComponentInvokeEnhancementAndValidation(basePath, "component-enhance") - } - - @Test - @Throws(Exception::class) - fun testGoldenEnhancementAndValidation() { - val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/golden" - testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance") - } - - @Test - @Throws(Exception::class) - fun testCapabilityRestconfEnhancementAndValidation() { - val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_restconf" - testComponentInvokeEnhancementAndValidation(basePath, "capability_restconf-enhance") - - } - - private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) { - runBlocking { - val targetPath = normalizedPathName("target/blueprints/enrichment", targetDirName) - - deleteDir(targetPath) - - val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) - Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) - - // Validate the Generated BluePrints - val valid = bluePrintValidatorService.validateBluePrints(targetPath) - Assert.assertTrue("blueprint($basePath) validation failed ", valid) - - deleteDir(targetPath) - } - } - - -} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt deleted file mode 100644 index 6bd10525e..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright © 2019 IBM. - * - * 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.apps.controllerblueprints.service.utils - -import kotlinx.coroutines.runBlocking -import org.junit.After -import org.junit.Before -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.core.* -import org.onap.ccsdk.apps.controllerblueprints.service.controller.mock.MockFilePart -import java.nio.file.Paths -import java.util.* -import kotlin.test.assertTrue - -class BluePrintEnhancerUtilsTest { - - private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" - private val blueprintArchivePath: String = "./target/blueprints/archive" - private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment" - private var zipBlueprintFileName = normalizedPathName(blueprintArchivePath, "test.zip") - - @Before - fun setUp() { - val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs() - assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}") - val enhancerDir = normalizedFile(blueprintEnrichmentPath).reCreateDirs() - assertTrue(enhancerDir.exists(), "failed to create enhancerDir(${enhancerDir.absolutePath}") - val blueprintFile = Paths.get(blueprintDir).toFile().normalize() - val testZipFile = blueprintFile.compress(zipBlueprintFileName) - assertTrue(testZipFile.exists(), "Failed to create blueprint test zip(${testZipFile.absolutePath}") - } - - @After - fun tearDown() { - deleteDir(blueprintArchivePath) - deleteDir(blueprintEnrichmentPath) - } - - @Test - fun testFilePartCompressionNDeCompression() { - val filePart = MockFilePart(zipBlueprintFileName) - - runBlocking { - val enhanceId = UUID.randomUUID().toString() - val blueprintArchiveLocation = normalizedPathName(blueprintArchivePath, enhanceId) - val blueprintEnrichmentLocation = normalizedPathName(blueprintEnrichmentPath, enhanceId) - BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation) - BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation) - } - } -} - diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.kt deleted file mode 100644 index db4ee5c98..000000000 --- a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/validator/ModelTypeValidatorTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * 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.apps.controllerblueprints.service.validator - -import com.fasterxml.jackson.databind.JsonNode -import org.junit.Test -import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType - -class ModelTypeValidatorTest { - - @Test(expected = IllegalStateException::class) - @Throws(Exception::class) - fun testvalidateModelType() { - val modelType = ModelType() - modelType.definitionType = "" - modelType.derivedFrom = "" - modelType.description = "" - val definitionContent: JsonNode? = null - modelType.definition = definitionContent - modelType.modelName = "" - modelType.version = "" - modelType.tags = "" - modelType.updatedBy = "" - ModelTypeValidator.validateModelType(modelType) - } -} diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelControllerTest.kt new file mode 100644 index 000000000..d61e64251 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/BlueprintModelControllerTest.kt @@ -0,0 +1,193 @@ +/* + * Copyright © 2019 Bell Canada Intellectual Property. + * Modifications Copyright © 2019 IBM. + * + * 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.controllerblueprints.service.controller + +import com.google.gson.Gson +import org.json.JSONException +import org.json.JSONObject +import org.junit.After +import org.junit.Before +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.onap.ccsdk.cds.controllerblueprints.TestApplication +import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintArchiveUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.BlueprintModelSearch +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.autoconfigure.EnableAutoConfiguration +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.context.annotation.ComponentScan +import org.springframework.core.io.ByteArrayResource +import org.springframework.http.HttpMethod +import org.springframework.http.HttpStatus +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import org.springframework.test.web.reactive.server.WebTestClient +import org.springframework.util.Base64Utils +import org.springframework.web.reactive.function.BodyInserters +import java.io.File +import java.io.IOException +import java.nio.charset.StandardCharsets.UTF_8 +import java.nio.file.Files +import java.nio.file.Paths + +/** + * BlueprintModelControllerTest Purpose: Integration test at API level + * + * @author Vinal Patel + * @version 1.0 + */ + +@RunWith(SpringRunner::class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = [TestApplication::class]) +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.controllerblueprints"]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@EnableAutoConfiguration +class BlueprintModelControllerTest { + + companion object { + + private var id: String? = null + private var name: String? = null + private var version: String? = null + private var tag: String? = null + private var result: String? = null + } + + @Value("\${controllerblueprints.loadBluePrintPaths}") + private val loadBluePrintPaths: String? = null + + @Autowired + private val webTestClient: WebTestClient? = null + + @Value("\${controllerblueprints.loadBlueprintsExamplesPath}") + private val blueprintArchivePath: String? = null + + private val filename = "test.zip" + private var blueprintFile: File? = null + private var zipBlueprintFile: File? = null + + @Before + @Throws(Exception::class) + fun setUp() { + blueprintFile = File(loadBluePrintPaths+"/baseconfiguration") + if (blueprintFile!!.isDirectory) { + zipBlueprintFile = File(Paths.get(blueprintArchivePath).resolve(filename).toString()) + BluePrintArchiveUtils.compress(blueprintFile!!, zipBlueprintFile!!, true) + } + } + + @After + @Throws(Exception::class) + fun tearDown() { + zipBlueprintFile!!.delete() + } + + @Test + @Throws(IOException::class, JSONException::class) + fun test1_saveBluePrint() { + webTestClient(HttpMethod.POST, + BodyInserters.fromMultipartData("file", object : ByteArrayResource(Files.readAllBytes(zipBlueprintFile!!.toPath())) { + override fun getFilename(): String? { + return "test.zip" + } + }), + "/api/v1/blueprint-model", + HttpStatus.OK, true) + } + + @Test + @Throws(JSONException::class) + fun test2_getBluePrintByNameAndVersion() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/by-name/$name/version/$version", HttpStatus.OK, false) + } + + + @Test + @Throws(JSONException::class) + fun test3_getBlueprintModel() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/$id", HttpStatus.OK, false) + } + + @Test + @Throws(JSONException::class) + fun test4_getAllBlueprintModel() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model", HttpStatus.OK, false) + } + + @Test + @Throws(JSONException::class) + fun test5_downloadBluePrint() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/$id", HttpStatus.OK, false) + } + + @Test + fun test6_publishBlueprintModel() { + } + + @Test + @Throws(JSONException::class) + fun test7_searchBlueprintModels() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/search/$name", HttpStatus.OK, false) + } + + @Test + @Throws(JSONException::class) + fun test8_downloadBlueprintByNameAndVersion() { + webTestClient(HttpMethod.GET, null, "/api/v1/blueprint-model/download/by-name/$name/version/$version", HttpStatus.OK, false) + } + + @Test + fun test9_deleteBluePrint() { + //TODO: Use webTestClient function + //webTestClient(HttpMethod.DELETE, null, "/api/v1/blueprint-model/" + id, HttpStatus.OK, false); + webTestClient!!.delete().uri("/api/v1/blueprint-model/$id") + .header("Authorization", "Basic " + Base64Utils + .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) + .exchange() + .expectStatus().is2xxSuccessful + } + + @Throws(JSONException::class) + private fun webTestClient(requestMethod: HttpMethod, body: BodyInserters.MultipartInserter?, uri: String, expectedResponceStatus: HttpStatus, setParam: Boolean) { + + result = String(webTestClient!!.method(requestMethod).uri(uri) + .header("Authorization", "Basic " + Base64Utils + .encodeToString(("ccsdkapps" + ":" + "ccsdkapps").toByteArray(UTF_8))) + .body(body) + .exchange() + .expectStatus().isEqualTo(expectedResponceStatus) + .expectBody() + .returnResult().responseBody!!) + + if (setParam) { + val jsonResponse = JSONObject(result) + val blueprintModelSearchJSON = jsonResponse.getJSONObject("blueprintModel") + val gson = Gson() + val blueprintModelSearch = gson.fromJson(blueprintModelSearchJSON.toString(), BlueprintModelSearch::class.java) + id = blueprintModelSearch.id + name = blueprintModelSearch.artifactName + version = blueprintModelSearch.artifactVersion + tag = blueprintModelSearch.tags + } + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeControllerTest.kt new file mode 100644 index 000000000..610c9d033 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ModelTypeControllerTest.kt @@ -0,0 +1,120 @@ +/* + * Copyright © 2019 IBM. + * + * 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.controllerblueprints.service.controller + +import com.att.eelf.configuration.EELFManager +import org.junit.Assert +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.onap.ccsdk.cds.controllerblueprints.TestApplication +import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest +import org.springframework.test.annotation.Commit +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner + +@RunWith(SpringRunner::class) +@DataJpaTest +@ContextConfiguration(classes = [TestApplication::class]) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class ModelTypeControllerTest { + + private val log = EELFManager.getInstance().getLogger(ModelTypeControllerTest::class.java)!! + + @Autowired + internal var modelTypeController: ModelTypeController? = null + + private var modelName = "test-datatype" + + @Test + @Commit + @Throws(Exception::class) + fun test01SaveModelType() { + log.info("**************** test01SaveModelType ********************") + + val content = JacksonUtils.getClassPathFileContent("model_type/data_type/datatype-property.json") + var modelType = ModelType() + modelType.definitionType = BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE + modelType.derivedFrom = BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + modelType.description = "Definition for Sample Datatype " + modelType.definition = JacksonUtils.jsonNode(content) + modelType.modelName = modelName + modelType.version = "1.0.0" + modelType.tags = ("test-datatype ," + BluePrintConstants.MODEL_TYPE_DATATYPES_ROOT + "," + + BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + modelType.updatedBy = "xxxxxx@xxx.com" + modelType = modelTypeController!!.saveModelType(modelType) + log.info("Saved Mode {}", modelType.toString()) + Assert.assertNotNull("Failed to get Saved ModelType", modelType) + Assert.assertNotNull("Failed to get Saved ModelType, Id", modelType.modelName) + + val dbModelType = modelTypeController!!.getModelTypeByName(modelType.modelName) + Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType!!.modelName + ")", + dbModelType) + + // Model Update + modelType.updatedBy = "bs2796@xxx.com" + modelType = modelTypeController!!.saveModelType(modelType) + Assert.assertNotNull("Failed to get Saved ModelType", modelType) + Assert.assertEquals("Failed to get Saved getUpdatedBy ", "bs2796@xxx.com", modelType.updatedBy) + + } + + @Test + @Throws(Exception::class) + fun test02SearchModelTypes() { + log.info("*********************** test02SearchModelTypes ***************************") + + val tags = "test-datatype" + + val dbModelTypes = modelTypeController!!.searchModelTypes(tags) + Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes) + Assert.assertTrue("Failed to search ResourceMapping by tags count", dbModelTypes.isNotEmpty()) + + } + + @Test + @Throws(Exception::class) + fun test03GetModelType() { + log.info("************************* test03GetModelType *********************************") + val dbModelType = modelTypeController!!.getModelTypeByName(modelName) + Assert.assertNotNull("Failed to get response for api call getModelByName $modelName", dbModelType) + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbModelType!!.modelName) + + val dbDatatypeModelTypes = modelTypeController!!.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE) + Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes) + Assert.assertTrue("Failed to find getModelTypeByDefinitionType by count", dbDatatypeModelTypes.isNotEmpty()) + } + + @Test + @Commit + @Throws(Exception::class) + fun test04DeleteModelType() { + log.info( + "************************ test03DeleteModelType ***********************") + val dbResourceMapping = modelTypeController!!.getModelTypeByName(modelName) + Assert.assertNotNull("Failed to get response for api call getModelByName ", dbResourceMapping) + Assert.assertNotNull("Failed to get Id for api call getModelByName ", dbResourceMapping!!.modelName) + + modelTypeController!!.deleteModelTypeByName(dbResourceMapping.modelName) + } +} diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt new file mode 100644 index 000000000..cf139ec00 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/ResourceDictionaryControllerTest.kt @@ -0,0 +1,43 @@ +/* + * Copyright © 2019 IBM. + * + * 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.controllerblueprints.service.controller + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.controllerblueprints.TestApplication +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.context.annotation.ComponentScan +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [TestApplication::class]) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ComponentScan(basePackages = ["org.onap.ccsdk.cds.controllerblueprints"]) +class ResourceDictionaryControllerTest { + + @Autowired + lateinit var resourceDictionaryController: ResourceDictionaryController + + @Test + fun testResourceDictionaryControllerPresence() { + assertNotNull(resourceDictionaryController, "failed to initialise ResourceDictionaryController") + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/mock/MockFilePart.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/mock/MockFilePart.kt new file mode 100644 index 000000000..2fb2129ae --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/controller/mock/MockFilePart.kt @@ -0,0 +1,53 @@ +/* + * Copyright © 2019 IBM. + * + * 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.controllerblueprints.service.controller.mock + +import org.apache.commons.io.FilenameUtils +import org.slf4j.LoggerFactory +import org.springframework.core.io.buffer.DataBuffer +import org.springframework.http.HttpHeaders +import org.springframework.http.codec.multipart.FilePart +import org.springframework.util.FileCopyUtils +import reactor.core.publisher.Flux +import reactor.core.publisher.Mono +import java.io.File +import java.nio.file.Path + +class MockFilePart(private val fileName: String) : FilePart { + val log = LoggerFactory.getLogger(MockFilePart::class.java)!! + override fun content(): Flux { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun headers(): HttpHeaders { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun filename(): String { + return FilenameUtils.getName(fileName) + } + + override fun name(): String { + return FilenameUtils.getBaseName(fileName) + } + + override fun transferTo(path: Path): Mono { + log.info("Copying file($fileName to ${path}") + FileCopyUtils.copy(File(fileName), path.toFile()) + return Mono.empty() + } +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt new file mode 100644 index 000000000..677dd45ad --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/enhancer/BluePrintEnhancerServiceImplTest.kt @@ -0,0 +1,111 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.controllerblueprints.service.enhancer + +import kotlinx.coroutines.runBlocking +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.cds.controllerblueprints.TestApplication +import org.onap.ccsdk.cds.controllerblueprints.core.deleteDir +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintEnhancerService +import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BluePrintValidatorService +import org.onap.ccsdk.cds.controllerblueprints.core.normalizedPathName +import org.onap.ccsdk.cds.controllerblueprints.service.load.ModelTypeLoadService +import org.onap.ccsdk.cds.controllerblueprints.service.load.ResourceDictionaryLoadService +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = arrayOf(TestApplication::class)) +@TestPropertySource(locations = arrayOf("classpath:application.properties")) +class BluePrintEnhancerServiceImplTest { + + @Autowired + lateinit var modelTypeLoadService: ModelTypeLoadService + + @Autowired + lateinit var resourceDictionaryLoadService: ResourceDictionaryLoadService + + @Autowired + lateinit var bluePrintEnhancerService: BluePrintEnhancerService + + @Autowired + lateinit var bluePrintValidatorService: BluePrintValidatorService + + @Before + fun init() { + runBlocking { + modelTypeLoadService.loadPathModelType("./../../../../components/model-catalog/definition-type/starter-type") + resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/starter-dictionary") + resourceDictionaryLoadService.loadPathResourceDictionary("./../../../../components/model-catalog/resource-dictionary/test-dictionary") + } + } + + @Test + @Throws(Exception::class) + fun testEnhancementAndValidation() { + + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + testComponentInvokeEnhancementAndValidation(basePath, "base-enhance") + } + + @Test + @Throws(Exception::class) + fun testComponentInvokeEnhancementAndValidation() { + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/component_invoke" + testComponentInvokeEnhancementAndValidation(basePath, "component-enhance") + } + + @Test + @Throws(Exception::class) + fun testGoldenEnhancementAndValidation() { + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/golden" + testComponentInvokeEnhancementAndValidation(basePath, "golden-enhance") + } + + @Test + @Throws(Exception::class) + fun testCapabilityRestconfEnhancementAndValidation() { + val basePath = "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_restconf" + testComponentInvokeEnhancementAndValidation(basePath, "capability_restconf-enhance") + + } + + private fun testComponentInvokeEnhancementAndValidation(basePath: String, targetDirName: String) { + runBlocking { + val targetPath = normalizedPathName("target/blueprints/enrichment", targetDirName) + + deleteDir(targetPath) + + val bluePrintContext = bluePrintEnhancerService.enhance(basePath, targetPath) + Assert.assertNotNull("failed to get blueprintContext ", bluePrintContext) + + // Validate the Generated BluePrints + val valid = bluePrintValidatorService.validateBluePrints(targetPath) + Assert.assertTrue("blueprint($basePath) validation failed ", valid) + + deleteDir(targetPath) + } + } + + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt new file mode 100644 index 000000000..100c3adeb --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/utils/BluePrintEnhancerUtilsTest.kt @@ -0,0 +1,66 @@ +/* + * Copyright © 2019 IBM. + * + * 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.controllerblueprints.service.utils + +import kotlinx.coroutines.runBlocking +import org.junit.After +import org.junit.Before +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.* +import org.onap.ccsdk.cds.controllerblueprints.service.controller.mock.MockFilePart +import java.nio.file.Paths +import java.util.* +import kotlin.test.assertTrue + +class BluePrintEnhancerUtilsTest { + + private val blueprintDir = "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration" + private val blueprintArchivePath: String = "./target/blueprints/archive" + private val blueprintEnrichmentPath: String = "./target/blueprints/enrichment" + private var zipBlueprintFileName = normalizedPathName(blueprintArchivePath, "test.zip") + + @Before + fun setUp() { + val archiveDir = normalizedFile(blueprintArchivePath).reCreateDirs() + assertTrue(archiveDir.exists(), "failed to create archiveDir(${archiveDir.absolutePath}") + val enhancerDir = normalizedFile(blueprintEnrichmentPath).reCreateDirs() + assertTrue(enhancerDir.exists(), "failed to create enhancerDir(${enhancerDir.absolutePath}") + val blueprintFile = Paths.get(blueprintDir).toFile().normalize() + val testZipFile = blueprintFile.compress(zipBlueprintFileName) + assertTrue(testZipFile.exists(), "Failed to create blueprint test zip(${testZipFile.absolutePath}") + } + + @After + fun tearDown() { + deleteDir(blueprintArchivePath) + deleteDir(blueprintEnrichmentPath) + } + + @Test + fun testFilePartCompressionNDeCompression() { + val filePart = MockFilePart(zipBlueprintFileName) + + runBlocking { + val enhanceId = UUID.randomUUID().toString() + val blueprintArchiveLocation = normalizedPathName(blueprintArchivePath, enhanceId) + val blueprintEnrichmentLocation = normalizedPathName(blueprintEnrichmentPath, enhanceId) + BluePrintEnhancerUtils.decompressFilePart(filePart, blueprintArchiveLocation, blueprintEnrichmentLocation) + BluePrintEnhancerUtils.compressToFilePart(blueprintEnrichmentLocation, blueprintArchiveLocation) + } + } +} + diff --git a/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidatorTest.kt b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidatorTest.kt new file mode 100644 index 000000000..728f431a7 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/service/validator/ModelTypeValidatorTest.kt @@ -0,0 +1,40 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.controllerblueprints.service.validator + +import com.fasterxml.jackson.databind.JsonNode +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.service.domain.ModelType + +class ModelTypeValidatorTest { + + @Test(expected = IllegalStateException::class) + @Throws(Exception::class) + fun testvalidateModelType() { + val modelType = ModelType() + modelType.definitionType = "" + modelType.derivedFrom = "" + modelType.description = "" + val definitionContent: JsonNode? = null + modelType.definition = definitionContent + modelType.modelName = "" + modelType.version = "" + modelType.tags = "" + modelType.updatedBy = "" + ModelTypeValidator.validateModelType(modelType) + } +} diff --git a/ms/controllerblueprints/modules/service/src/test/resources/logback.xml b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml index 2546a8389..e66127977 100644 --- a/ms/controllerblueprints/modules/service/src/test/resources/logback.xml +++ b/ms/controllerblueprints/modules/service/src/test/resources/logback.xml @@ -31,7 +31,7 @@ - + -- cgit 1.2.3-korg