1e740ec33d00411680eec82f4a77fab355d8e582
[ccsdk/cds.git] /
1 /*
2  *  Copyright © 2018 IBM.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 package org.onap.ccsdk.apps.controllerblueprints.service.repository;
18
19 import org.junit.Assert;
20 import org.junit.Before;
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.context.ContextConfiguration;
32 import org.springframework.test.context.junit4.SpringRunner;
33
34 import java.util.Arrays;
35 import java.util.List;
36
37 /**
38  * ResourceDictionaryReactRepositoryTest.
39  *
40  * @author Brinda Santh
41  */
42
43 @RunWith(SpringRunner.class)
44 @DataJpaTest
45 @ContextConfiguration(classes = {TestApplication.class})
46 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
47 public class ResourceDictionaryReactRepositoryTest {
48
49     @Autowired
50     protected ResourceDictionaryReactRepository resourceDictionaryReactRepository;
51
52     @Before
53     public void init() {
54         ResourceDefinition resourceDefinition = JacksonUtils.readValueFromFile("load/resource_dictionary/db-source" +
55                 ".json", ResourceDefinition.class);
56
57         ResourceDictionary resourceDictionary = transformResourceDictionary(resourceDefinition);
58         ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.save(resourceDictionary).block();
59         Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary);
60     }
61
62     @Test
63     public void test01FindByNameReact() throws Exception {
64         ResourceDictionary dbResourceDictionary = resourceDictionaryReactRepository.findByName("db-source").block();
65         Assert.assertNotNull("Failed to query React Resource Dictionary by Name", dbResourceDictionary);
66     }
67
68     @Test
69     public void test02FindByNameInReact() throws Exception {
70         List<ResourceDictionary> dbResourceDictionaries =
71                 resourceDictionaryReactRepository.findByNameIn(Arrays.asList("db-source")).collectList().block();
72         Assert.assertNotNull("Failed to query React Resource Dictionary by Names", dbResourceDictionaries);
73     }
74
75     @Test
76     public void test03FindByTagsContainingIgnoreCaseReact() throws Exception {
77         List<ResourceDictionary> dbTagsResourceDictionaries =
78                 resourceDictionaryReactRepository.findByTagsContainingIgnoreCase("db-source").collectList().block();
79         Assert.assertNotNull("Failed to query React Resource Dictionary by Tags", dbTagsResourceDictionaries);
80     }
81
82     private ResourceDictionary transformResourceDictionary(ResourceDefinition resourceDefinition) {
83         ResourceDictionary resourceDictionary = new ResourceDictionary();
84         resourceDictionary.setName(resourceDefinition.getName());
85         resourceDictionary.setDataType(resourceDefinition.getProperty().getType());
86         resourceDictionary.setDescription(resourceDefinition.getProperty().getDescription());
87         resourceDictionary.setResourcePath(resourceDefinition.getResourcePath());
88         resourceDictionary.setResourceType(resourceDefinition.getResourceType());
89         resourceDictionary.setTags(resourceDefinition.getTags());
90         resourceDictionary.setUpdatedBy(resourceDefinition.getUpdatedBy());
91         resourceDictionary.setDefinition(resourceDefinition);
92         return resourceDictionary;
93     }
94 }