2  * ============LICENSE_START=======================================================
\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 
  13  *      http://www.apache.org/licenses/LICENSE-2.0
\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 
  21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r 
  22  * ============LICENSE_END=========================================================
\r 
  25 package org.openecomp.sdnc.config.params.transformer.tosca;
\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 
  32 import java.util.ArrayList;
\r 
  33 import java.util.List;
\r 
  35 public class TestPropertyQueryString
\r 
  38     public void testBuildResponseKeys()
\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 
  46     public void testBuildRequestKeys()
\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 
  54     public void testEncoding()
\r 
  56         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
\r 
  58         String expected1 = "<class-type>";
\r 
  59         String encoded1 = arp.encode("<class-type>");
\r 
  60         Assert.assertEquals(expected1,encoded1);
\r 
  62         String expected2 = "<<<metallica<>iron_maiden>>>";
\r 
  63         String encoded2 = arp.encode("<<<metallica<>iron_maiden>>>");
\r 
  64         Assert.assertEquals(expected2,encoded2);
\r 
  66         String expected3 = "band-list:metallica,ironmaiden";
\r 
  67         String encoded3 = arp.encode("band-list:metallica,ironmaiden");
\r 
  68         Assert.assertEquals(expected3,encoded3);
\r 
  70         String expected4 = "motorhead=lemmy";
\r 
  71         String encoded4 = arp.encode("motorhead=lemmy");
\r 
  72         Assert.assertEquals(expected4,encoded4);
\r 
  74         String expected5 = "DreamTheater";
\r 
  75         String encoded5 = arp.encode("  DreamTheater  ");
\r 
  76         Assert.assertEquals(expected5,encoded5);
\r 
  80     public void testBuildRuleType()
\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 
  89     public void testRuleTypeSetNull()
\r 
  91         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
\r 
  92         String expected = "<rule-type = >";
\r 
  93         Assert.assertEquals(expected,arp.buildRuleType(null));
\r 
  97     public void testBuildRequestKeysWithKeyNull()
\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 
 107     public void testBuildResponseKeysWithKeyNull()
\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 
 117     public void testBuildSourceSystem()
\r 
 119         ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
\r 
 120         Assert.assertEquals("<source-system = source>",arp.buildSourceSystem("source"));
\r 
 124     private List<RequestKey> createRequestKeys()
\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 
 131         //Create RequestKey object 2
\r 
 132         RequestKey requestKey2 = new RequestKey();
\r 
 133         requestKey2.setKeyName("address_fqdn");
\r 
 134         requestKey2.setKeyValue("00000000000000");
\r 
 136         //Create RequestKey object 3
\r 
 137         RequestKey requestKey3 = new RequestKey();
\r 
 138         requestKey3.setKeyName("address_type");
\r 
 139         requestKey3.setKeyValue("v4");
\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 
 150     private List<ResponseKey> createResponseKeys()
\r 
 152         //Create RequestKey object 1
\r 
 153         ResponseKey responseKey1 = new ResponseKey();
\r 
 155         responseKey1.setUniqueKeyName("address-fqdn");
\r 
 156         responseKey1.setUniqueKeyValue("0000000000000");
\r 
 157         responseKey1.setFieldKeyName("ipaddress-v4");
\r 
 159         ResponseKey responseKey2 = new ResponseKey();
\r 
 160         responseKey2.setUniqueKeyName("key2");
\r 
 161         responseKey2.setUniqueKeyValue("value2");
\r 
 162         responseKey2.setFieldKeyName("field2");
\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 
 169         return  responseKeyList;
\r