2 * Copyright © 2018 IBM.
3 * Modifications Copyright © 2017-2018 AT&T Intellectual Property.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.apps.controllerblueprints.service.repository;
20 import org.junit.Assert;
21 import org.junit.FixMethodOrder;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.MethodSorters;
25 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;
26 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;
27 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;
28 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
31 import org.springframework.test.annotation.Commit;
32 import org.springframework.test.context.ContextConfiguration;
33 import org.springframework.test.context.junit4.SpringRunner;
35 import java.util.Arrays;
36 import java.util.List;
39 * ResourceDictionaryReactRepositoryTest.
41 * @author Brinda Santh
44 @RunWith(SpringRunner.class)
46 @ContextConfiguration(classes = {TestApplication.class})
47 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
48 public class ResourceDictionaryReactRepositoryTest {
50 private String sourceName = "test-source";
53 protected ResourceDictionaryReactRepository resourceDictionaryReactRepository;
57 public void test01Save() {
58 ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile("./../../application/load/resource_dictionary/sample-db-source" +
59 ".json", ResourceDefinition.class);
60 Assert.assertNotNull("Failed to get resourceDefinition from content", resourceDefinition);
61 resourceDefinition.setName(sourceName);
63 ResourceDictionary resourceDictionary = transformResourceDictionary(resourceDefinition);
64 ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.save(resourceDictionary).block();
65 Assert.assertNotNull("Failed to save ResourceDictionary", dbResourceDictionary);
69 public void test02FindByNameReact() {
70 ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName(sourceName).block();
71 Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary);
75 public void test03FindByNameInReact() {
76 List<ResourceDictionary> dbResourceDictionaries =
77 resourceDictionaryReactRepository.findByNameIn(Arrays.asList(sourceName)).collectList().block();
78 Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries);
82 public void test04FindByTagsContainingIgnoreCaseReact() {
83 List<ResourceDictionary> dbTagsResourceDictionaries =
84 resourceDictionaryReactRepository.findByTagsContainingIgnoreCase(sourceName).collectList().block();
85 Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries);
90 public void test05Delete() {
91 resourceDictionaryReactRepository.deleteByName(sourceName).block();
94 private ResourceDictionary transformResourceDictionary(ResourceDefinition resourceDefinition) {
95 ResourceDictionary resourceDictionary = new ResourceDictionary();
96 resourceDictionary.setName(resourceDefinition.getName());
97 resourceDictionary.setDataType(resourceDefinition.getProperty().getType());
98 resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription());
99 resourceDictionary.setTags(resourceDefinition.getTags());
100 resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy());
101 resourceDictionary.setDefinition(resourceDefinition);
102 return resourceDictionary;