a968c3fb10d0b9a0487055d265781042a58e4637
[ccsdk/sli/adaptors.git] /
1 package jtest.org.onap.ccsdk.sli.adaptors.ra;
2
3 import org.junit.Assert;
4 import org.junit.FixMethodOrder;
5 import org.junit.Test;
6 import org.junit.runner.RunWith;
7 import org.junit.runners.MethodSorters;
8 import org.onap.ccsdk.sli.adaptors.ra.ResourceAllocator;
9 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
10 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13 import org.springframework.beans.factory.annotation.Autowired;
14 import org.springframework.test.context.ContextConfiguration;
15 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
16
17 @RunWith(SpringJUnit4ClassRunner.class)
18 @ContextConfiguration(locations = {"classpath:test-context.xml"})
19 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
20 public class TestGetResource {
21
22     private static final Logger log = LoggerFactory.getLogger(TestGetResource.class);
23
24     @Autowired(required = true)
25     private ResourceAllocator resourceAllocator;
26
27     @Autowired(required = true)
28     private DataSetup dataSetup;
29
30     private void setupResourceData() {
31         dataSetup.cleanup();
32
33         String targetId = "GBLOND2025MG2";
34         String assetId = "Device::" + targetId;
35         String resourceName = "internal-vlan";
36
37         for (int i = 0; i < 5; i++) {
38             String entityId = "TEST" + i;
39
40             String resourceUnion = "EVC::" + entityId;
41             String resourceSet = resourceUnion + "::1";
42
43             dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(i));
44         }
45
46         for (int i = 0; i < 5; i++) {
47             String entityId = "TEST" + (i + 10);
48
49             String resourceUnion = "EVC::SVLAN::" + entityId;
50             String resourceSet = resourceUnion + "::1";
51
52             dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(10 + i));
53         }
54
55         for (int i = 0; i < 5; i++) {
56             String entityId = "TEST" + (i + 20);
57
58             String resourceUnion = "EVC::" + entityId;
59             String resourceSet = resourceUnion + "::1";
60             String resourceShareGroup = "SHARE1";
61
62             dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
63                     String.valueOf(20 + i));
64         }
65
66         for (int i = 0; i < 5; i++) {
67             String entityId = "TEST" + (i + 30);
68
69             String resourceUnion = "EVC::SVLAN::" + entityId;
70             String resourceSet = resourceUnion + "::1";
71             String resourceShareGroup = "SHARE1";
72
73             dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
74                     String.valueOf(30 + i));
75         }
76     }
77
78     @Test
79     public void test001() throws Exception {
80
81         String t = "001";
82         log.info("============== query node " + t + " ================================");
83         log.info("=== Test query for resource target - no additional criteria");
84
85         setupResourceData();
86
87         SvcLogicContext ctx = new SvcLogicContext();
88         ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
89         ctx.setAttribute("ra-input.resource-target-type", "Device");
90
91         ctx.setAttribute("ra-input.resource-name", "internal-vlan");
92
93         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
94
95         Assert.assertTrue(st == QueryStatus.SUCCESS);
96
97         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
98         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
99         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
100         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
101         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
102                 "0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 30, 31, 32, 33, 34");
103     }
104
105     @Test
106     public void test002() throws Exception {
107
108         String t = "002";
109         log.info("============== query node " + t + " ================================");
110         log.info("=== Test query for resource target - with resource entity condition");
111
112         setupResourceData();
113
114         SvcLogicContext ctx = new SvcLogicContext();
115         ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
116         ctx.setAttribute("ra-input.resource-target-type", "Device");
117
118         ctx.setAttribute("ra-input.resource-name", "internal-vlan");
119
120         ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
121         ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");
122
123         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
124
125         Assert.assertTrue(st == QueryStatus.SUCCESS);
126
127         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
128         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
129         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
130         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
131         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
132                 "10, 11, 12, 13, 14, 30, 31, 32, 33, 34");
133     }
134
135     @Test
136     public void test003() throws Exception {
137
138         String t = "003";
139         log.info("============== query node " + t + " ================================");
140         log.info("=== Test query for resource target - with resource share group condition");
141
142         setupResourceData();
143
144         SvcLogicContext ctx = new SvcLogicContext();
145         ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
146         ctx.setAttribute("ra-input.resource-target-type", "Device");
147
148         ctx.setAttribute("ra-input.resource-name", "internal-vlan");
149
150         ctx.setAttribute("ra-input.resource-share-group-filter", "SHARE1");
151
152         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
153
154         Assert.assertTrue(st == QueryStatus.SUCCESS);
155
156         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
157         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
158         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
159         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
160         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
161                 "20, 21, 22, 23, 24, 30, 31, 32, 33, 34");
162     }
163
164     @Test
165     public void test004() throws Exception {
166
167         String t = "004";
168         log.info("============== query node " + t + " ================================");
169         log.info("=== Test query for resource target - with resource share group condition NULL");
170
171         setupResourceData();
172
173         SvcLogicContext ctx = new SvcLogicContext();
174         ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
175         ctx.setAttribute("ra-input.resource-target-type", "Device");
176
177         ctx.setAttribute("ra-input.resource-name", "internal-vlan");
178
179         ctx.setAttribute("ra-input.resource-share-group-filter", "null");
180
181         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
182
183         Assert.assertTrue(st == QueryStatus.SUCCESS);
184
185         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
186         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
187         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
188         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
189         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
190                 "0, 1, 2, 3, 4, 10, 11, 12, 13, 14");
191     }
192
193     @Test
194     public void test005() throws Exception {
195
196         String t = "005";
197         log.info("============== query node " + t + " ================================");
198         log.info("=== Test query for resource target - with both resource entity and resource share group conditions");
199
200         setupResourceData();
201
202         SvcLogicContext ctx = new SvcLogicContext();
203         ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
204         ctx.setAttribute("ra-input.resource-target-type", "Device");
205
206         ctx.setAttribute("ra-input.resource-name", "internal-vlan");
207
208         ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
209         ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");
210         ctx.setAttribute("ra-input.resource-share-group-filter", "null");
211
212         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
213
214         Assert.assertTrue(st == QueryStatus.SUCCESS);
215
216         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
217         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
218         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
219         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
220         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "10, 11, 12, 13, 14");
221     }
222 }