Merge "added test case to PropertyOperatorTest.java"
[ccsdk/apps.git] / ms / controllerblueprints / modules / service / src / test / java / org / onap / ccsdk / apps / controllerblueprints / service / rs / ResourceDictionaryRestTest.java
1 /*\r
2  * Copyright © 2017-2018 AT&T Intellectual Property.\r
3  * Modifications Copyright © 2018 IBM.\r
4  *\r
5  * Licensed under the Apache License, Version 2.0 (the "License");\r
6  * you may not use this file except in compliance with the License.\r
7  * You may obtain a copy of the License at\r
8  *\r
9  *     http://www.apache.org/licenses/LICENSE-2.0\r
10  *\r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 \r
18 package org.onap.ccsdk.apps.controllerblueprints.service.rs;\r
19 \r
20 import org.apache.commons.io.IOUtils;\r
21 import org.junit.Assert;\r
22 import org.junit.FixMethodOrder;\r
23 import org.junit.Test;\r
24 import org.junit.runner.RunWith;\r
25 import org.junit.runners.MethodSorters;\r
26 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;\r
27 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils;\r
28 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition;\r
29 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceSourceMapping;\r
30 import org.onap.ccsdk.apps.controllerblueprints.service.domain.ResourceDictionary;\r
31 import com.att.eelf.configuration.EELFLogger;\r
32 import com.att.eelf.configuration.EELFManager;\r
33 import org.springframework.beans.factory.annotation.Autowired;\r
34 import org.springframework.boot.test.context.SpringBootTest;\r
35 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;\r
36 import org.springframework.test.context.ContextConfiguration;\r
37 import org.springframework.test.context.junit4.SpringRunner;\r
38 \r
39 import java.nio.charset.Charset;\r
40 import java.util.ArrayList;\r
41 import java.util.List;\r
42 \r
43 \r
44 @RunWith(SpringRunner.class)\r
45 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {"blueprints.load.initial-data=true"})\r
46 @ContextConfiguration(classes = {TestApplication.class})\r
47 @FixMethodOrder(MethodSorters.NAME_ASCENDING)\r
48 public class ResourceDictionaryRestTest {\r
49 \r
50     private static EELFLogger log = EELFManager.getInstance().getLogger(ResourceDictionaryRestTest.class);\r
51 \r
52     @Autowired\r
53     protected ResourceDictionaryRest resourceDictionaryRest;\r
54 \r
55     @Test\r
56     public void test01SaveDataDictionary() throws Exception {\r
57         String definition = IOUtils.toString(\r
58                 getClass().getClassLoader().getResourceAsStream("resourcedictionary/default_definition.json"),\r
59                 Charset.defaultCharset());\r
60 \r
61         ResourceDictionary dataDictionary = new ResourceDictionary();\r
62         dataDictionary.setName("test-name");\r
63         dataDictionary.setDefinition(JacksonUtils.readValue(definition, ResourceDefinition.class));\r
64         dataDictionary.setDataType("string");\r
65         dataDictionary.setDescription("Sample Resource Mapping");\r
66         dataDictionary.setTags("test, ipaddress");\r
67         dataDictionary.setUpdatedBy("xxxxxx@xxx.com");\r
68 \r
69         dataDictionary = resourceDictionaryRest.saveResourceDictionary(dataDictionary);\r
70 \r
71         Assert.assertNotNull("Failed to get Saved Resource Dictionary", dataDictionary);\r
72         Assert.assertNotNull("Failed to get Saved Resource Dictionary, Id", dataDictionary.getName());\r
73 \r
74         ResourceDictionary dbDataDictionary =\r
75                 resourceDictionaryRest.getResourceDictionaryByName(dataDictionary.getName());\r
76         Assert.assertNotNull("Failed to query Resource Dictionary for ID (" + dataDictionary.getName() + ")",\r
77                 dbDataDictionary);\r
78         Assert.assertNotNull("Failed to query Resource Dictionary definition for ID (" + dataDictionary.getName() + ")",\r
79                 dbDataDictionary.getDefinition());\r
80 \r
81         log.trace("Saved Dictionary " + dbDataDictionary.getDefinition());\r
82 \r
83     }\r
84 \r
85     @Test\r
86     public void test02GetDataDictionary() throws Exception {\r
87 \r
88         ResourceDictionary dbResourceDictionary = resourceDictionaryRest.getResourceDictionaryByName("test-name");\r
89         Assert.assertNotNull("Failed to query Resource Dictionary by Name", dbResourceDictionary);\r
90 \r
91         String tags = "ipaddress";\r
92 \r
93         List<ResourceDictionary> dbResourceDictionaries = resourceDictionaryRest.searchResourceDictionaryByTags(tags);\r
94         Assert.assertNotNull("Failed to search ResourceDictionary by tags", dbResourceDictionaries);\r
95         Assert.assertTrue("Failed to search searchResourceDictionaryByTags by tags by count",\r
96                 dbResourceDictionaries.size() > 0);\r
97 \r
98         List<String> names = new ArrayList<>();\r
99         names.add("test-name");\r
100         dbResourceDictionaries = resourceDictionaryRest.searchResourceDictionaryByNames(names);\r
101         Assert.assertNotNull("Failed to search ResourceDictionary by Names", dbResourceDictionaries);\r
102         Assert.assertTrue("Failed to search searchResourceDictionaryByNames by tags by count",\r
103                 dbResourceDictionaries.size() > 0);\r
104 \r
105     }\r
106 \r
107     @Test\r
108     public void test03GetResourceSourceMapping() {\r
109         ResourceSourceMapping resourceSourceMapping = resourceDictionaryRest.getResourceSourceMapping();\r
110         org.springframework.util.Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping");\r
111         org.springframework.util.Assert.notNull(resourceSourceMapping.getResourceSourceMappings(), "Failed to get resource source mappings");\r
112     }\r
113 \r
114 }\r