summaryrefslogtreecommitdiffstats
path: root/adaptors/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java
blob: 04ee381154f32eab626b889e5c5036b3dfa8b39b (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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
package jtest.org.onap.ccsdk.sli.adaptors.ra;

import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:test-context.xml"})
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestGetResource {

    private static final Logger log = LoggerFactory.getLogger(TestGetResource.class);

    @Autowired(required = true)
    private ResourceAllocator resourceAllocator;

    @Autowired(required = true)
    private DataSetup dataSetup;

    private void setupResourceData() {
        dataSetup.cleanup();

        String targetId = "GBLOND2025MG2";
        String assetId = "Device::" + targetId;
        String resourceName = "internal-vlan";

        for (int i = 0; i < 5; i++) {
            String entityId = "TEST" + i;

            String resourceUnion = "EVC::" + entityId;
            String resourceSet = resourceUnion + "::1";

            dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(i));
        }

        for (int i = 0; i < 5; i++) {
            String entityId = "TEST" + (i + 10);

            String resourceUnion = "EVC::SVLAN::" + entityId;
            String resourceSet = resourceUnion + "::1";

            dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(10 + i));
        }

        for (int i = 0; i < 5; i++) {
            String entityId = "TEST" + (i + 20);

            String resourceUnion = "EVC::" + entityId;
            String resourceSet = resourceUnion + "::1";
            String resourceShareGroup = "SHARE1";

            dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
                    String.valueOf(20 + i));
        }

        for (int i = 0; i < 5; i++) {
            String entityId = "TEST" + (i + 30);

            String resourceUnion = "EVC::SVLAN::" + entityId;
            String resourceSet = resourceUnion + "::1";
            String resourceShareGroup = "SHARE1";

            dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
                    String.valueOf(30 + i));
        }
    }

    @Test
    public void test001() throws Exception {

        String t = "001";
        log.info("============== get-resource node " + t + " ================================");
        log.info("=== Test query for resource target - no additional criteria");

        setupResourceData();

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
        ctx.setAttribute("ra-input.resource-target-type", "Device");

        ctx.setAttribute("ra-input.resource-name", "internal-vlan");

        QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);

        Assert.assertTrue(st == QueryStatus.SUCCESS);

        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
                "0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 30, 31, 32, 33, 34");
    }

    @Test
    public void test002() throws Exception {

        String t = "002";
        log.info("============== get-resource node " + t + " ================================");
        log.info("=== Test query for resource target - with resource entity condition");

        setupResourceData();

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
        ctx.setAttribute("ra-input.resource-target-type", "Device");

        ctx.setAttribute("ra-input.resource-name", "internal-vlan");

        ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
        ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");

        QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);

        Assert.assertTrue(st == QueryStatus.SUCCESS);

        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
                "10, 11, 12, 13, 14, 30, 31, 32, 33, 34");
    }

    @Test
    public void test003() throws Exception {

        String t = "003";
        log.info("============== get-resource node " + t + " ================================");
        log.info("=== Test query for resource target - with resource share group condition");

        setupResourceData();

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
        ctx.setAttribute("ra-input.resource-target-type", "Device");

        ctx.setAttribute("ra-input.resource-name", "internal-vlan");

        ctx.setAttribute("ra-input.resource-share-group-filter", "SHARE1");

        QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);

        Assert.assertTrue(st == QueryStatus.SUCCESS);

        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
                "20, 21, 22, 23, 24, 30, 31, 32, 33, 34");
    }

    @Test
    public void test004() throws Exception {

        String t = "004";
        log.info("============== get-resource node " + t + " ================================");
        log.info("=== Test query for resource target - with resource share group condition NULL");

        setupResourceData();

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
        ctx.setAttribute("ra-input.resource-target-type", "Device");

        ctx.setAttribute("ra-input.resource-name", "internal-vlan");

        ctx.setAttribute("ra-input.resource-share-group-filter", "null");

        QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);

        Assert.assertTrue(st == QueryStatus.SUCCESS);

        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
                "0, 1, 2, 3, 4, 10, 11, 12, 13, 14");
    }

    @Test
    public void test005() throws Exception {

        String t = "005";
        log.info("============== get-resource node " + t + " ================================");
        log.info("=== Test query for resource target - with both resource entity and resource share group conditions");

        setupResourceData();

        SvcLogicContext ctx = new SvcLogicContext();
        ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
        ctx.setAttribute("ra-input.resource-target-type", "Device");

        ctx.setAttribute("ra-input.resource-name", "internal-vlan");

        ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
        ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");
        ctx.setAttribute("ra-input.resource-share-group-filter", "null");

        QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);

        Assert.assertTrue(st == QueryStatus.SUCCESS);

        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
        Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "10, 11, 12, 13, 14");
    }
}