Changed to unmaintained
[appc.git] / appc-config / appc-config-params / provider / src / test / java / org / onap / sdnc / config / params / transformer / tosca / TestPropertyQueryString.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP : APPC\r
4  * ================================================================================\r
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Copyright (C) 2017 Amdocs\r
8  * =============================================================================\r
9  * Licensed under the Apache License, Version 2.0 (the "License");\r
10  * you may not use this file except in compliance with the License.\r
11  * You may obtain a copy of the License at\r
12  * \r
13  *      http://www.apache.org/licenses/LICENSE-2.0\r
14  * \r
15  * Unless required by applicable law or agreed to in writing, software\r
16  * distributed under the License is distributed on an "AS IS" BASIS,\r
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
18  * See the License for the specific language governing permissions and\r
19  * limitations under the License.\r
20  * \r
21  * ============LICENSE_END=========================================================\r
22  */\r
23 \r
24 package org.onap.sdnc.config.params.transformer.tosca;\r
25 \r
26 import java.util.ArrayList;\r
27 import java.util.List;\r
28 import org.junit.Assert;\r
29 import org.junit.Test;\r
30 import org.onap.sdnc.config.params.data.RequestKey;\r
31 import org.onap.sdnc.config.params.data.ResponseKey;\r
32 \r
33 public class TestPropertyQueryString {\r
34     @Test\r
35     public void testBuildResponseKeys() {\r
36         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
37         String properties = arp.buildResponseKeyExpression(createResponseKeys());\r
38         Assert.assertEquals(\r
39                 "<response-keys = address-fqdn:0000000000000:ipaddress-v4 , key2:value2:field2>",\r
40                 properties);\r
41     }\r
42 \r
43     @Test\r
44     public void testBuildRequestKeys() {\r
45         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
46         String properties = arp.buildRequestKeyExpression(createRequestKeys());\r
47         Assert.assertEquals(\r
48                 "<request-keys = class-type:interface-ip-address , address_fqdn:00000000000000 , address_type:v4>",\r
49                 properties);\r
50     }\r
51 \r
52     @Test\r
53     public void testEncoding() {\r
54         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
55 \r
56         String expected1 = "&lt;class-type&gt;";\r
57         String encoded1 = arp.encode("<class-type>");\r
58         Assert.assertEquals(expected1, encoded1);\r
59 \r
60         String expected2 = "&lt;&lt;&lt;metallica&lt;&gt;iron_maiden&gt;&gt;&gt;";\r
61         String encoded2 = arp.encode("<<<metallica<>iron_maiden>>>");\r
62         Assert.assertEquals(expected2, encoded2);\r
63 \r
64         String expected3 = "band-list&colon;metallica&comma;ironmaiden";\r
65         String encoded3 = arp.encode("band-list:metallica,ironmaiden");\r
66         Assert.assertEquals(expected3, encoded3);\r
67 \r
68         String expected4 = "motorhead&equals;lemmy";\r
69         String encoded4 = arp.encode("motorhead=lemmy");\r
70         Assert.assertEquals(expected4, encoded4);\r
71 \r
72         String expected5 = "DreamTheater";\r
73         String encoded5 = arp.encode("  DreamTheater  ");\r
74         Assert.assertEquals(expected5, encoded5);\r
75     }\r
76 \r
77     @Test\r
78     public void testBuildRuleType() {\r
79         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
80         String input = "IPV4";\r
81         String expected = "<rule-type = IPV4>";\r
82         Assert.assertEquals(expected, arp.buildRuleType(input));\r
83     }\r
84 \r
85     @Test\r
86     public void testRuleTypeSetNull() {\r
87         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
88         String expected = "<rule-type = >";\r
89         Assert.assertEquals(expected, arp.buildRuleType(null));\r
90     }\r
91 \r
92     @Test\r
93     public void testBuildRequestKeysWithKeyNull() {\r
94         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
95         List<RequestKey> requestKeyList = new ArrayList<RequestKey>();\r
96         requestKeyList.add(null);\r
97         String properties = arp.buildRequestKeyExpression(requestKeyList);\r
98         Assert.assertEquals("<request-keys = >", properties);\r
99     }\r
100 \r
101     @Test\r
102     public void testBuildResponseKeysWithKeyNull() {\r
103         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
104         List<ResponseKey> responseKeyList = new ArrayList<ResponseKey>();\r
105         responseKeyList.add(null);\r
106         String properties = arp.buildResponseKeyExpression(responseKeyList);\r
107         Assert.assertEquals("<response-keys = >", properties);\r
108     }\r
109 \r
110     @Test\r
111     public void testBuildSourceSystem() {\r
112         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
113         Assert.assertEquals("<source-system = source>", arp.buildSourceSystem("source"));\r
114     }\r
115 \r
116     // @Test\r
117     private List<RequestKey> createRequestKeys() {\r
118         // Create RequestKey object 1\r
119         RequestKey requestKey1 = new RequestKey();\r
120         requestKey1.setKeyName("class-type");\r
121         requestKey1.setKeyValue("interface-ip-address");\r
122 \r
123         // Create RequestKey object 2\r
124         RequestKey requestKey2 = new RequestKey();\r
125         requestKey2.setKeyName("address_fqdn");\r
126         requestKey2.setKeyValue("00000000000000");\r
127 \r
128         // Create RequestKey object 3\r
129         RequestKey requestKey3 = new RequestKey();\r
130         requestKey3.setKeyName("address_type");\r
131         requestKey3.setKeyValue("v4");\r
132 \r
133         // Add the RequestKey Objects to the List\r
134         List<RequestKey> requestKeyList = new ArrayList<RequestKey>();\r
135         requestKeyList.add(requestKey1);\r
136         requestKeyList.add(requestKey2);\r
137         requestKeyList.add(requestKey3);\r
138         return requestKeyList;\r
139     }\r
140 \r
141     // @Test\r
142     private List<ResponseKey> createResponseKeys() {\r
143         // Create RequestKey object 1\r
144         ResponseKey responseKey1 = new ResponseKey();\r
145 \r
146         responseKey1.setUniqueKeyName("address-fqdn");\r
147         responseKey1.setUniqueKeyValue("0000000000000");\r
148         responseKey1.setFieldKeyName("ipaddress-v4");\r
149 \r
150         ResponseKey responseKey2 = new ResponseKey();\r
151         responseKey2.setUniqueKeyName("key2");\r
152         responseKey2.setUniqueKeyValue("value2");\r
153         responseKey2.setFieldKeyName("field2");\r
154 \r
155         // Add the RequestKey Objects to the List\r
156         List<ResponseKey> responseKeyList = new ArrayList<ResponseKey>();\r
157         responseKeyList.add(responseKey1);\r
158         responseKeyList.add(responseKey2);\r
159 \r
160         return responseKeyList;\r
161     }\r
162 }\r