2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20 * ============LICENSE_END=========================================================
23 package org.openecomp.sdnc.config.params.transformer.tosca;
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;
31 import java.util.ArrayList;
32 import java.util.List;
35 public class TestPropertyQueryString
38 public void testBuildResponseKeys()
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);
46 public void testBuildRequestKeys()
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);
54 public void testEncoding()
56 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
58 String expected1 = "<class-type>";
59 String encoded1 = arp.encode("<class-type>");
60 Assert.assertEquals(expected1,encoded1);
62 String expected2 = "<<<metallica<>iron_maiden>>>";
63 String encoded2 = arp.encode("<<<metallica<>iron_maiden>>>");
64 Assert.assertEquals(expected2,encoded2);
66 String expected3 = "band-list:metallica,ironmaiden";
67 String encoded3 = arp.encode("band-list:metallica,ironmaiden");
68 Assert.assertEquals(expected3,encoded3);
70 String expected4 = "motorhead=lemmy";
71 String encoded4 = arp.encode("motorhead=lemmy");
72 Assert.assertEquals(expected4,encoded4);
74 String expected5 = "DreamTheater";
75 String encoded5 = arp.encode(" DreamTheater ");
76 Assert.assertEquals(expected5,encoded5);
80 public void testBuildRuleType()
82 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
83 String input = "IPV4";
84 String expected = "<rule-type = IPV4>";
85 Assert.assertEquals(expected,arp.buildRuleType(input));
89 public void testRuleTypeSetNull()
91 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
92 String expected = "<rule-type = >";
93 Assert.assertEquals(expected,arp.buildRuleType(null));
97 public void testBuildRequestKeysWithKeyNull()
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);
107 public void testBuildResponseKeysWithKeyNull()
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);
117 public void testBuildSourceSystem()
119 ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
120 Assert.assertEquals("<source-system = INSTAR>",arp.buildSourceSystem("INSTAR"));
123 private List<RequestKey> createRequestKeys()
125 //Create RequestKey object 1
126 RequestKey requestKey1 = new RequestKey();
127 requestKey1.setKeyName("class-type");
128 requestKey1.setKeyValue("interface-ip-address");
130 //Create RequestKey object 2
131 RequestKey requestKey2 = new RequestKey();
132 requestKey2.setKeyName("address_fqdn");
133 requestKey2.setKeyValue("00000000000000");
135 //Create RequestKey object 3
136 RequestKey requestKey3 = new RequestKey();
137 requestKey3.setKeyName("address_type");
138 requestKey3.setKeyValue("v4");
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;
148 private List<ResponseKey> createResponseKeys()
150 //Create RequestKey object 1
151 ResponseKey responseKey1 = new ResponseKey();
153 responseKey1.setUniqueKeyName("address-fqdn");
154 responseKey1.setUniqueKeyValue("0000000000000");
155 responseKey1.setFieldKeyName("ipaddress-v4");
157 ResponseKey responseKey2 = new ResponseKey();
158 responseKey2.setUniqueKeyName("key2");
159 responseKey2.setUniqueKeyValue("value2");
160 responseKey2.setFieldKeyName("field2");
163 //Add the RequestKey Objects to the List
164 List<ResponseKey> responseKeyList = new ArrayList<ResponseKey>();
165 responseKeyList.add(responseKey1);
166 responseKeyList.add(responseKey2);
168 return responseKeyList;