From 812bd02e844b4a518e5f02506b8fd7cb3a306636 Mon Sep 17 00:00:00 2001 From: Brinda Santh Date: Sun, 9 Sep 2018 22:00:59 -0400 Subject: Controller Blueprints Microservice Add ModelType and Resource Dictionary reactor repository service and junit test cases for reactor repositories. Change-Id: Id358082739f81d18b534c224dc7472355e21f026 Issue-ID: CCSDK-491 Signed-off-by: Brinda Santh --- .../service/ModelTypeService.java | 88 +++++---------- .../repository/ResourceDictionaryRepository.java | 10 +- .../repository/BluePrintsReactRepository.kt | 76 +++++++++++++ .../ResourceDictionaryReactRepository.kt | 8 +- .../service/ModelTypeServiceTest.java | 123 +++++++++++++++++++++ .../repository/ModelTypeReactRepositoryTest.java | 110 ++++++++++++++++++ .../ResourceDictionaryReactRepositoryTest.java | 30 +++-- 7 files changed, 367 insertions(+), 78 deletions(-) create mode 100644 ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java create mode 100644 ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java (limited to 'ms/controllerblueprints') diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java index 2bc2963b..925a6c49 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java @@ -1,5 +1,6 @@ /* * 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. @@ -16,6 +17,7 @@ package org.onap.ccsdk.apps.controllerblueprints.service; +import com.google.common.base.Preconditions; import org.apache.commons.lang3.StringUtils; import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException; import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType; @@ -43,7 +45,7 @@ public class ModelTypeService { /** * This is a ModelTypeService, used to save and get the model types stored in database * - * @param modelTypeRepository + * @param modelTypeRepository modelTypeRepository */ public ModelTypeService(ModelTypeRepository modelTypeRepository) { this.modelTypeRepository = modelTypeRepository; @@ -53,19 +55,15 @@ public class ModelTypeService { /** * This is a getModelTypeByName service * - * @param modelTypeName + * @param modelTypeName modelTypeName * @return ModelType - * @throws BluePrintException */ - public ModelType getModelTypeByName(String modelTypeName) throws BluePrintException { + public ModelType getModelTypeByName(String modelTypeName) { ModelType modelType = null; - if (StringUtils.isNotBlank(modelTypeName)) { - Optional modelTypeOption = modelTypeRepository.findByModelName(modelTypeName); - if (modelTypeOption.isPresent()) { - modelType = modelTypeOption.get(); - } - } else { - throw new BluePrintException("Model Name Information is missing."); + Preconditions.checkArgument(StringUtils.isNotBlank(modelTypeName), "Model Name Information is missing."); + Optional modelTypeOption = modelTypeRepository.findByModelName(modelTypeName); + if (modelTypeOption.isPresent()) { + modelType = modelTypeOption.get(); } return modelType; } @@ -74,27 +72,25 @@ public class ModelTypeService { /** * This is a searchModelTypes service * - * @param tags + * @param tags tags * @return List - * @throws BluePrintException */ - public List searchModelTypes(String tags) throws BluePrintException { - if (tags != null) { - return modelTypeRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("No Search Information provide"); - } + public List searchModelTypes(String tags) { + Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No Search Information provide"); + return modelTypeRepository.findByTagsContainingIgnoreCase(tags); } /** * This is a saveModel service * - * @param modelType + * @param modelType modelType * @return ModelType - * @throws BluePrintException + * @throws BluePrintException BluePrintException */ public ModelType saveModel(ModelType modelType) throws BluePrintException { + Preconditions.checkNotNull(modelType, "Model Type Information is missing."); + ModelTypeValidator.validateModelType(modelType); Optional dbModelType = modelTypeRepository.findByModelName(modelType.getModelName()); @@ -118,60 +114,34 @@ public class ModelTypeService { /** * This is a deleteByModelName service * - * @param modelName - * @throws BluePrintException + * @param modelName modelName */ - public void deleteByModelName(String modelName) throws BluePrintException { - if (modelName != null) { - modelTypeRepository.deleteByModelName(modelName); - } else { - throw new BluePrintException("Model Name Information is missing."); - } - } + public void deleteByModelName(String modelName) { + Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Model Name Information is missing."); + modelTypeRepository.deleteByModelName(modelName); - /** - * This is a getModelTypeByTags service - * - * @param tags - * @return List - * @throws BluePrintException - */ - public List getModelTypeByTags(String tags) throws BluePrintException { - if (StringUtils.isNotBlank(tags)) { - return modelTypeRepository.findByTagsContainingIgnoreCase(tags); - } else { - throw new BluePrintException("Model Tag Information is missing."); - } } /** * This is a getModelTypeByDefinitionType service * - * @param definitionType + * @param definitionType definitionType * @return List - * @throws BluePrintException */ - public List getModelTypeByDefinitionType(String definitionType) throws BluePrintException { - if (StringUtils.isNotBlank(definitionType)) { - return modelTypeRepository.findByDefinitionType(definitionType); - } else { - throw new BluePrintException("Model definitionType Information is missing."); - } + public List getModelTypeByDefinitionType(String definitionType) { + Preconditions.checkArgument(StringUtils.isNotBlank(definitionType), "Model definitionType Information is missing."); + return modelTypeRepository.findByDefinitionType(definitionType); } /** * This is a getModelTypeByDerivedFrom service * - * @param derivedFrom + * @param derivedFrom derivedFrom * @return List - * @throws BluePrintException */ - public List getModelTypeByDerivedFrom(String derivedFrom) throws BluePrintException { - if (StringUtils.isNotBlank(derivedFrom)) { - return modelTypeRepository.findByDerivedFrom(derivedFrom); - } else { - throw new BluePrintException("Model derivedFrom Information is missing."); - } + public List getModelTypeByDerivedFrom(String derivedFrom) { + Preconditions.checkArgument(StringUtils.isNotBlank(derivedFrom), "Model derivedFrom Information is missing."); + return modelTypeRepository.findByDerivedFrom(derivedFrom); } diff --git a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java index 16031b6e..c53040e2 100644 --- a/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java +++ b/ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java @@ -37,7 +37,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ Optional findByName(String name); @@ -45,7 +45,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ List findByNameIn(List names); @@ -53,7 +53,7 @@ public interface ResourceDictionaryRepository extends JpaRepository */ List findByTagsContainingIgnoreCase(String tags); @@ -61,9 +61,9 @@ public interface ResourceDictionaryRepository extends JpaRepository { + return Mono.justOrEmpty(modelTypeRepository.save(modelType)) + } + + fun findByModelName(modelName: String): Mono { + return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName)) + } + + fun findByModelNameIn(modelNames: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDerivedFrom(derivedFrom: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDerivedFromIn(derivedFroms: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDefinitionType(definitionType: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByDefinitionTypeIn(definitionTypes: List): Flux { + return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes)) + .subscribeOn(Schedulers.elastic()) + } + + fun findByTagsContainingIgnoreCase(tags: String): Flux { + return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags)) + .subscribeOn(Schedulers.elastic()) + } + + fun deleteByModelName(modelName: String): Mono { + modelTypeRepository.deleteByModelName(modelName) + return Mono.empty() + } + +} \ No newline at end of file diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt index 064b5c38..0865b69d 100644 --- a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt +++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt @@ -16,7 +16,6 @@ package org.onap.ccsdk.apps.controllerblueprints.service.repository -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary import org.springframework.stereotype.Service import reactor.core.publisher.Flux @@ -49,10 +48,9 @@ open class ResourceDictionaryReactRepository(private val resourceDictionaryRepos .subscribeOn(Schedulers.elastic()) } - fun deleteByName(name: String): Mono { - return Mono.fromCallable { - resourceDictionaryRepository.deleteByName(name) - } + fun deleteByName(name: String): Mono { + resourceDictionaryRepository.deleteByName(name) + return Mono.empty() } } \ 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 new file mode 100644 index 00000000..8e258ab6 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java @@ -0,0 +1,123 @@ +/* + * 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.*; +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.rs.ModelTypeRestTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +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(ModelTypeRestTest.class); + @Autowired + ModelTypeService modelTypeService; + + String modelName = "test-datatype"; + + @Test + public void test01SaveModelType() throws Exception { + log.info("**************** test01SaveModelType ********************"); + + String content = JacksonUtils.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.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 = modelTypeService.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 = modelTypeService.getModelTypeByName(modelType.getModelName()); + Assert.assertNotNull("Failed to query ResourceMapping for ID (" + dbModelType.getModelName() + ")", + dbModelType); + + // Model Update + modelType.setUpdatedBy("bs2796@xxx.com"); + modelType = modelTypeService.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 = modelTypeService.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 = modelTypeService.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 = + modelTypeService.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 = + modelTypeService.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 = modelTypeService.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()); + + modelTypeService.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/repository/ModelTypeReactRepositoryTest.java b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java new file mode 100644 index 00000000..7549b780 --- /dev/null +++ b/ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/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.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.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.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 index 7034b7e2..ab939ffa 100644 --- 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 @@ -28,6 +28,7 @@ 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; @@ -46,39 +47,50 @@ import java.util.List; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ResourceDictionaryReactRepositoryTest { + private String sourceName = "test-source"; + @Autowired protected ResourceDictionaryReactRepository resourceDictionaryReactRepository; - @Before - public void init() { + @Test + @Commit + public void test01Save() { ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile("./../../application/load/resource_dictionary/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 query React Resource Dictionary by Name", dbResourceDictionary); + Assert.assertNotNull("Failed to save ResourceDictionary", dbResourceDictionary); } @Test - public void test01FindByNameReact() throws Exception { - ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName("db-source").block(); + public void test02FindByNameReact() { + ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName(sourceName).block(); Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary); } @Test - public void test02FindByNameInReact() throws Exception { + public void test03FindByNameInReact() { List dbResourceDictionaries = - resourceDictionaryReactRepository.findByNameIn(Arrays.asList("db-source")).collectList().block(); + resourceDictionaryReactRepository.findByNameIn(Arrays.asList(sourceName)).collectList().block(); Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries); } @Test - public void test03FindByTagsContainingIgnoreCaseReact() throws Exception { + public void test04FindByTagsContainingIgnoreCaseReact() { List dbTagsResourceDictionaries = - resourceDictionaryReactRepository.findByTagsContainingIgnoreCase("db-source").collectList().block(); + resourceDictionaryReactRepository.findByTagsContainingIgnoreCase(sourceName).collectList().block(); Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries); } + @Test + @Commit + public void test05Delete() { + resourceDictionaryReactRepository.deleteByName("db-source").block(); + } + private ResourceDictionary transformResourceDictionary(ResourceDefinition resourceDefinition) { ResourceDictionary resourceDictionary = new ResourceDictionary(); resourceDictionary.setName(resourceDefinition.getName()); -- cgit 1.2.3-korg