d4de5b579c64d25cb0b56b8d05c20915e9562eff
[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 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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * ============LICENSE_END=========================================================\r
23  */\r
24 \r
25 package org.onap.sdnc.config.params.transformer.tosca;\r
26 \r
27 import java.util.ArrayList;\r
28 import java.util.List;\r
29 import org.junit.Assert;\r
30 import org.junit.Test;\r
31 import org.onap.sdnc.config.params.data.RequestKey;\r
32 import org.onap.sdnc.config.params.data.ResponseKey;\r
33 \r
34 public class TestPropertyQueryString {\r
35     @Test\r
36     public void testBuildResponseKeys() {\r
37         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
38         String properties = arp.buildResponseKeyExpression(createResponseKeys());\r
39         Assert.assertEquals(\r
40                 "<response-keys = address-fqdn:0000000000000:ipaddress-v4 , key2:value2:field2>",\r
41                 properties);\r
42     }\r
43 \r
44     @Test\r
45     public void testBuildRequestKeys() {\r
46         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
47         String properties = arp.buildRequestKeyExpression(createRequestKeys());\r
48         Assert.assertEquals(\r
49                 "<request-keys = class-type:interface-ip-address , address_fqdn:00000000000000 , address_type:v4>",\r
50                 properties);\r
51     }\r
52 \r
53     @Test\r
54     public void testEncoding() {\r
55         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
56 \r
57         String expected1 = "&lt;class-type&gt;";\r
58         String encoded1 = arp.encode("<class-type>");\r
59         Assert.assertEquals(expected1, encoded1);\r
60 \r
61         String expected2 = "&lt;&lt;&lt;metallica&lt;&gt;iron_maiden&gt;&gt;&gt;";\r
62         String encoded2 = arp.encode("<<<metallica<>iron_maiden>>>");\r
63         Assert.assertEquals(expected2, encoded2);\r
64 \r
65         String expected3 = "band-list&colon;metallica&comma;ironmaiden";\r
66         String encoded3 = arp.encode("band-list:metallica,ironmaiden");\r
67         Assert.assertEquals(expected3, encoded3);\r
68 \r
69         String expected4 = "motorhead&equals;lemmy";\r
70         String encoded4 = arp.encode("motorhead=lemmy");\r
71         Assert.assertEquals(expected4, encoded4);\r
72 \r
73         String expected5 = "DreamTheater";\r
74         String encoded5 = arp.encode("  DreamTheater  ");\r
75         Assert.assertEquals(expected5, encoded5);\r
76     }\r
77 \r
78     @Test\r
79     public void testBuildRuleType() {\r
80         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
81         String input = "IPV4";\r
82         String expected = "<rule-type = IPV4>";\r
83         Assert.assertEquals(expected, arp.buildRuleType(input));\r
84     }\r
85 \r
86     @Test\r
87     public void testRuleTypeSetNull() {\r
88         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
89         String expected = "<rule-type = >";\r
90         Assert.assertEquals(expected, arp.buildRuleType(null));\r
91     }\r
92 \r
93     @Test\r
94     public void testBuildRequestKeysWithKeyNull() {\r
95         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
96         List<RequestKey> requestKeyList = new ArrayList<RequestKey>();\r
97         requestKeyList.add(null);\r
98         String properties = arp.buildRequestKeyExpression(requestKeyList);\r
99         Assert.assertEquals("<request-keys = >", properties);\r
100     }\r
101 \r
102     @Test\r
103     public void testBuildResponseKeysWithKeyNull() {\r
104         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
105         List<ResponseKey> responseKeyList = new ArrayList<ResponseKey>();\r
106         responseKeyList.add(null);\r
107         String properties = arp.buildResponseKeyExpression(responseKeyList);\r
108         Assert.assertEquals("<response-keys = >", properties);\r
109     }\r
110 \r
111     @Test\r
112     public void testBuildSourceSystem() {\r
113         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();\r
114         Assert.assertEquals("<source-system = source>", arp.buildSourceSystem("source"));\r
115     }\r
116 \r
117     // @Test\r
118     private List<RequestKey> createRequestKeys() {\r
119         // Create RequestKey object 1\r
120         RequestKey requestKey1 = new RequestKey();\r
121         requestKey1.setKeyName("class-type");\r
122         requestKey1.setKeyValue("interface-ip-address");\r
123 \r
124         // Create RequestKey object 2\r
125         RequestKey requestKey2 = new RequestKey();\r
126         requestKey2.setKeyName("address_fqdn");\r
127         requestKey2.setKeyValue("00000000000000");\r
128 \r
129         // Create RequestKey object 3\r
130         RequestKey requestKey3 = new RequestKey();\r
131         requestKey3.setKeyName("address_type");\r
132         requestKey3.setKeyValue("v4");\r
133 \r
134         // Add the RequestKey Objects to the List\r
135         List<RequestKey> requestKeyList = new ArrayList<RequestKey>();\r
136         requestKeyList.add(requestKey1);\r
137         requestKeyList.add(requestKey2);\r
138         requestKeyList.add(requestKey3);\r
139         return requestKeyList;\r
140     }\r
141 \r
142     // @Test\r
143     private List<ResponseKey> createResponseKeys() {\r
144         // Create RequestKey object 1\r
145         ResponseKey responseKey1 = new ResponseKey();\r
146 \r
147         responseKey1.setUniqueKeyName("address-fqdn");\r
148         responseKey1.setUniqueKeyValue("0000000000000");\r
149         responseKey1.setFieldKeyName("ipaddress-v4");\r
150 \r
151         ResponseKey responseKey2 = new ResponseKey();\r
152         responseKey2.setUniqueKeyName("key2");\r
153         responseKey2.setUniqueKeyValue("value2");\r
154         responseKey2.setFieldKeyName("field2");\r
155 \r
156         // Add the RequestKey Objects to the List\r
157         List<ResponseKey> responseKeyList = new ArrayList<ResponseKey>();\r
158         responseKeyList.add(responseKey1);\r
159         responseKeyList.add(responseKey2);\r
160 \r
161         return responseKeyList;\r
162     }\r
163 }\r