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