2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.openecomp.sdnc.config.params.transformer.tosca;
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;
33 import java.util.ArrayList;
34 import java.util.List;
37 public class TestPropertyQueryString
40 public void testBuildResponseKeys()
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);
48 public void testBuildRequestKeys()
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);
56 public void testEncoding()
58 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
60 String expected1 = "<class-type>";
61 String encoded1 = arp.encode("<class-type>");
62 Assert.assertEquals(expected1,encoded1);
64 String expected2 = "<<<metallica<>iron_maiden>>>";
65 String encoded2 = arp.encode("<<<metallica<>iron_maiden>>>");
66 Assert.assertEquals(expected2,encoded2);
68 String expected3 = "band-list:metallica,ironmaiden";
69 String encoded3 = arp.encode("band-list:metallica,ironmaiden");
70 Assert.assertEquals(expected3,encoded3);
72 String expected4 = "motorhead=lemmy";
73 String encoded4 = arp.encode("motorhead=lemmy");
74 Assert.assertEquals(expected4,encoded4);
76 String expected5 = "DreamTheater";
77 String encoded5 = arp.encode(" DreamTheater ");
78 Assert.assertEquals(expected5,encoded5);
82 public void testBuildRuleType()
84 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
85 String input = "IPV4";
86 String expected = "<rule-type = IPV4>";
87 Assert.assertEquals(expected,arp.buildRuleType(input));
91 public void testRuleTypeSetNull()
93 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
94 String expected = "<rule-type = >";
95 Assert.assertEquals(expected,arp.buildRuleType(null));
99 public void testBuildRequestKeysWithKeyNull()
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);
109 public void testBuildResponseKeysWithKeyNull()
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);
119 public void testBuildSourceSystem()
121 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
122 Assert.assertEquals("<source-system = INSTAR>",arp.buildSourceSystem("INSTAR"));
125 private List<RequestKey> createRequestKeys()
127 //Create RequestKey object 1
128 RequestKey requestKey1 = new RequestKey();
129 requestKey1.setKeyName("class-type");
130 requestKey1.setKeyValue("interface-ip-address");
132 //Create RequestKey object 2
133 RequestKey requestKey2 = new RequestKey();
134 requestKey2.setKeyName("address_fqdn");
135 requestKey2.setKeyValue("00000000000000");
137 //Create RequestKey object 3
138 RequestKey requestKey3 = new RequestKey();
139 requestKey3.setKeyName("address_type");
140 requestKey3.setKeyValue("v4");
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;
150 private List<ResponseKey> createResponseKeys()
152 //Create RequestKey object 1
153 ResponseKey responseKey1 = new ResponseKey();
155 responseKey1.setUniqueKeyName("address-fqdn");
156 responseKey1.setUniqueKeyValue("0000000000000");
157 responseKey1.setFieldKeyName("ipaddress-v4");
159 ResponseKey responseKey2 = new ResponseKey();
160 responseKey2.setUniqueKeyName("key2");
161 responseKey2.setUniqueKeyValue("value2");
162 responseKey2.setFieldKeyName("field2");
165 //Add the RequestKey Objects to the List
166 List<ResponseKey> responseKeyList = new ArrayList<ResponseKey>();
167 responseKeyList.add(responseKey1);
168 responseKeyList.add(responseKey2);
170 return responseKeyList;