aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrinda Santh <brindasanth@in.ibm.com>2018-09-09 22:00:59 -0400
committerBrinda Santh <brindasanth@in.ibm.com>2018-09-09 22:00:59 -0400
commit812bd02e844b4a518e5f02506b8fd7cb3a306636 (patch)
tree3acb9f3a4273672ac62dff9bfa9bd1a3bb4f25c0
parent7326444cb71223a3d57c5441efe86dde08bb1b9a (diff)
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 <brindasanth@in.ibm.com>
-rw-r--r--components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt4
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeService.java88
-rw-r--r--ms/controllerblueprints/modules/service/src/main/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryRepository.java10
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt76
-rw-r--r--ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepository.kt8
-rw-r--r--ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/ModelTypeServiceTest.java123
-rw-r--r--ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ModelTypeReactRepositoryTest.java110
-rw-r--r--ms/controllerblueprints/modules/service/src/test/java/org/onap/ccsdk/apps/controllerblueprints/service/repository/ResourceDictionaryReactRepositoryTest.java30
8 files changed, 368 insertions, 81 deletions
diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt
index 228b39e2..fae509d2 100644
--- a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt
+++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceAssignmentValidationService.kt
@@ -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.
@@ -87,9 +88,6 @@ open class ResourceAssignmentValidationDefaultService : ResourceAssignmentValida
val dependenciesNames = resourceAssignments.mapNotNull { it.dependencies }.flatten()
- log.info("Resource assignment definitions : {}", resourceAssignmentMap.keys)
- log.info("Resource assignment Dictionary dependencies : {}", dependenciesNames)
-
val notPresentDictionaries = dependenciesNames.filter { !resourceAssignmentMap.containsKey(it) }.distinct()
if (notPresentDictionaries.isNotEmpty()) {
validationMessage.appendln(String.format("No assignments for Dictionary Keys (%s)", notPresentDictionaries))
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<ModelType> 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<ModelType> 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<ModelType>
- * @throws BluePrintException
*/
- public List<ModelType> searchModelTypes(String tags) throws BluePrintException {
- if (tags != null) {
- return modelTypeRepository.findByTagsContainingIgnoreCase(tags);
- } else {
- throw new BluePrintException("No Search Information provide");
- }
+ public List<ModelType> 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<ModelType> 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<ModelType>
- * @throws BluePrintException
- */
- public List<ModelType> 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<ModelType>
- * @throws BluePrintException
*/
- public List<ModelType> getModelTypeByDefinitionType(String definitionType) throws BluePrintException {
- if (StringUtils.isNotBlank(definitionType)) {
- return modelTypeRepository.findByDefinitionType(definitionType);
- } else {
- throw new BluePrintException("Model definitionType Information is missing.");
- }
+ public List<ModelType> 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<ModelType>
- * @throws BluePrintException
*/
- public List<ModelType> getModelTypeByDerivedFrom(String derivedFrom) throws BluePrintException {
- if (StringUtils.isNotBlank(derivedFrom)) {
- return modelTypeRepository.findByDerivedFrom(derivedFrom);
- } else {
- throw new BluePrintException("Model derivedFrom Information is missing.");
- }
+ public List<ModelType> 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<ResourceDict
/**
* This is a findByName method
*
- * @param name
+ * @param name name
* @return Optional<ResourceMapping>
*/
Optional<ResourceDictionary> findByName(String name);
@@ -45,7 +45,7 @@ public interface ResourceDictionaryRepository extends JpaRepository<ResourceDict
/**
* This is a findByNameIn method
*
- * @param names
+ * @param names names
* @return Optional<ResourceMapping>
*/
List<ResourceDictionary> findByNameIn(List<String> names);
@@ -53,7 +53,7 @@ public interface ResourceDictionaryRepository extends JpaRepository<ResourceDict
/**
* This is a findByTagsContainingIgnoreCase method
*
- * @param tags
+ * @param tags tags
* @return Optional<ModelType>
*/
List<ResourceDictionary> findByTagsContainingIgnoreCase(String tags);
@@ -61,9 +61,9 @@ public interface ResourceDictionaryRepository extends JpaRepository<ResourceDict
/**
* This is a deleteByName method
*
- * @param name
+ * @param name name
*/
- ResourceDictionary deleteByName(String name);
+ void deleteByName(String name);
}
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
index 00000000..141ba92c
--- /dev/null
+++ b/ms/controllerblueprints/modules/service/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/service/repository/BluePrintsReactRepository.kt
@@ -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
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<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
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<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
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<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();
+ }
+
+}
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<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());