Controller Blueprints Microservice
authorBrinda Santh <brindasanth@in.ibm.com>
Mon, 10 Sep 2018 02:00:59 +0000 (22:00 -0400)
committerBrinda Santh <brindasanth@in.ibm.com>
Mon, 10 Sep 2018 02:00:59 +0000 (22:00 -0400)
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 <brindasanth@in.ibm.com>
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java
ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java [new file with mode: 0644]
ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java

index 2bc2963..925a6c4 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * Modifications Copyright © 2018 IBM.\r
  *\r
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
@@ -16,6 +17,7 @@
 \r
 package org.onap.ccsdk.apps.controllerblueprints.service;\r
 \r
+import com.google.common.base.Preconditions;\r
 import org.apache.commons.lang3.StringUtils;\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType;\r
@@ -43,7 +45,7 @@ public class ModelTypeService {
     /**\r
      * This is a ModelTypeService, used to save and get the model types stored in database\r
      *\r
-     * @param modelTypeRepository\r
+     * @param modelTypeRepository modelTypeRepository\r
      */\r
     public ModelTypeService(ModelTypeRepository modelTypeRepository) {\r
         this.modelTypeRepository = modelTypeRepository;\r
@@ -53,19 +55,15 @@ public class ModelTypeService {
     /**\r
      * This is a getModelTypeByName service\r
      *\r
-     * @param modelTypeName\r
+     * @param modelTypeName modelTypeName\r
      * @return ModelType\r
-     * @throws BluePrintException\r
      */\r
-    public ModelType getModelTypeByName(String modelTypeName) throws BluePrintException {\r
+    public ModelType getModelTypeByName(String modelTypeName) {\r
         ModelType modelType = null;\r
-        if (StringUtils.isNotBlank(modelTypeName)) {\r
-            Optional<ModelType> modelTypeOption = modelTypeRepository.findByModelName(modelTypeName);\r
-            if (modelTypeOption.isPresent()) {\r
-                modelType = modelTypeOption.get();\r
-            }\r
-        } else {\r
-            throw new BluePrintException("Model Name Information is missing.");\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(modelTypeName), "Model Name Information is missing.");\r
+        Optional<ModelType> modelTypeOption = modelTypeRepository.findByModelName(modelTypeName);\r
+        if (modelTypeOption.isPresent()) {\r
+            modelType = modelTypeOption.get();\r
         }\r
         return modelType;\r
     }\r
@@ -74,27 +72,25 @@ public class ModelTypeService {
     /**\r
      * This is a searchModelTypes service\r
      *\r
-     * @param tags\r
+     * @param tags tags\r
      * @return List<ModelType>\r
-     * @throws BluePrintException\r
      */\r
-    public List<ModelType> searchModelTypes(String tags) throws BluePrintException {\r
-        if (tags != null) {\r
-            return modelTypeRepository.findByTagsContainingIgnoreCase(tags);\r
-        } else {\r
-            throw new BluePrintException("No Search Information provide");\r
-        }\r
+    public List<ModelType> searchModelTypes(String tags) {\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(tags), "No Search Information provide");\r
+        return modelTypeRepository.findByTagsContainingIgnoreCase(tags);\r
     }\r
 \r
     /**\r
      * This is a saveModel service\r
      *\r
-     * @param modelType\r
+     * @param modelType modelType\r
      * @return ModelType\r
-     * @throws BluePrintException\r
+     * @throws BluePrintException BluePrintException\r
      */\r
     public ModelType saveModel(ModelType modelType) throws BluePrintException {\r
 \r
+        Preconditions.checkNotNull(modelType, "Model Type Information is missing.");\r
+\r
         ModelTypeValidator.validateModelType(modelType);\r
 \r
         Optional<ModelType> dbModelType = modelTypeRepository.findByModelName(modelType.getModelName());\r
@@ -118,60 +114,34 @@ public class ModelTypeService {
     /**\r
      * This is a deleteByModelName service\r
      *\r
-     * @param modelName\r
-     * @throws BluePrintException\r
+     * @param modelName modelName\r
      */\r
-    public void deleteByModelName(String modelName) throws BluePrintException {\r
-        if (modelName != null) {\r
-            modelTypeRepository.deleteByModelName(modelName);\r
-        } else {\r
-            throw new BluePrintException("Model Name Information is missing.");\r
-        }\r
-    }\r
+    public void deleteByModelName(String modelName) {\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(modelName), "Model Name Information is missing.");\r
+        modelTypeRepository.deleteByModelName(modelName);\r
 \r
-    /**\r
-     * This is a getModelTypeByTags service\r
-     *\r
-     * @param tags\r
-     * @return List<ModelType>\r
-     * @throws BluePrintException\r
-     */\r
-    public List<ModelType> getModelTypeByTags(String tags) throws BluePrintException {\r
-        if (StringUtils.isNotBlank(tags)) {\r
-            return modelTypeRepository.findByTagsContainingIgnoreCase(tags);\r
-        } else {\r
-            throw new BluePrintException("Model Tag Information is missing.");\r
-        }\r
     }\r
 \r
     /**\r
      * This is a getModelTypeByDefinitionType service\r
      *\r
-     * @param definitionType\r
+     * @param definitionType definitionType\r
      * @return List<ModelType>\r
-     * @throws BluePrintException\r
      */\r
-    public List<ModelType> getModelTypeByDefinitionType(String definitionType) throws BluePrintException {\r
-        if (StringUtils.isNotBlank(definitionType)) {\r
-            return modelTypeRepository.findByDefinitionType(definitionType);\r
-        } else {\r
-            throw new BluePrintException("Model definitionType Information is missing.");\r
-        }\r
+    public List<ModelType> getModelTypeByDefinitionType(String definitionType) {\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(definitionType), "Model definitionType Information is missing.");\r
+        return modelTypeRepository.findByDefinitionType(definitionType);\r
     }\r
 \r
     /**\r
      * This is a getModelTypeByDerivedFrom service\r
      *\r
-     * @param derivedFrom\r
+     * @param derivedFrom derivedFrom\r
      * @return List<ModelType>\r
-     * @throws BluePrintException\r
      */\r
-    public List<ModelType> getModelTypeByDerivedFrom(String derivedFrom) throws BluePrintException {\r
-        if (StringUtils.isNotBlank(derivedFrom)) {\r
-            return modelTypeRepository.findByDerivedFrom(derivedFrom);\r
-        } else {\r
-            throw new BluePrintException("Model derivedFrom Information is missing.");\r
-        }\r
+    public List<ModelType> getModelTypeByDerivedFrom(String derivedFrom) {\r
+        Preconditions.checkArgument(StringUtils.isNotBlank(derivedFrom), "Model derivedFrom Information is missing.");\r
+        return modelTypeRepository.findByDerivedFrom(derivedFrom);\r
     }\r
 \r
 \r
index 16031b6..c53040e 100644 (file)
@@ -37,7 +37,7 @@ public interface ResourceDictionaryRepository extends JpaRepository<ResourceDict
     /**\r
      * This is a findByName method\r
      * \r
-     * @param name\r
+     * @param name name\r
      * @return Optional<ResourceMapping>\r
      */\r
     Optional<ResourceDictionary> findByName(String name);\r
@@ -45,7 +45,7 @@ public interface ResourceDictionaryRepository extends JpaRepository<ResourceDict
     /**\r
      * This is a findByNameIn method\r
      * \r
-     * @param names\r
+     * @param names names\r
      * @return Optional<ResourceMapping>\r
      */\r
     List<ResourceDictionary> findByNameIn(List<String> names);\r
@@ -53,7 +53,7 @@ public interface ResourceDictionaryRepository extends JpaRepository<ResourceDict
     /**\r
      * This is a findByTagsContainingIgnoreCase method\r
      * \r
-     * @param tags\r
+     * @param tags tags\r
      * @return Optional<ModelType>\r
      */\r
     List<ResourceDictionary> findByTagsContainingIgnoreCase(String tags);\r
@@ -61,9 +61,9 @@ public interface ResourceDictionaryRepository extends JpaRepository<ResourceDict
     /**\r
      * This is a deleteByName method\r
      * \r
-     * @param name\r
+     * @param name name\r
      */\r
-    ResourceDictionary deleteByName(String name);\r
+    void deleteByName(String name);\r
 \r
 \r
 }\r
diff --git a/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt
new file mode 100644 (file)
index 0000000..141ba92
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ *  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.onap.ccsdk.apps.controllerblueprints.service.domain.ModelType
+import org.springframework.stereotype.Service
+import reactor.core.publisher.Flux
+import reactor.core.publisher.Mono
+import reactor.core.scheduler.Schedulers
+
+/**
+ * ModelTypeReactRepository.
+ *
+ * @author Brinda Santh
+ */
+@Service
+open class ModelTypeReactRepository(private val modelTypeRepository: ModelTypeRepository) {
+
+    fun save(modelType: ModelType): Mono<ModelType> {
+        return Mono.justOrEmpty(modelTypeRepository.save(modelType))
+    }
+
+    fun findByModelName(modelName: String): Mono<ModelType> {
+        return Mono.justOrEmpty(modelTypeRepository.findByModelName(modelName))
+    }
+
+    fun findByModelNameIn(modelNames: List<String>): Flux<ModelType> {
+        return Flux.fromIterable(modelTypeRepository.findByModelNameIn(modelNames))
+                .subscribeOn(Schedulers.elastic())
+    }
+
+    fun findByDerivedFrom(derivedFrom: String): Flux<ModelType> {
+        return Flux.fromIterable(modelTypeRepository.findByDerivedFrom(derivedFrom))
+                .subscribeOn(Schedulers.elastic())
+    }
+
+    fun findByDerivedFromIn(derivedFroms: List<String>): Flux<ModelType> {
+        return Flux.fromIterable(modelTypeRepository.findByDerivedFromIn(derivedFroms))
+                .subscribeOn(Schedulers.elastic())
+    }
+
+    fun findByDefinitionType(definitionType: String): Flux<ModelType> {
+        return Flux.fromIterable(modelTypeRepository.findByDefinitionType(definitionType))
+                .subscribeOn(Schedulers.elastic())
+    }
+
+    fun findByDefinitionTypeIn(definitionTypes: List<String>): Flux<ModelType> {
+        return Flux.fromIterable(modelTypeRepository.findByDefinitionTypeIn(definitionTypes))
+                .subscribeOn(Schedulers.elastic())
+    }
+
+    fun findByTagsContainingIgnoreCase(tags: String): Flux<ModelType> {
+        return Flux.fromIterable(modelTypeRepository.findByTagsContainingIgnoreCase(tags))
+                .subscribeOn(Schedulers.elastic())
+    }
+
+    fun deleteByModelName(modelName: String): Mono<Void> {
+        modelTypeRepository.deleteByModelName(modelName)
+        return Mono.empty()
+    }
+
+}
\ No newline at end of file
index 064b5c3..0865b69 100644 (file)
@@ -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<ResourceDictionary> {
-        return Mono.fromCallable {
-            resourceDictionaryRepository.deleteByName(name)
-        }
+    fun deleteByName(name: String): Mono<Void> {
+        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 (file)
index 0000000..8e258ab
--- /dev/null
@@ -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<ModelType> 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<ModelType> 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<ModelType> 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 (file)
index 0000000..7549b78
--- /dev/null
@@ -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<ModelType> 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<ModelType> 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<ModelType> 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<ModelType> 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<ModelType> 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();
+    }
+
+}
index 7034b7e..ab939ff 100644 (file)
@@ -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<ResourceDictionary> 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<ResourceDictionary> 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());