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