aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-config-params/provider/src/test/java/org/openecomp/sdnc/config/params/transformer/tosca/TestPropertyQueryString.java
blob: 3eb231ae9396b79f7cb6df329663c746ea725e6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*-
 * ============LICENSE_START=======================================================
 * ONAP : APPC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Copyright (C) 2017 Amdocs
 * =============================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdnc.config.params.transformer.tosca;

import org.junit.Assert;
import org.junit.Test;
import org.openecomp.sdnc.config.params.data.RequestKey;
import org.openecomp.sdnc.config.params.data.ResponseKey;

import java.util.ArrayList;
import java.util.List;

public class TestPropertyQueryString
{
   @Test
    public void testBuildResponseKeys()
    {
        ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
        String properties= arp.buildResponseKeyExpression(createResponseKeys());
        Assert.assertEquals("<response-keys = address-fqdn:0000000000000:ipaddress-v4 , key2:value2:field2>",properties);
    }

   @Test
    public void testBuildRequestKeys()
    {
        ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
        String properties= arp.buildRequestKeyExpression(createRequestKeys());
        Assert.assertEquals("<request-keys = class-type:interface-ip-address , address_fqdn:00000000000000 , address_type:v4>",properties);
    }

    @Test
    public void testEncoding()
    {
        ArtifactProcessorImpl arp = new ArtifactProcessorImpl();

        String expected1 = "&lt;class-type&gt;";
        String encoded1 = arp.encode("<class-type>");
        Assert.assertEquals(expected1,encoded1);

        String expected2 = "&lt;&lt;&lt;metallica&lt;&gt;iron_maiden&gt;&gt;&gt;";
        String encoded2 = arp.encode("<<<metallica<>iron_maiden>>>");
        Assert.assertEquals(expected2,encoded2);

        String expected3 = "band-list&colon;metallica&comma;ironmaiden";
        String encoded3 = arp.encode("band-list:metallica,ironmaiden");
        Assert.assertEquals(expected3,encoded3);

        String expected4 = "motorhead&equals;lemmy";
        String encoded4 = arp.encode("motorhead=lemmy");
        Assert.assertEquals(expected4,encoded4);

        String expected5 = "DreamTheater";
        String encoded5 = arp.encode("  DreamTheater  ");
        Assert.assertEquals(expected5,encoded5);
    }

    @Test
    public void testBuildRuleType()
    {
        ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
        String input = "IPV4";
        String expected = "<rule-type = IPV4>";
        Assert.assertEquals(expected,arp.buildRuleType(input));
    }

    @Test
    public void testRuleTypeSetNull()
    {
        ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
        String expected = "<rule-type = >";
        Assert.assertEquals(expected,arp.buildRuleType(null));
    }

    @Test
    public void testBuildRequestKeysWithKeyNull()
    {
        ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
        List<RequestKey> requestKeyList = new ArrayList<RequestKey>();
        requestKeyList.add(null);
        String properties= arp.buildRequestKeyExpression(requestKeyList);
        Assert.assertEquals("<request-keys = >",properties);
    }

    @Test
    public void testBuildResponseKeysWithKeyNull()
    {
        ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
        List<ResponseKey> responseKeyList = new ArrayList<ResponseKey>();
        responseKeyList.add(null);
        String properties= arp.buildResponseKeyExpression(responseKeyList);
        Assert.assertEquals("<response-keys = >",properties);
    }

    @Test
    public void testBuildSourceSystem()
    {
        ArtifactProcessorImpl arp = new ArtifactProcessorImpl();
        Assert.assertEquals("<source-system = source>",arp.buildSourceSystem("source"));
    }
    
    //@Test
    private List<RequestKey> createRequestKeys()
    {
        //Create RequestKey object 1
        RequestKey requestKey1 = new RequestKey();
        requestKey1.setKeyName("class-type");
        requestKey1.setKeyValue("interface-ip-address");

        //Create RequestKey object 2
        RequestKey requestKey2 = new RequestKey();
        requestKey2.setKeyName("address_fqdn");
        requestKey2.setKeyValue("00000000000000");

        //Create RequestKey object 3
        RequestKey requestKey3 = new RequestKey();
        requestKey3.setKeyName("address_type");
        requestKey3.setKeyValue("v4");

        //Add the RequestKey Objects to the List
        List<RequestKey> requestKeyList = new ArrayList<RequestKey>();
        requestKeyList.add(requestKey1);
        requestKeyList.add(requestKey2);
        requestKeyList.add(requestKey3);
        return  requestKeyList;
    }
    
    //@Test
    private List<ResponseKey> createResponseKeys()
    {
        //Create RequestKey object 1
        ResponseKey responseKey1 = new ResponseKey();

        responseKey1.setUniqueKeyName("address-fqdn");
        responseKey1.setUniqueKeyValue("0000000000000");
        responseKey1.setFieldKeyName("ipaddress-v4");

        ResponseKey responseKey2 = new ResponseKey();
        responseKey2.setUniqueKeyName("key2");
        responseKey2.setUniqueKeyValue("value2");
        responseKey2.setFieldKeyName("field2");

        //Add the RequestKey Objects to the List
        List<ResponseKey> responseKeyList = new ArrayList<ResponseKey>();
        responseKeyList.add(responseKey1);
        responseKeyList.add(responseKey2);

        return  responseKeyList;
    }
}