1 package jtest.org.onap.ccsdk.sli.adaptors.ra;
3 import org.junit.Assert;
4 import org.junit.FixMethodOrder;
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.adaptors.ra.comp.ResourceRequest;
10 import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceTarget;
11 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
12 import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.test.context.ContextConfiguration;
17 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
19 @RunWith(SpringJUnit4ClassRunner.class)
20 @ContextConfiguration(locations = {"classpath:test-context.xml"})
21 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
22 public class TestGetResource {
24 private static final Logger log = LoggerFactory.getLogger(TestGetResource.class);
26 @Autowired(required = true)
27 private ResourceAllocator resourceAllocator;
29 @Autowired(required = true)
30 private DataSetup dataSetup;
32 private void setupResourceData() {
35 String targetId = "GBLOND2025MG2";
36 String assetId = "Device::" + targetId;
37 String resourceName = "internal-vlan";
39 for (int i = 0; i < 5; i++) {
40 String entityId = "TEST" + i;
42 String resourceUnion = "EVC::" + entityId;
43 String resourceSet = resourceUnion + "::1";
45 dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(i));
48 for (int i = 0; i < 5; i++) {
49 String entityId = "TEST" + (i + 10);
51 String resourceUnion = "EVC::SVLAN::" + entityId;
52 String resourceSet = resourceUnion + "::1";
54 dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(10 + i));
57 for (int i = 0; i < 5; i++) {
58 String entityId = "TEST" + (i + 20);
60 String resourceUnion = "EVC::" + entityId;
61 String resourceSet = resourceUnion + "::1";
62 String resourceShareGroup = "SHARE1";
64 dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
65 String.valueOf(20 + i));
68 for (int i = 0; i < 5; i++) {
69 String entityId = "TEST" + (i + 30);
71 String resourceUnion = "EVC::SVLAN::" + entityId;
72 String resourceSet = resourceUnion + "::1";
73 String resourceShareGroup = "SHARE1";
75 dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
76 String.valueOf(30 + i));
81 public void test001() throws Exception {
84 log.info("============== query node " + t + " ================================");
85 log.info("=== Test query for resource target - no additional criteria");
89 ResourceTarget rt = new ResourceTarget();
90 rt.resourceTargetId = "GBLOND2025MG2";
91 rt.resourceTargetType = "Device";
93 ResourceRequest rr = new ResourceRequest();
94 rr.resourceName = "internal-vlan";
96 SvcLogicContext ctx = new SvcLogicContext();
97 ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
98 ctx.setAttribute("ra-input.resource-target-type", "Device");
100 ctx.setAttribute("ra-input.resource-name", "internal-vlan");
102 QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
104 Assert.assertTrue(st == QueryStatus.SUCCESS);
106 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
107 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
108 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
109 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
110 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
111 "0, 1, 2, 3, 4, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 30, 31, 32, 33, 34");
115 public void test002() throws Exception {
118 log.info("============== query node " + t + " ================================");
119 log.info("=== Test query for resource target - with resource entity condition");
123 ResourceTarget rt = new ResourceTarget();
124 rt.resourceTargetId = "GBLOND2025MG2";
125 rt.resourceTargetType = "Device";
127 ResourceRequest rr = new ResourceRequest();
128 rr.resourceName = "internal-vlan";
130 SvcLogicContext ctx = new SvcLogicContext();
131 ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
132 ctx.setAttribute("ra-input.resource-target-type", "Device");
134 ctx.setAttribute("ra-input.resource-name", "internal-vlan");
136 ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
137 ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");
139 QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
141 Assert.assertTrue(st == QueryStatus.SUCCESS);
143 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
144 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
145 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
146 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
147 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
148 "10, 11, 12, 13, 14, 30, 31, 32, 33, 34");
152 public void test003() throws Exception {
155 log.info("============== query node " + t + " ================================");
156 log.info("=== Test query for resource target - with resource share group condition");
160 ResourceTarget rt = new ResourceTarget();
161 rt.resourceTargetId = "GBLOND2025MG2";
162 rt.resourceTargetType = "Device";
164 ResourceRequest rr = new ResourceRequest();
165 rr.resourceName = "internal-vlan";
167 SvcLogicContext ctx = new SvcLogicContext();
168 ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
169 ctx.setAttribute("ra-input.resource-target-type", "Device");
171 ctx.setAttribute("ra-input.resource-name", "internal-vlan");
173 ctx.setAttribute("ra-input.resource-share-group-filter", "SHARE1");
175 QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
177 Assert.assertTrue(st == QueryStatus.SUCCESS);
179 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
180 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
181 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
182 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
183 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
184 "20, 21, 22, 23, 24, 30, 31, 32, 33, 34");
188 public void test004() throws Exception {
191 log.info("============== query node " + t + " ================================");
192 log.info("=== Test query for resource target - with resource share group condition NULL");
196 ResourceTarget rt = new ResourceTarget();
197 rt.resourceTargetId = "GBLOND2025MG2";
198 rt.resourceTargetType = "Device";
200 ResourceRequest rr = new ResourceRequest();
201 rr.resourceName = "internal-vlan";
203 SvcLogicContext ctx = new SvcLogicContext();
204 ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
205 ctx.setAttribute("ra-input.resource-target-type", "Device");
207 ctx.setAttribute("ra-input.resource-name", "internal-vlan");
209 ctx.setAttribute("ra-input.resource-share-group-filter", "null");
211 QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
213 Assert.assertTrue(st == QueryStatus.SUCCESS);
215 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
216 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
217 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
218 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
219 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"),
220 "0, 1, 2, 3, 4, 10, 11, 12, 13, 14");
224 public void test005() throws Exception {
227 log.info("============== query node " + t + " ================================");
228 log.info("=== Test query for resource target - with both resource entity and resource share group conditions");
232 ResourceTarget rt = new ResourceTarget();
233 rt.resourceTargetId = "GBLOND2025MG2";
234 rt.resourceTargetType = "Device";
236 ResourceRequest rr = new ResourceRequest();
237 rr.resourceName = "internal-vlan";
239 SvcLogicContext ctx = new SvcLogicContext();
240 ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
241 ctx.setAttribute("ra-input.resource-target-type", "Device");
243 ctx.setAttribute("ra-input.resource-name", "internal-vlan");
245 ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
246 ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");
247 ctx.setAttribute("ra-input.resource-share-group-filter", "null");
249 QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
251 Assert.assertTrue(st == QueryStatus.SUCCESS);
253 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
254 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "internal-vlan");
255 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Device");
256 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "GBLOND2025MG2");
257 Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "10, 11, 12, 13, 14");