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.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;
 
  17 @RunWith(SpringJUnit4ClassRunner.class)
 
  18 @ContextConfiguration(locations = {"classpath:test-context.xml"})
 
  19 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 
  20 public class TestGetResource {
 
  22     private static final Logger log = LoggerFactory.getLogger(TestGetResource.class);
 
  24     @Autowired(required = true)
 
  25     private ResourceAllocator resourceAllocator;
 
  27     @Autowired(required = true)
 
  28     private DataSetup dataSetup;
 
  30     private void setupResourceData() {
 
  33         String targetId = "GBLOND2025MG2";
 
  34         String assetId = "Device::" + targetId;
 
  35         String resourceName = "internal-vlan";
 
  37         for (int i = 0; i < 5; i++) {
 
  38             String entityId = "TEST" + i;
 
  40             String resourceUnion = "EVC::" + entityId;
 
  41             String resourceSet = resourceUnion + "::1";
 
  43             dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(i));
 
  46         for (int i = 0; i < 5; i++) {
 
  47             String entityId = "TEST" + (i + 10);
 
  49             String resourceUnion = "EVC::SVLAN::" + entityId;
 
  50             String resourceSet = resourceUnion + "::1";
 
  52             dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, String.valueOf(10 + i));
 
  55         for (int i = 0; i < 5; i++) {
 
  56             String entityId = "TEST" + (i + 20);
 
  58             String resourceUnion = "EVC::" + entityId;
 
  59             String resourceSet = resourceUnion + "::1";
 
  60             String resourceShareGroup = "SHARE1";
 
  62             dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
 
  63                     String.valueOf(20 + i));
 
  66         for (int i = 0; i < 5; i++) {
 
  67             String entityId = "TEST" + (i + 30);
 
  69             String resourceUnion = "EVC::SVLAN::" + entityId;
 
  70             String resourceSet = resourceUnion + "::1";
 
  71             String resourceShareGroup = "SHARE1";
 
  73             dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, resourceShareGroup,
 
  74                     String.valueOf(30 + i));
 
  79     public void test001() throws Exception {
 
  82         log.info("============== query node " + t + " ================================");
 
  83         log.info("=== Test query for resource target - no additional criteria");
 
  87         SvcLogicContext ctx = new SvcLogicContext();
 
  88         ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
 
  89         ctx.setAttribute("ra-input.resource-target-type", "Device");
 
  91         ctx.setAttribute("ra-input.resource-name", "internal-vlan");
 
  93         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
 
  95         Assert.assertTrue(st == QueryStatus.SUCCESS);
 
  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");
 
 106     public void test002() throws Exception {
 
 109         log.info("============== query node " + t + " ================================");
 
 110         log.info("=== Test query for resource target - with resource entity condition");
 
 114         SvcLogicContext ctx = new SvcLogicContext();
 
 115         ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
 
 116         ctx.setAttribute("ra-input.resource-target-type", "Device");
 
 118         ctx.setAttribute("ra-input.resource-name", "internal-vlan");
 
 120         ctx.setAttribute("ra-input.resource-entity-type-filter", "EVC");
 
 121         ctx.setAttribute("ra-input.resource-entity-id-filter", "SVLAN%");
 
 123         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
 
 125         Assert.assertTrue(st == QueryStatus.SUCCESS);
 
 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");
 
 136     public void test003() throws Exception {
 
 139         log.info("============== query node " + t + " ================================");
 
 140         log.info("=== Test query for resource target - with resource share group condition");
 
 144         SvcLogicContext ctx = new SvcLogicContext();
 
 145         ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
 
 146         ctx.setAttribute("ra-input.resource-target-type", "Device");
 
 148         ctx.setAttribute("ra-input.resource-name", "internal-vlan");
 
 150         ctx.setAttribute("ra-input.resource-share-group-filter", "SHARE1");
 
 152         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
 
 154         Assert.assertTrue(st == QueryStatus.SUCCESS);
 
 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");
 
 165     public void test004() throws Exception {
 
 168         log.info("============== query node " + t + " ================================");
 
 169         log.info("=== Test query for resource target - with resource share group condition NULL");
 
 173         SvcLogicContext ctx = new SvcLogicContext();
 
 174         ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
 
 175         ctx.setAttribute("ra-input.resource-target-type", "Device");
 
 177         ctx.setAttribute("ra-input.resource-name", "internal-vlan");
 
 179         ctx.setAttribute("ra-input.resource-share-group-filter", "null");
 
 181         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
 
 183         Assert.assertTrue(st == QueryStatus.SUCCESS);
 
 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");
 
 194     public void test005() throws Exception {
 
 197         log.info("============== query node " + t + " ================================");
 
 198         log.info("=== Test query for resource target - with both resource entity and resource share group conditions");
 
 202         SvcLogicContext ctx = new SvcLogicContext();
 
 203         ctx.setAttribute("ra-input.resource-target-id", "GBLOND2025MG2");
 
 204         ctx.setAttribute("ra-input.resource-target-type", "Device");
 
 206         ctx.setAttribute("ra-input.resource-name", "internal-vlan");
 
 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");
 
 212         QueryStatus st = resourceAllocator.query("NetworkCapacity", false, null, null, "ra-output", null, ctx);
 
 214         Assert.assertTrue(st == QueryStatus.SUCCESS);
 
 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");