From b35d55e3f57630551f0b773674bd1f5c44585ede Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Thu, 9 Aug 2018 20:47:29 +0000 Subject: Controller Blueprints MS Creating the base directory structure for Controller Blueprints MicroService Change-Id: I1ccf7fc76446048af3b2822f9155bb634657aee3 Issue-ID: CCSDK-410 Signed-off-by: Singal, Kapil (ks220y) --- .../apps/controllerblueprints/DatabaseConfig.java | 61 ++++++++ .../controllerblueprints/JerseyConfiguration.java | 69 +++++++++ .../apps/controllerblueprints/TestApplication.java | 34 ++++ .../controllerblueprints/TestConfiguration.java | 36 +++++ .../service/common/SchemaGeneratorServiceTest.java | 50 ++++++ .../common/ServiceTemplateValidationTest.java | 56 +++++++ .../service/rs/ConfigModelRestTest.java | 172 +++++++++++++++++++++ .../service/rs/ModelTypeRestTest.java | 130 ++++++++++++++++ .../service/rs/ResourceDictionaryRestTest.java | 113 ++++++++++++++ .../service/rs/ServiceTemplateRestTest.java | 155 +++++++++++++++++++ .../service/utils/ConfigModelUtilsTest.java | 33 ++++ 11 files changed, 909 insertions(+) create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/DatabaseConfig.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestApplication.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/SchemaGeneratorServiceTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java (limited to 'ms/controllerblueprints/modules/service/src/test/java/org/onap') 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 new file mode 100644 index 000000000..db35fe661 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/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.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/JerseyConfiguration.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java new file mode 100644 index 000000000..f5535eb12 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/JerseyConfiguration.java @@ -0,0 +1,69 @@ +/* + * 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 com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import org.glassfish.jersey.logging.LoggingFeature; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.servlet.ServletProperties; +import org.onap.ccsdk.apps.controllerblueprints.service.common.ServiceExceptionMapper; +import org.onap.ccsdk.apps.controllerblueprints.service.rs.ConfigModelRestImpl; +import org.onap.ccsdk.apps.controllerblueprints.service.rs.ModelTypeRestImpl; +import org.onap.ccsdk.apps.controllerblueprints.service.rs.ResourceDictionaryRestImpl; +import org.onap.ccsdk.apps.controllerblueprints.service.rs.ServiceTemplateRestImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +import java.util.logging.Logger; + + +@Component +public class JerseyConfiguration extends ResourceConfig { + private static final Logger log = Logger.getLogger(JerseyConfiguration.class.getName()); + + @Bean + @Primary + public ObjectMapper objectMapper() { + ObjectMapper objectMapper = new ObjectMapper(); + objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); + objectMapper.enable(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES); + objectMapper.enable(DeserializationFeature.READ_ENUMS_USING_TO_STRING); + objectMapper.enable(SerializationFeature.WRITE_ENUMS_USING_TO_STRING); + return objectMapper; + } + + @Autowired + public JerseyConfiguration() { + register(ConfigModelRestImpl.class); + register(ModelTypeRestImpl.class); + register(ResourceDictionaryRestImpl.class); + register(ServiceTemplateRestImpl.class); + // Exception Mapping + register(ServiceExceptionMapper.class); + property(ServletProperties.FILTER_FORWARD_ON_404, true); + register(new LoggingFeature(log)); + } + + +} \ No newline at end of file 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 new file mode 100644 index 000000000..537429f0b --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/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.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/TestConfiguration.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.java new file mode 100644 index 000000000..ea259c9c9 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/TestConfiguration.java @@ -0,0 +1,36 @@ +/* + * 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.context.annotation.Bean; + +import java.util.ArrayList; + +//@Configuration +public class TestConfiguration { + + @Bean("jaxrsProviders") + public ArrayList provider() { + return new ArrayList(); + } + + @Bean("jaxrsServices") + public ArrayList service() { + return new ArrayList(); + } + +} 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 new file mode 100644 index 000000000..50e94df9e --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/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.apps.controllerblueprints.service.common; + +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 org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.nio.charset.Charset; + + +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class SchemaGeneratorServiceTest { + + private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.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/common/ServiceTemplateValidationTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java new file mode 100644 index 000000000..af309e217 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/common/ServiceTemplateValidationTest.java @@ -0,0 +1,56 @@ +/* + * 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 org.apache.commons.io.IOUtils; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; +import org.onap.ccsdk.apps.controllerblueprints.service.validator.ServiceTemplateValidator; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.nio.charset.Charset; +import java.util.List; + +public class ServiceTemplateValidationTest { + private static Logger log = LoggerFactory.getLogger(ServiceTemplateValidationTest.class); + + @Test + public void testBluePrintDirs(){ + List dirs = ConfigModelUtils.getBlueprintNames("load/blueprints"); + Assert.assertNotNull("Failed to get blueprint directories", dirs ); + Assert.assertEquals("Failed to get actual directories",2, dirs.size() ); + } + + // @Test + public void validateServiceTemplate() { + try { + String file = "load/service_template/vrr-201806-test/service-template.json"; + String serviceTemplateContent = + IOUtils.toString(ServiceTemplateValidationTest.class.getClassLoader().getResourceAsStream(file), + Charset.defaultCharset()); + ServiceTemplateValidator serviceTemplateValidator = new ServiceTemplateValidator(); + serviceTemplateValidator.validateServiceTemplate(serviceTemplateContent); + log.info("Validated Service Template " + serviceTemplateValidator.getMetaData()); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java new file mode 100644 index 000000000..5b10a7e86 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ConfigModelRestTest.java @@ -0,0 +1,172 @@ +/* + * 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.rs; + +import org.junit.*; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.apps.controllerblueprints.TestApplication; +import org.onap.ccsdk.apps.controllerblueprints.TestConfiguration; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; +import org.onap.ccsdk.apps.controllerblueprints.service.utils.ConfigModelUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ConfigModelRestTest { + + private static Logger log = LoggerFactory.getLogger(ConfigModelRestTest.class); + + @Autowired + ConfigModelRest configModelRest; + + ConfigModel configModel; + + String name = "vrr-test"; + String version = "1.0.0"; + + @Before + public void setUp() { + + } + + + @After + public void tearDown() { + } + + + @Test + public void test01getInitialConfigModel() throws Exception { + log.info("** test01getInitialConfigModel *****************"); + + String name = "default_netconf"; + ConfigModel configModel = configModelRest.getInitialConfigModel(name); + Assert.assertNotNull("Failed to get Initial Config Model , Return object is Null", configModel); + Assert.assertNotNull("Failed to get Service Template Content ", configModel.getConfigModelContents()); + + } + + + @Test + public void test02SaveServiceTemplate() throws Exception { + log.info("************************ test02SaveServiceTemplate ******************"); + + + configModel = ConfigModelUtils.getConfigModel("load/blueprints/vrr-test"); + + configModel = configModelRest.saveConfigModel(configModel); + Assert.assertNotNull("Failed to ConfigModel, Return object is Null", configModel); + Assert.assertNotNull("Failed to ConfigModel Id , Return ID object is Null", configModel.getId()); + Assert.assertNotNull("Failed to ConfigModel Content, Return object is Null", + configModel.getConfigModelContents()); + Assert.assertEquals("Failed in validation of ConfigModel Content count,", 3, + configModel.getConfigModelContents().size()); + + ConfigModel dbconfigModel = configModelRest.getConfigModel(configModel.getId()); + + log.info("************************ test02SaveServiceTemplate-2 ******************"); + + dbconfigModel.getConfigModelContents().remove(2); + dbconfigModel = configModelRest.saveConfigModel(dbconfigModel); + log.info("Saved Config Model " + configModel.getId()); + Assert.assertNotNull("Failed to ConfigModel, Return object is Null", dbconfigModel); + Assert.assertNotNull("Failed to ConfigModel Id ", dbconfigModel.getId()); + Assert.assertNotNull("Failed to ConfigModel Content", + dbconfigModel.getConfigModelContents()); + Assert.assertEquals("Failed to Remove the ConfigModel Content,", 2, + dbconfigModel.getConfigModelContents().size()); + + + } + + + @Test + public void test03PublishServiceTemplate() throws Exception { + log.info("** test03PublishServiceTemplate *****************"); + + ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); + log.info("Publishing Config Model " + configModel.getId()); + configModel = configModelRest.publishConfigModel(configModel.getId()); + Assert.assertNotNull("Failed to ConfigModel, Return object is Null", configModel); + Assert.assertNotNull("Failed to ConfigModel Id ", configModel.getId()); + Assert.assertNotNull("Failed to ConfigModel Content", configModel.getConfigModelContents()); + Assert.assertEquals("Failed to update the publish indicator", "Y", configModel.getPublished()); + } + + + @Test + public void test04GetConfigModel() throws Exception { + log.info("** test04GetConfigModel *****************"); + + ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); + Assert.assertNotNull("Failed to get ConfigModel for the Name (" + configModel.getArtifactName() + ") and (" + + configModel.getArtifactVersion() + ")", configModel); + Assert.assertNotNull("Failed to get ConfigModel Id", configModel.getId()); + + configModel = configModelRest.getConfigModel(configModel.getId()); + Assert.assertNotNull("Failed to get ConfigModel for the Id (" + configModel.getId() + ") ", configModel); + + } + + @Test + public void test05GetCloneConfigModel() throws Exception { + log.info("** test05GetCloneConfigModel *****************"); + + ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); + + Assert.assertNotNull("Failed to get ConfigModel for the Name (" + configModel.getArtifactName() + ") and (" + + configModel.getArtifactVersion() + ")", configModel); + Assert.assertNotNull("Failed to get ConfigModel Id", configModel.getId()); + + configModel = configModelRest.getCloneConfigModel(configModel.getId()); + Assert.assertNotNull("Failed to get ConfigModel for the Id (" + configModel.getId() + ") ", configModel); + } + + + @Test + public void test07SearchConfigModels() throws Exception { + log.info("** test07SearchConfigModels *****************"); + + List configModels = configModelRest.searchConfigModels("vrr-test"); + Assert.assertNotNull("Failed to search ConfigModel", configModels); + Assert.assertTrue("Failed to search ConfigModel with count", configModels.size() > 0); + // update the ServiceModelContent + } + + + @Test + public void test08DeleteConfigModels() throws Exception { + log.info("** test08DeleteConfigModels *****************"); + + ConfigModel configModel = configModelRest.getConfigModelByNameAndVersion(name, version); + configModelRest.deleteConfigModel(configModel.getId()); + + } + + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java new file mode 100644 index 000000000..d33349c53 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ModelTypeRestTest.java @@ -0,0 +1,130 @@ +/* + * 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.rs; + +import org.apache.commons.io.FileUtils; +import org.junit.*; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.onap.ccsdk.apps.controllerblueprints.TestApplication; +import org.onap.ccsdk.apps.controllerblueprints.TestConfiguration; +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.List; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ModelTypeRestTest { + private static Logger log = LoggerFactory.getLogger(ModelTypeRestTest.class); + @Autowired + ModelTypeRest modelTypeRest; + + String modelName = "test-datatype"; + + @Before + public void setUp() { + + } + + + @After + public void tearDown() {} + + @Test + public void test01SaveModelType() throws Exception { + log.info( "**************** test01SaveModelType ********************"); + + String content = FileUtils.readFileToString(new File("load/model_type/data_type/datatype-property.json"), Charset.defaultCharset()); + 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(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 = modelTypeRest.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.getModelName()); + + ModelType dbModelType = modelTypeRest.getModelTypeByName(modelType.getModelName()); + Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")", + dbModelType); + + // Model Update + modelType.setUpdatedBy("bs2796@xxx.com"); + modelType = modelTypeRest.saveModelType(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 = modelTypeRest.searchModelTypes(tags); + Assert.assertNotNull("Failed to search ResourceMapping by tags", dbModelTypes); + Assert.assertEquals("Failed to search ResourceMapping by tags count", true, dbModelTypes.size() > 0); + + } + + @Test + public void test03GetModelType() throws Exception { + log.info( "************************* test03GetModelType *********************************"); + ModelType dbModelType = modelTypeRest.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 = + modelTypeRest.getModelTypeByDefinitionType(BluePrintConstants.MODEL_DEFINITION_TYPE_DATA_TYPE); + Assert.assertNotNull("Failed to find getModelTypeByDefinitionType by tags", dbDatatypeModelTypes); + Assert.assertEquals("Failed to find getModelTypeByDefinitionType by count", true, + dbDatatypeModelTypes.size() > 0); + } + + @Test + public void test04DeleteModelType() throws Exception { + log.info( + "************************ test03DeleteModelType ***********************"); + ModelType dbResourceMapping = modelTypeRest.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()); + + modelTypeRest.deleteModelTypeByName(dbResourceMapping.getModelName()); + } + + + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java new file mode 100644 index 000000000..71dff338b --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ResourceDictionaryRestTest.java @@ -0,0 +1,113 @@ +/* + * 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.rs; + +import org.apache.commons.io.IOUtils; +import org.junit.Assert; +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.TestConfiguration; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.List; + + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ResourceDictionaryRestTest { + + private static Logger log = LoggerFactory.getLogger(ResourceDictionaryRestTest.class); + + @Autowired + protected ResourceDictionaryRest resourceDictionaryRest; + + @Before + public void setUp() { + + } + + @Test + public void test01SaveDataDictionary() throws Exception { + String definition = IOUtils.toString( + getClass().getClassLoader().getResourceAsStream("resourcedictionary/default_definition.json"), + Charset.defaultCharset()); + + ResourceDictionary dataDictionary = new ResourceDictionary(); + dataDictionary.setResourcePath("test/vnf/ipaddress"); + dataDictionary.setName("test-name"); + dataDictionary.setDefinition(definition); + dataDictionary.setValidValues("127.0.0.1"); + dataDictionary.setResourceType("ONAP"); + dataDictionary.setDataType("string"); + dataDictionary.setDescription("Sample Resource Mapping"); + dataDictionary.setTags("test, ipaddress"); + dataDictionary.setUpdatedBy("xxxxxx@xxx.com"); + + dataDictionary = resourceDictionaryRest.saveResourceDictionary(dataDictionary); + + Assert.assertNotNull("Failed to get Saved Resource Dictionary", dataDictionary); + Assert.assertNotNull("Failed to get Saved Resource Dictionary, Id", dataDictionary.getName()); + + ResourceDictionary dbDataDictionary = + resourceDictionaryRest.getResourceDictionaryByName(dataDictionary.getName()); + Assert.assertNotNull("Failed to query Resource Dictionary for ID (" + dataDictionary.getName() + ")", + dbDataDictionary); + Assert.assertNotNull("Failed to query Resource Dictionary definition for ID (" + dataDictionary.getName() + ")", + dbDataDictionary.getDefinition()); + + log.trace("Saved Dictionary " + dbDataDictionary.getDefinition()); + + } + + @Test + public void test02GetDataDictionary() throws Exception { + + ResourceDictionary dbResourceDictionary = resourceDictionaryRest.getResourceDictionaryByName("test-name"); + Assert.assertNotNull("Failed to query Resource Dictionary by Name", dbResourceDictionary); + + String tags = "ipaddress"; + + List dbResourceDictionaries = resourceDictionaryRest.searchResourceDictionaryByTags(tags); + Assert.assertNotNull("Failed to search ResourceDictionary by tags", dbResourceDictionaries); + Assert.assertTrue("Failed to search searchResourceDictionaryByTags by tags by count", + dbResourceDictionaries.size() > 0); + + List names = new ArrayList<>(); + names.add("test-name"); + dbResourceDictionaries = resourceDictionaryRest.searchResourceDictionaryByNames(names); + Assert.assertNotNull("Failed to search ResourceDictionary by Names", dbResourceDictionaries); + Assert.assertTrue("Failed to search searchResourceDictionaryByNames by tags by count", + dbResourceDictionaries.size() > 0); + + } + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java new file mode 100644 index 000000000..f81dd4165 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/rs/ServiceTemplateRestTest.java @@ -0,0 +1,155 @@ +/* + * 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.rs; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.io.FileUtils; +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.TestConfiguration; +import org.onap.ccsdk.apps.controllerblueprints.core.ConfigModelConstant; +import org.onap.ccsdk.apps.controllerblueprints.core.data.ServiceTemplate; +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModelContent; +import org.onap.ccsdk.apps.controllerblueprints.service.model.AutoMapResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.List; + + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ContextConfiguration(classes = {TestApplication.class, TestConfiguration.class}) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +public class ServiceTemplateRestTest { + + private static Logger log = LoggerFactory.getLogger(ServiceTemplateRestTest.class); + @Autowired + ModelTypeRest modelTypeRest; + + @Autowired + private ServiceTemplateRest serviceTemplateRest; + + @Test + public void test02EnrichServiceTemplate() throws Exception { + log.info("*********** test02EnrichServiceTemplate ***********************"); + String file = "src/test/resources/enhance/enhance-template.json"; + + String serviceTemplateContent = FileUtils.readFileToString(new File(file), Charset.defaultCharset()); + + ServiceTemplate serviceTemplate = JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); + + serviceTemplate = serviceTemplateRest.enrichServiceTemplate(serviceTemplate); + + String enhancedFile = "src/test/resources/enhance/enhanced-template.json"; + + FileUtils.write(new File(enhancedFile), + JacksonUtils.getJson(serviceTemplate, true), Charset.defaultCharset()); + + Assert.assertNotNull("Failed to get Enriched Blueprints, Return object is Null", serviceTemplate); + Assert.assertNotNull("Failed to get Enriched Blueprints Data Type, Return object is Null", + serviceTemplate.getDataTypes()); + Assert.assertNotNull("Failed to get Enriched Blueprints Node Type, Return object is Null", + serviceTemplate.getNodeTypes()); + log.trace("Enriched Service Template :\n" + JacksonUtils.getJson(serviceTemplate, true)); + } + + @Test + public void test03ValidateServiceTemplate() throws Exception { + log.info("*********** test03ValidateServiceTemplate *******************************************"); + String enhancedFile = "src/test/resources/enhance/enhanced-template.json"; + String serviceTemplateContent = FileUtils.readFileToString(new File(enhancedFile), Charset.defaultCharset()); + + ServiceTemplate serviceTemplate = + JacksonUtils.readValue(serviceTemplateContent, ServiceTemplate.class); + + serviceTemplate = serviceTemplateRest.validateServiceTemplate(serviceTemplate); + + Assert.assertNotNull("Failed to validate Service Template, Return object is Null", serviceTemplate); + Assert.assertNotNull("Failed to get Service Template Data Type, Return object is Null", + serviceTemplate.getDataTypes()); + Assert.assertNotNull("Failed to get Service Template Node Type, Return object is Null", + serviceTemplate.getNodeTypes()); + + log.trace("Validated Service Template :\n" + JacksonUtils.getJson(serviceTemplate, true)); + + } + + + @Test + public void test04GenerateResourceAssignments() throws Exception { + log.info("*********** test04GenerateResourceAssignments *******************************************"); + ConfigModelContent baseConfigConfigModelContent = new ConfigModelContent(); + String baseConfigContent = FileUtils.readFileToString(new File("load/blueprints/vrr-test/Templates/base-config-template.vtl") + , Charset.defaultCharset()); + baseConfigConfigModelContent.setName("base-config-template"); + baseConfigConfigModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE); + baseConfigConfigModelContent.setContent(baseConfigContent); + + List resourceAssignments = + serviceTemplateRest.generateResourceAssignments(baseConfigConfigModelContent); + + Assert.assertNotNull("Failed to get ResourceAssignments, Return object is Null", resourceAssignments); + Assert.assertTrue("Failed to get ResourceAssignments count", resourceAssignments.size() > 0); + + log.trace("Validated Service Template :\n" + JacksonUtils.getJson(resourceAssignments, true)); + + + } + + @Test + public void test05AutoMap() throws Exception { + log.info("*********** test05AutoMap *******************************************"); + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/resourcedictionary/automap.json"), Charset.defaultCharset()); + List batchResourceAssignment = + JacksonUtils.getListFromJson(resourceassignmentContent, ResourceAssignment.class); + AutoMapResponse autoMapResponse = serviceTemplateRest.autoMap(batchResourceAssignment); + + Assert.assertNotNull("Failed to get ResourceAssignments, Return object is Null", + autoMapResponse.getResourceAssignments()); + Assert.assertNotNull("Failed to get Data Dictionary from ResourceAssignments", + autoMapResponse.getDataDictionaries()); + Assert.assertTrue("Failed to get ResourceAssignments count", + CollectionUtils.isNotEmpty(autoMapResponse.getDataDictionaries())); + + List autoMappedResourceAssignment = autoMapResponse.getResourceAssignments(); + autoMappedResourceAssignment.forEach(resourceAssignment -> { + if ("bundle-id".equals(resourceAssignment.getName())) { + Assert.assertEquals("Failed to assign default first source", "db", + resourceAssignment.getDictionarySource()); + } + }); + + } + + +} diff --git a/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java new file mode 100644 index 000000000..b38dd6de1 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/utils/ConfigModelUtilsTest.java @@ -0,0 +1,33 @@ +/* + * 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.utils; + +import org.apache.commons.collections.CollectionUtils; +import org.junit.Assert; +import org.junit.Test; +import org.onap.ccsdk.apps.controllerblueprints.service.domain.ConfigModel; + +public class ConfigModelUtilsTest { + + @Test + public void testConfigModel() throws Exception { + + ConfigModel configModel = ConfigModelUtils.getConfigModel("load/blueprints/vrr-test"); + Assert.assertNotNull("Failed to prepare config model", configModel); + Assert.assertTrue("Failed to prepare config model contents", CollectionUtils.isNotEmpty(configModel.getConfigModelContents())); + } +} -- cgit 1.2.3-korg