4be985b2ae4132ec295f25fb3db822311ddf39ab
[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 TestQueryResource {
21
22     private static final Logger log = LoggerFactory.getLogger(TestQueryResource.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         for (int k = 0; k < 6; k++) {
34             String assetId = "Port::TESTPORT-" + (k / 2 + 1) + "-" + (k + 1);
35
36             for (int i = 0; i < 5; i++) {
37                 String entityId = "TEST-" + i + "-" + (k / 2 + 1);
38
39                 String resourceUnion = "EVC::" + entityId;
40                 String resourceSet = resourceUnion + "::1";
41
42                 dataSetup.setupRangeItem("test-range-1", assetId, resourceSet, resourceUnion, String.valueOf(i));
43             }
44         }
45
46         for (int k = 0; k < 6; k++) {
47             String assetId = "Port::TESTPORT-" + (k / 2 + 1) + "-" + (k + 1);
48
49             for (int i = 0; i < 5; i++) {
50                 String entityId = "TEST-" + i + "-" + (k / 2 + 1);
51
52                 String resourceUnion = "EVC::" + entityId;
53                 String resourceSet = resourceUnion + "::1";
54
55                 dataSetup.setupLimitItem("test-limit-1", assetId, resourceSet, resourceUnion, (i + 1) * 100);
56             }
57         }
58     }
59
60     @Test
61     public void test001() throws Exception {
62
63         String t = "001";
64         log.info("============== query node " + t + " ================================");
65         log.info("=== Test query for resources - with resource target condition - range");
66
67         setupResourceData();
68
69         SvcLogicContext ctx = new SvcLogicContext();
70         ctx.setAttribute("ra-input.resource-target-id-filter", "TESTPORT-1-%");
71         ctx.setAttribute("ra-input.resource-target-type-filter", "Port");
72
73         ctx.setAttribute("ra-input.resource-name", "test-range-1");
74
75         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
76
77         Assert.assertTrue(st == QueryStatus.SUCCESS);
78
79         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "2");
80         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "test-range-1");
81         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Port");
82         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "TESTPORT-1-1");
83         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "0, 1, 2, 3, 4");
84         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-name"), "test-range-1");
85         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-target-type"), "Port");
86         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-target-id"), "TESTPORT-1-2");
87         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocated"), "0, 1, 2, 3, 4");
88     }
89
90     @Test
91     public void test002() throws Exception {
92
93         String t = "002";
94         log.info("============== query node " + t + " ================================");
95         log.info("=== Test query for resources - with resource target condition - limit");
96
97         setupResourceData();
98
99         SvcLogicContext ctx = new SvcLogicContext();
100         ctx.setAttribute("ra-input.resource-target-id-filter", "TESTPORT-%-1");
101         ctx.setAttribute("ra-input.resource-target-type-filter", "Port");
102
103         ctx.setAttribute("ra-input.resource-name", "test-limit-1");
104
105         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
106
107         Assert.assertTrue(st == QueryStatus.SUCCESS);
108
109         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list_length"), "1");
110         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "test-limit-1");
111         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Port");
112         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "TESTPORT-1-1");
113         Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "1500");
114     }
115 }