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