diff options
author | Jessica Wagantall <jwagantall@linuxfoundation.org> | 2020-12-01 11:26:31 -0800 |
---|---|---|
committer | Jessica Wagantall <jwagantall@linuxfoundation.org> | 2020-12-01 11:27:11 -0800 |
commit | 11510b43c277b8e1dd7e58d79785544810118c8e (patch) | |
tree | b88a497c999d24b5f357ea9b26bc93e0990fd5e7 /resource-assignment/provider/src/test/java | |
parent | 5d2eab72fc4442f14108b41800cec88126913823 (diff) |
Migrate sli-adaptor files
Migrate sli-adaptor repo files into
a new "adaptors" directory.
Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Diffstat (limited to 'resource-assignment/provider/src/test/java')
10 files changed, 0 insertions, 2188 deletions
diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java deleted file mode 100644 index 9aa3f26c4..000000000 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/DataSetup.java +++ /dev/null @@ -1,108 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package jtest.org.onap.ccsdk.sli.adaptors.ra; - -import java.util.Date; -import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestDb; -import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestTable; - -public class DataSetup { - - private TestDb testDb; - - private TestTable resource = null; - private TestTable allocationItem = null; - - private static final String[] RESOURCE_COLUMNS = - {"asset_id", "resource_name", "resource_type", "lt_used", "rr_used"}; - - private static final String[] ALLOCATION_ITEM_COLUMNS = {"resource_id", "application_id", "resource_set_id", - "resource_union_id", "resource_share_group_list", "lt_used", "rr_used", "allocation_time"}; - - private void initTables() { - if (resource == null) { - resource = testDb.table("RESOURCE", "resource_id", RESOURCE_COLUMNS); - } - if (allocationItem == null) { - allocationItem = testDb.table("ALLOCATION_ITEM", "allocation_item_id", ALLOCATION_ITEM_COLUMNS); - } - } - - public void cleanup() { - initTables(); - allocationItem.delete("true"); - resource.delete("true"); - } - - public void setupLimitItem(String resourceName, String assetId, String resourceSetId, String resourceUnionId, - long used) { - initTables(); - - Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'"); - if (rid == null) { - resource.add(assetId, resourceName, "Limit", used, null); - rid = resource.getLastId(); - } - allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, null, used, null, new Date()); - } - - public void setupRangeItem(String resourceName, String assetId, String resourceSetId, String resourceUnionId, - String resourceShareGroup, String used) { - initTables(); - - Long rid = resource.getId("asset_id = '" + assetId + "' AND resource_name = '" + resourceName + "'"); - if (rid == null) { - resource.add(assetId, resourceName, "Range", null, used); - rid = resource.getLastId(); - } - allocationItem.add(rid, "SDNC", resourceSetId, resourceUnionId, resourceShareGroup, null, used, new Date()); - } - - public void setupRangeItem(String resourceName, String assetId, String resourceSetId, String resourceUnionId, - String used) { - setupRangeItem(resourceName, assetId, resourceSetId, resourceUnionId, null, used); - } - - public boolean checkRangeItem(String resourceName, String assetId, String resourceSetId, String used) { - String where = "resource_id = (SELECT resource_id FROM RESOURCE WHERE resource_name = '" + resourceName - + "' AND asset_id = '" + assetId + "') AND resource_set_id = '" + resourceSetId + "'"; - Object usedInDb = allocationItem.getColumn("rr_used", where); - return used.equals(usedInDb); - } - - public boolean checkLimitItem(String resourceName, String assetId, String resourceSetId, int used) { - String where = "resource_id = (SELECT resource_id FROM RESOURCE WHERE resource_name = '" + resourceName - + "' AND asset_id = '" + assetId + "') AND resource_set_id = '" + resourceSetId + "' AND lt_used = " - + used; - return allocationItem.exists(where); - } - - public boolean checkItemNotThere(String resourceName, String assetId, String resourceSetId) { - String where = "resource_id = (SELECT resource_id FROM RESOURCE WHERE resource_name = '" + resourceName - + "' AND asset_id = '" + assetId + "') AND resource_set_id = '" + resourceSetId + "'"; - return !allocationItem.exists(where); - } - - public void setTestDb(TestDb testDb) { - this.testDb = testDb; - } -} diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java deleted file mode 100644 index 04ee38115..000000000 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestGetResource.java +++ /dev/null @@ -1,222 +0,0 @@ -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"); - } -} diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java deleted file mode 100644 index a9389b279..000000000 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestLockHelper.java +++ /dev/null @@ -1,61 +0,0 @@ -package jtest.org.onap.ccsdk.sli.adaptors.ra; - -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.onap.ccsdk.sli.adaptors.lock.comp.LockHelper; -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; -import static org.junit.Assert.assertNotNull; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:test-context.xml" }) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestLockHelper { - - private static final Logger log = LoggerFactory.getLogger(TestLockHelper.class); - - @Autowired - private LockHelper lockHelper; - - @Test - public void test1() throws Exception { - LockThread t1 = new LockThread("req1"); - LockThread t2 = new LockThread("req2"); - LockThread t3 = new LockThread("req3"); - - t1.start(); - t2.start(); - t3.start(); - - t1.join(); - t2.join(); - t3.join(); - assertNotNull(t1); - } - - private class LockThread extends Thread { - private String requester; - - public LockThread(String requester) { - this.requester = requester; - } - - @Override - public void run() { - lockHelper.lock("resource1", requester, 20); - - try { - Thread.sleep(500); - } catch (InterruptedException e) { - log.warn("Thread interrupted: " + e.getMessage(), e); - } - - lockHelper.unlock("resource1", false); - } - } -} diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java deleted file mode 100644 index f31a3859a..000000000 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestQueryResource.java +++ /dev/null @@ -1,157 +0,0 @@ -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 TestQueryResource { - - private static final Logger log = LoggerFactory.getLogger(TestQueryResource.class); - - @Autowired(required = true) - private ResourceAllocator resourceAllocator; - - @Autowired(required = true) - private DataSetup dataSetup; - - private void setupResourceData() { - dataSetup.cleanup(); - - for (int k = 0; k < 6; k++) { - String assetId = "Port::TESTPORT-" + (k / 2 + 1) + "-" + (k + 1); - - for (int i = 0; i < 5; i++) { - String entityId = "TEST-" + i + "-" + (k / 2 + 1); - - String resourceUnion = "EVC::" + entityId; - String resourceSet = resourceUnion + "::1"; - - dataSetup.setupRangeItem("test-range-1", assetId, resourceSet, resourceUnion, String.valueOf(i)); - } - } - - for (int k = 0; k < 6; k++) { - String assetId = "Port::TESTPORT-" + (k / 2 + 1) + "-" + (k + 1); - - for (int i = 0; i < 5; i++) { - String entityId = "TEST-" + i + "-" + (k / 2 + 1); - - String resourceUnion = "EVC::" + entityId; - String resourceSet = resourceUnion + "::1"; - - dataSetup.setupLimitItem("test-limit-1", assetId, resourceSet, resourceUnion, (i + 1) * 100); - } - } - } - - @Test - public void test001() throws Exception { - - String t = "001"; - log.info("============== query node " + t + " ================================"); - log.info("=== Test query for resources - with resource target condition - range"); - - setupResourceData(); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-target-id-filter", "TESTPORT-1-%"); - ctx.setAttribute("ra-input.resource-target-type-filter", "Port"); - - ctx.setAttribute("ra-input.resource-name", "test-range-1"); - - 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"), "2"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-name"), "test-range-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Port"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "TESTPORT-1-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "0, 1, 2, 3, 4"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-name"), "test-range-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-target-type"), "Port"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].resource-target-id"), "TESTPORT-1-2"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocated"), "0, 1, 2, 3, 4"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list_length"), "5"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].resource-entity-type"), "EVC"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].resource-entity-id"), "TEST-0-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].resource-entity-version"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[0].allocated"), "0"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].resource-entity-type"), "EVC"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].resource-entity-id"), "TEST-1-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].resource-entity-version"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[1].allocated"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].resource-entity-type"), "EVC"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].resource-entity-id"), "TEST-2-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].resource-entity-version"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[2].allocated"), "2"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].resource-entity-type"), "EVC"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].resource-entity-id"), "TEST-3-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].resource-entity-version"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[3].allocated"), "3"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].resource-entity-type"), "EVC"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].resource-entity-id"), "TEST-4-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].resource-entity-version"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[1].allocation-data-list[4].allocated"), "4"); - } - - @Test - public void test002() throws Exception { - - String t = "002"; - log.info("============== query node " + t + " ================================"); - log.info("=== Test query for resources - with resource target condition - limit"); - - setupResourceData(); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-target-id-filter", "TESTPORT-%-1"); - ctx.setAttribute("ra-input.resource-target-type-filter", "Port"); - - ctx.setAttribute("ra-input.resource-name", "test-limit-1"); - - 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"), "test-limit-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-type"), "Port"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].resource-target-id"), "TESTPORT-1-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocated"), "1500"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list_length"), "5"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].resource-entity-type"), "EVC"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].resource-entity-id"), "TEST-0-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].resource-entity-version"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[0].allocated"), "100"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].resource-entity-type"), "EVC"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].resource-entity-id"), "TEST-1-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].resource-entity-version"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[1].allocated"), "200"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].resource-entity-type"), "EVC"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].resource-entity-id"), "TEST-2-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].resource-entity-version"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[2].allocated"), "300"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].resource-entity-type"), "EVC"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].resource-entity-id"), "TEST-3-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].resource-entity-version"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[3].allocated"), "400"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].resource-entity-type"), "EVC"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].resource-entity-id"), "TEST-4-1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].resource-entity-version"), "1"); - Assert.assertEquals(ctx.getAttribute("ra-output.resource-list[0].allocation-data-list[4].allocated"), "500"); - } -} diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestRelease.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestRelease.java deleted file mode 100644 index 88ec586e8..000000000 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestRelease.java +++ /dev/null @@ -1,420 +0,0 @@ -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 TestRelease { - - private static final Logger log = LoggerFactory.getLogger(TestRelease.class); - - @Autowired(required = true) - private ResourceAllocator resourceAllocator; - - @Autowired(required = true) - private DataSetup dataSetup; - - private void setupResourceData() { - dataSetup.cleanup(); - - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-1::1", "EVC::TEST-1", "1"); - - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-2::1", "EVC::TEST-2", "2"); - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-2::2", "EVC::TEST-2", "2"); - - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "EVC::TEST-3", "3"); - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "EVC::TEST-3", "4"); - - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "EVC::TEST-4", "5"); - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "EVC::TEST-4", "5"); - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "EVC::TEST-4", "6"); - - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-1::1", "EVC::TEST-1", "1"); - - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "EVC::TEST-3", "3"); - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "EVC::TEST-3", "4"); - - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-5::1", "EVC::TEST-5", "5"); - - dataSetup.setupRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-6::1", "EVC::TEST-6", "6-20"); - - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-1::1", "EVC::TEST-1", 100); - - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-2::1", "EVC::TEST-2", 200); - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-2::2", "EVC::TEST-2", 200); - - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "EVC::TEST-3", 300); - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "EVC::TEST-3", 400); - - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "EVC::TEST-4", 500); - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "EVC::TEST-4", 500); - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "EVC::TEST-4", 600); - - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-1::1", "EVC::TEST-1", 100); - - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "EVC::TEST-3", 300); - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "EVC::TEST-3", 400); - - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-5::1", "EVC::TEST-5", 500); - - dataSetup.setupLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-6::1", "EVC::TEST-6", 1000); - } - - @Test - public void test001() throws Exception { - - String t = "001"; - log.info("============== release node " + t + " ================================"); - log.info("=== Test release - with resource set"); - - setupResourceData(); - - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "5")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "5")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "6")); - - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::1", 500)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::2", 500)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::3", 600)); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-entity-type", "EVC"); - ctx.setAttribute("ra-input.resource-entity-id", "TEST-4"); - ctx.setAttribute("ra-input.resource-entity-version", "2"); - - QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "5")); - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "5")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "6")); - - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::1", 500)); - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::2", 500)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::3", 600)); - } - - @Test - public void test002() throws Exception { - - String t = "002"; - log.info("============== query node " + t + " ================================"); - log.info("=== Test release - with resource union"); - - setupResourceData(); - - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "5")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "5")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "6")); - - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::1", 500)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::2", 500)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::3", 600)); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-entity-type", "EVC"); - ctx.setAttribute("ra-input.resource-entity-id", "TEST-4"); - - QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::1", "5")); - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::2", "5")); - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-4::3", "6")); - - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::1", 500)); - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::2", 500)); - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-4::3", 600)); - } - - @Test - public void test003() throws Exception { - - String t = "003"; - log.info("============== release node " + t + " ================================"); - log.info("=== Test release - with resource set on 2 ports"); - - setupResourceData(); - - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4")); - - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400)); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-entity-type", "EVC"); - ctx.setAttribute("ra-input.resource-entity-id", "TEST-3"); - ctx.setAttribute("ra-input.resource-entity-version", "1"); - - QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4")); - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4")); - - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400)); - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400)); - } - - @Test - public void test004() throws Exception { - - String t = "004"; - log.info("============== release node " + t + " ================================"); - log.info("=== Test release - with resource union on 2 ports"); - - setupResourceData(); - - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4")); - - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400)); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-entity-type", "EVC"); - ctx.setAttribute("ra-input.resource-entity-id", "TEST-3"); - - QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3")); - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4")); - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3")); - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4")); - - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300)); - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400)); - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300)); - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400)); - } - - @Test - public void test005() throws Exception { - - String t = "005"; - log.info("============== release node " + t + " ================================"); - log.info("=== Test release - with resource set and asset"); - - setupResourceData(); - - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4")); - - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400)); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-entity-type", "EVC"); - ctx.setAttribute("ra-input.resource-entity-id", "TEST-3"); - ctx.setAttribute("ra-input.resource-entity-version", "1"); - - ctx.setAttribute("ra-input.resource-target-type", "Port"); - ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-1"); - - QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4")); - - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400)); - } - - @Test - public void test006() throws Exception { - - String t = "006"; - log.info("============== release node " + t + " ================================"); - log.info("=== Test release - with resource union on 2 ports"); - - setupResourceData(); - - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4")); - - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400)); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-entity-type", "EVC"); - ctx.setAttribute("ra-input.resource-entity-id", "TEST-3"); - - ctx.setAttribute("ra-input.resource-target-type", "Port"); - ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-1"); - - QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::1", "3")); - Assert.assertFalse(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-1", "EVC::TEST-3::2", "4")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::1", "3")); - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-3::2", "4")); - - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::1", 300)); - Assert.assertFalse(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-1", "EVC::TEST-3::2", 400)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::1", 300)); - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-3::2", 400)); - } - - @Test - public void test007() throws Exception { - - String t = "007"; - log.info("============== release node " + t + " ================================"); - log.info("=== Test release - partial release of range"); - - setupResourceData(); - - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-6::1", "6-20")); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-entity-type", "EVC"); - ctx.setAttribute("ra-input.resource-entity-id", "TEST-6"); - ctx.setAttribute("ra-input.resource-entity-version", "1"); - - ctx.setAttribute("ra-input.resource-target-type", "Port"); - ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-2"); - - ctx.setAttribute("ra-input.resource-name", "test-range-1"); - ctx.setAttribute("ra-input.range-release-numbers", "7,9,15-17"); - - QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-6::1", "6,8,10-14,18-20")); - } - - @Test - public void test008() throws Exception { - - String t = "008"; - log.info("============== release node " + t + " ================================"); - log.info("=== Test release - partial release of range, but release all numbers"); - - setupResourceData(); - - Assert.assertTrue(dataSetup.checkRangeItem("test-range-1", "Port::TESTPORT-2", "EVC::TEST-6::1", "6-20")); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-entity-type", "EVC"); - ctx.setAttribute("ra-input.resource-entity-id", "TEST-6"); - ctx.setAttribute("ra-input.resource-entity-version", "1"); - - ctx.setAttribute("ra-input.resource-target-type", "Port"); - ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-2"); - - ctx.setAttribute("ra-input.resource-name", "test-range-1"); - ctx.setAttribute("ra-input.range-release-numbers", "6-25"); - - QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - Assert.assertTrue(dataSetup.checkItemNotThere("test-range-1", "Port::TESTPORT-2", "EVC::TEST-6::1")); - } - - @Test - public void test009() throws Exception { - - String t = "009"; - log.info("============== release node " + t + " ================================"); - log.info("=== Test release - partial release of limit"); - - setupResourceData(); - - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-6::1", 1000)); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-entity-type", "EVC"); - ctx.setAttribute("ra-input.resource-entity-id", "TEST-6"); - ctx.setAttribute("ra-input.resource-entity-version", "1"); - - ctx.setAttribute("ra-input.resource-target-type", "Port"); - ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-2"); - - ctx.setAttribute("ra-input.resource-name", "test-limit-1"); - ctx.setAttribute("ra-input.limit-release-amount", "200"); - - QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-6::1", 800)); - } - - @Test - public void test010() throws Exception { - - String t = "010"; - log.info("============== release node " + t + " ================================"); - log.info("=== Test release - partial release of limit, but release big number"); - - setupResourceData(); - - Assert.assertTrue(dataSetup.checkLimitItem("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-6::1", 1000)); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.resource-entity-type", "EVC"); - ctx.setAttribute("ra-input.resource-entity-id", "TEST-6"); - ctx.setAttribute("ra-input.resource-entity-version", "1"); - - ctx.setAttribute("ra-input.resource-target-type", "Port"); - ctx.setAttribute("ra-input.resource-target-id", "TESTPORT-2"); - - ctx.setAttribute("ra-input.resource-name", "test-limit-1"); - ctx.setAttribute("ra-input.limit-release-amount", "2000"); - - QueryStatus st = resourceAllocator.release("NETWORK-CAPACITY", null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - Assert.assertTrue(dataSetup.checkItemNotThere("test-limit-1", "Port::TESTPORT-2", "EVC::TEST-6::1")); - } -} diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java deleted file mode 100644 index dbf0c4aac..000000000 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestReserve.java +++ /dev/null @@ -1,964 +0,0 @@ -package jtest.org.onap.ccsdk.sli.adaptors.ra; - -import static org.junit.Assert.assertNotNull; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -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.adaptors.ra.comp.ResourceEntity; -import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceRequest; -import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceResponse; -import org.onap.ccsdk.sli.adaptors.ra.comp.ResourceTarget; -import org.onap.ccsdk.sli.adaptors.rm.data.AllocationStatus; -import org.onap.ccsdk.sli.adaptors.rm.data.Range; -import org.onap.ccsdk.sli.adaptors.rm.data.ResourceType; -import org.onap.ccsdk.sli.adaptors.util.str.StrUtil; -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.jdbc.core.JdbcTemplate; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import jtest.util.org.onap.ccsdk.sli.adaptors.ra.TestTable; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:test-context.xml" }) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class TestReserve { - - private static final Logger log = LoggerFactory.getLogger(TestReserve.class); - - private JdbcTemplate jdbcTemplate; - - private static final String[] RESOURCE_COLUMNS = { "asset_id", "resource_name", "resource_type", "lt_used" }; - - private static final String[] ALLOCATION_ITEM_COLUMNS = { "resource_id", "application_id", "resource_set_id", - "resource_union_id", "resource_share_group_list", "lt_used", "allocation_time" }; - - @Autowired - public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { - this.jdbcTemplate = jdbcTemplate; - } - - @Autowired(required = true) - private ResourceAllocator resourceAllocator; - - /* - * @Autowired(required = true) private ResourceAllocatorApi - * resourceAllocatorApi; - */ - - @Autowired(required = true) - private DataSetup dataSetup; - - @Test - public void test001() throws Exception { - String t = "001"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - // String service1 = "reserve" + t + "/service1"; - - dataSetup.cleanup(); - - TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS); - TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id", - ALLOCATION_ITEM_COLUMNS); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "ADIG"); - ctx.setAttribute("ra-input.check-only", "false"); - ctx.setAttribute("ra-input.reservation-entity-type", "SI"); - ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456"); - ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100"); - ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps"); - - ctx.setAttribute("ra-input.reservation-target-data.vnf-type", "VPE"); - ctx.setAttribute("ra-input.reservation-target-data.vpe-name", "mdt300vpe54"); - ctx.setAttribute("ra-input.reservation-target-id", "mdt300vpe54"); - ctx.setAttribute("ra-input.reservation-target-type", "VNF"); - - ctx.setAttribute("ra-input.reservation-target-data.max-vpe-bandwidth-mbps", "5000"); - - QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - resource.print(); - allocationItem.print(); - - ctx.setAttribute("ra-input.service-model", "ADIG"); - ctx.setAttribute("ra-input.check-only", "false"); - ctx.setAttribute("ra-input.reservation-entity-type", "SI"); - ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456"); - ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100"); - ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps"); - - ctx.setAttribute("ra-input.reservation-target-data.service-speed", "100"); - ctx.setAttribute("ra-input.reservation-target-data.service-speed-unit", "Mbps"); - ctx.setAttribute("ra-input.reservation-target-id", "ICORESITEID-123456"); - ctx.setAttribute("ra-input.reservation-target-type", "Port"); - - st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - ctx.setAttribute("ra-input.service-model", "ADIG"); - ctx.setAttribute("ra-input.check-only", "false"); - ctx.setAttribute("ra-input.reservation-entity-type", "SI"); - ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456"); - ctx.setAttribute("ra-input.reservation-entity-data.service-speed", "100"); - ctx.setAttribute("ra-input.reservation-entity-data.service-speed-unit", "Mbps"); - - ctx.setAttribute("ra-input.reservation-target-data.vnf-type", "VPE"); - ctx.setAttribute("ra-input.reservation-target-data.vpe-name", "mdt300vpe54"); - ctx.setAttribute("ra-input.reservation-target-id", "mdt300vpe54"); - ctx.setAttribute("ra-input.reservation-target-type", "AffinityLink"); - - st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - resource.print(); - allocationItem.print(); - - /* Query Using ReservationEntityId using ServiceLogicContext */ - ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "ADIG"); - ctx.setAttribute("ra-input.reservation-entity-id", "ICOREPVCID-123456"); - ctx.setAttribute("ra-input.reservation-entity-type", "SI"); - - st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx); - Assert.assertTrue(st == QueryStatus.SUCCESS); - - /* Query Using ReservationTargetId using ServiceLogicContext */ - ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "ADIG"); - ctx.setAttribute("ra-input.reservation-target-id", "ICORESITEID-123456"); - ctx.setAttribute("ra-input.reservation-target-type", "Port"); - ctx.setAttribute("ra-input.resource-name", "Bandwidth"); - - st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx); - Assert.assertTrue(st == QueryStatus.SUCCESS); - - log.info("======================== Query Using ResourceEntity=============================="); - /* Query Using ResourceEntity bean */ - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "ICOREPVCID-123456"; - sd.resourceEntityType = "SI"; - - ResourceRequest rr = new ResourceRequest(); - rr.serviceModel = "ADIG"; - rr.resourceName = "cust-vlan-id"; - rr.requestType = "New"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - - List<ResourceResponse> rsList = new ArrayList<>(); - resourceAllocator.query(sd, null, null, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - log.info("======================== release Using ResourceEntity=============================="); - rsList = new ArrayList<>(); - AllocationStatus status = resourceAllocator.release(sd); - Assert.assertTrue(status == AllocationStatus.Success); - - log.info("======================== Query Using ResourceEntity=============================="); - rsList = new ArrayList<>(); - resourceAllocator.query(sd, null, null, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - } - - @Test - public void test002() throws Exception { - String t = "002"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - Map<String, String> data = new HashMap<>(); - data.put("service-speed", "100"); - data.put("service-speed-unit", "Mbps"); - - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "ICOREPVCID-123456"; - sd.resourceEntityType = "SI"; - sd.data = data; - - data = new HashMap<>(); - data.put("vnf-type", "VPE"); - data.put("vpe-name", "mdt300vpe54"); - data.put("max-vpe-bandwidth-mbps", "5000"); - - ResourceTarget rt = new ResourceTarget(); - rt.resourceTargetId = "mdt300vpe54"; - rt.resourceTargetType = "VNF"; - rt.data = data; - - ResourceRequest rr = new ResourceRequest(); - rr.serviceModel = "ADIG"; - // rr.resourceName = "cust-vlan-id"; - rr.requestType = "New"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - rr.applicationId = "myapp"; - - List<ResourceResponse> rsList = new ArrayList<>(); - - resourceAllocator.reserve(sd, rt, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - log.info("======================== Query + t =============================="); - rsList = new ArrayList<>(); - resourceAllocator.query(sd, null, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - assertNotNull(rsList); - - } - - @Test - public void test003() throws Exception { - String t = "003"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VNF"; - - ResourceTarget rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - ResourceRequest rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - rr.resourceName = "VPE-Cust"; - // rr.requestType = "New"; - // rr.rangeMaxOverride = 5; - // rr.rangeMinOverride = 5; - - List<ResourceResponse> rsList = new ArrayList<>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - log.info("======================== Query + t =============================="); - rsList = new ArrayList<>(); - resourceAllocator.query(sd, null, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - assertNotNull(sd); - - } - - @Test - public void test004() throws Exception { - String t = "004"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VNF"; - - ResourceTarget rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - List<ResourceRequest> rrs = new ArrayList<>(); - ResourceRequest rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - rr.resourceName = "VPE-Cust"; - rrs.add(rr); - - rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - rr.resourceName = "VPE-Core1"; - rrs.add(rr); - - rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - rr.resourceName = "VPE-Core2"; - rrs.add(rr); - - List<ResourceResponse> rsList = new ArrayList<>(); - // resourceAllocator.reserve(sd, rt, rrs, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - log.info("======================== Query + t =============================="); - rsList = new ArrayList<>(); - resourceAllocator.query(sd, null, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - assertNotNull(rr); - - } - - @Test - public void test005() throws Exception { - String t = "005"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - // String service1 = "reserve" + t + "/service1"; - - dataSetup.cleanup(); - - TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS); - TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id", - ALLOCATION_ITEM_COLUMNS); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); - ctx.setAttribute("ra-input.check-only", "false"); - ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Cust"); - ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); - - ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - - ctx.setAttribute("ra-input.resource-name", "cust-vlan-id"); - - QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - resource.print(); - allocationItem.print(); - - ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); - ctx.setAttribute("ra-input.check-only", "false"); - ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1"); - ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); - - ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - - ctx.setAttribute("ra-input.resource-name", "vlan-id-inner"); - - st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - resource.print(); - allocationItem.print(); - - ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); - ctx.setAttribute("ra-input.check-only", "false"); - ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core2"); - ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); - - ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - - ctx.setAttribute("ra-input.resource-name", "vlan-id-inner"); - ctx.setAttribute("ra-input.replace", "false"); - - st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - - resource.print(); - allocationItem.print(); - - /* Query Using ReservationEntityId using ServiceLogicContext */ - ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); - ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); - ctx.setAttribute("ra-input.reservation-entity-type", "VPE-Core1"); - - st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx); - Assert.assertTrue(st == QueryStatus.SUCCESS); - - /* Query Using ReservationTargetId using ServiceLogicContext */ - ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL-1"); - ctx.setAttribute("ra-input.reservation-target-id", "MDTWNJ21A5"); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - ctx.setAttribute("ra-input.resource-name", "vlan-id-inner"); - - st = resourceAllocator.query("NetworkCapacity", false, null, null, null, null, ctx); - Assert.assertTrue(st == QueryStatus.SUCCESS); - - log.info("======================== Query Using ResourceEntity=============================="); - /* Query Using ResourceEntity bean */ - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE-Core1"; - - ResourceRequest rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL-1"; - rr.resourceName = "vlan-id-inner"; - rr.requestType = "New"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - - List<ResourceResponse> rsList = new ArrayList<>(); - resourceAllocator.query(sd, null, null, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - /* - * log. - * info("======================== release Using ResourceEntity==============================" - * ); rsList = new ArrayList<ResourceResponse>(); AllocationStatus status = - * resourceAllocator.release(sd); Assert.assertTrue(status == - * AllocationStatus.Success); - * - * - * log. - * info("======================== Query Using ResourceEntity==============================" - * ); rsList = new ArrayList<ResourceResponse>(); resourceAllocator.query(sd, - * null, null, rsList); - * - * - * rsList.forEach(r -> { StrUtil.info(log, r); }); - */ - - } - - @Test - public void test006() throws Exception { - String t = "006"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE-Cust"; - - ResourceTarget rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - ResourceRequest rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL-1"; - rr.resourceName = "cust-vlan-id"; - - List<ResourceResponse> rsList = new ArrayList<>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - log.info("======================== Query + t =============================="); - rsList = new ArrayList<>(); - resourceAllocator.query(sd, null, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - assertNotNull(rsList); - - } - - @Test - public void test007() throws Exception { - String t = "007"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test successful response - new start - all resources available"); - - dataSetup.cleanup(); - - TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS); - TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id", - ALLOCATION_ITEM_COLUMNS); - - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE"; - sd.resourceEntityVersion = "1"; - - ResourceTarget rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - ResourceRequest rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - // rr.resourceName = "vlan-id-outer"; - rr.endPointPosition = "VPE-Cust"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - rr.applicationId = "myapp"; - - List<ResourceResponse> rsList = new ArrayList<>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - // VPE-Core1 - sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE"; - sd.resourceEntityVersion = "1"; - - rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - // rr.resourceName = "vlan-id-filter"; - rr.endPointPosition = "VPE-Core1"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - rr.applicationId = "myapp"; - - rsList = new ArrayList<>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - // VPE-Core2 - sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE"; - sd.resourceEntityVersion = "1"; - - rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - // rr.resourceName = "vlan-id-filter"; - rr.endPointPosition = "VPE-Core2"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - rr.applicationId = "myapp"; - - rsList = new ArrayList<>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - // VPE-Core3 - sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VPE"; - sd.resourceEntityVersion = "1"; - - rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL"; - // rr.resourceName = "vlan-id-filter"; - rr.endPointPosition = "VPE-Core3"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - rr.applicationId = "myapp"; - - rsList = new ArrayList<>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - resource.print(); - allocationItem.print(); - - log.info("======================== Query + t =============================="); - rsList = new ArrayList<>(); - resourceAllocator.query(sd, null, rr, rsList); - - rsList.forEach(r -> { - StrUtil.info(log, r); - }); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.reservation-entity-id", "gblond2003me6"); - ctx.setAttribute("ra-input.reservation-entity-type", "VPE"); - - QueryStatus st = resourceAllocator.release("NetworkCapacity", "gblond2003me6", ctx); - Assert.assertTrue(st == QueryStatus.SUCCESS); - - } - - @Test - public void test008() throws Exception { - String t = "008"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test range-force-new-numbers = false"); - - String entityId = "reserve" + t; - String targetId = "port-id-1"; - String resourceName = "cust-vlan-id"; - - String assetId = "VNF::" + targetId; - String resourceUnion = "SI::" + entityId; - String resourceSet1 = resourceUnion + "::1"; - String resourceSet2 = resourceUnion + "::2"; - - dataSetup.cleanup(); - - dataSetup.setupRangeItem(resourceName, assetId, resourceSet1, resourceUnion, "201"); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "ADIG"); - ctx.setAttribute("ra-input.check-only", "false"); - - ctx.setAttribute("ra-input.resource-name", resourceName); - ctx.setAttribute("ra-input.range-force-new-numbers", "false"); - - ctx.setAttribute("ra-input.reservation-entity-type", "SI"); - ctx.setAttribute("ra-input.reservation-entity-id", entityId); - ctx.setAttribute("ra-input.reservation-entity-version", "2"); - - ctx.setAttribute("ra-input.reservation-target-id", targetId); - ctx.setAttribute("ra-input.reservation-target-type", "VNF"); - - QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet1, "201")); - Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet2, "201")); - - Assert.assertEquals(ctx.getAttribute("resource-list_length"), "1"); - Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-name"), "cust-vlan-id"); - Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-target-type"), "VNF"); - Assert.assertEquals(ctx.getAttribute("resource-list[0].resource-target-id"), "port-id-1"); - Assert.assertEquals(ctx.getAttribute("resource-list[0].status"), "Success"); - Assert.assertEquals(ctx.getAttribute("resource-list[0].allocated"), "201"); - Assert.assertEquals(ctx.getAttribute("resource-list[0].used"), "201"); - Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list_length"), "1"); - Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list[0].min"), "2"); - Assert.assertEquals(ctx.getAttribute("resource-list[0].range-list[0].max"), "1000"); - } - - @Test - public void test009() throws Exception { - String t = "009"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test range-force-new-numbers = true"); - - String entityId = "reserve" + t; - String targetId = "port-id-1"; - String resourceName = "cust-vlan-id"; - - String assetId = "VNF::" + targetId; - String resourceUnion = "SI::" + entityId; - String resourceSet1 = resourceUnion + "::1"; - String resourceSet2 = resourceUnion + "::2"; - - dataSetup.cleanup(); - - dataSetup.setupRangeItem(resourceName, assetId, resourceSet1, resourceUnion, "201"); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "ADIG"); - ctx.setAttribute("ra-input.check-only", "false"); - - ctx.setAttribute("ra-input.resource-name", resourceName); - ctx.setAttribute("ra-input.range-force-new-numbers", "true"); - - ctx.setAttribute("ra-input.reservation-entity-type", "SI"); - ctx.setAttribute("ra-input.reservation-entity-id", entityId); - ctx.setAttribute("ra-input.reservation-entity-version", "2"); - - ctx.setAttribute("ra-input.reservation-target-id", targetId); - ctx.setAttribute("ra-input.reservation-target-type", "VNF"); - - QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, resourceSet1, "201")); - Assert.assertFalse(dataSetup.checkRangeItem(resourceName, assetId, resourceSet2, "201")); - } - - @Test - public void test0010_vlantag_with_resourcemodel() throws Exception { - - String t = "0010"; - log.info("============== reserve " + t + " ================================"); - - dataSetup.cleanup(); - - TestTable resource = new TestTable(jdbcTemplate, "RESOURCE", "resource_id", RESOURCE_COLUMNS); - TestTable allocationItem = new TestTable(jdbcTemplate, "ALLOCATION_ITEM", "allocation_item_id", - ALLOCATION_ITEM_COLUMNS); - - ResourceEntity sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VNF"; - sd.resourceEntityVersion = "1"; - - ResourceTarget rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - ResourceRequest rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL_3456"; - rr.resourceName = "vlan-id-outer"; - rr.endPointPosition = "VPE-Core1"; - rr.rangeMaxOverride = 3901; - rr.rangeMinOverride = 3900; - rr.resourceType = ResourceType.Range; - rr.applicationId = "myapp"; - - List<ResourceResponse> rsList = new ArrayList<>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - resource.print(); - allocationItem.print(); - - Range range = new Range(); - range.min = 3900; - range.max = 3901; - - sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VNF"; - sd.resourceEntityVersion = "1"; - - rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL_3456"; - rr.resourceName = "vlan-id-outer"; - rr.endPointPosition = "VPE-Core2"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - rr.rangeOverrideList = Arrays.asList(range); - rr.resourceType = ResourceType.Range; - rr.applicationId = "myapp"; - - rsList = new ArrayList<>(); - resourceAllocator.reserve(sd, rt, rr, rsList); - - resource.print(); - allocationItem.print(); - - sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VNF"; - sd.resourceEntityVersion = "1"; - - rt = new ResourceTarget(); - rt.resourceTargetId = "MDTWNJ21A5"; - rt.resourceTargetType = "Site"; - - Range range1 = new Range(); - range1.min = 3900; - range1.max = 3901; - - Range range2 = new Range(); - range2.min = 3904; - range2.max = 3905; - - rr = new ResourceRequest(); - rr.serviceModel = "MY-SERV-MODEL_3456"; - rr.resourceName = "vlan-id-outer"; - rr.endPointPosition = "VPE-Core3"; - rr.rangeMaxOverride = -1; - rr.rangeMinOverride = -1; - rr.rangeOverrideList = new ArrayList<>(); - rr.rangeOverrideList.add(range1); - rr.rangeOverrideList.add(range2); - rr.applicationId = "myapp"; - rr.resourceType = ResourceType.Range; - - rsList = new ArrayList<>(); - AllocationStatus status = resourceAllocator.reserve(sd, rt, rr, rsList); - Assert.assertTrue(status == AllocationStatus.Success); - - resource.print(); - allocationItem.print(); - - sd = new ResourceEntity(); - sd.resourceEntityId = "gblond2003me6"; - sd.resourceEntityType = "VNF"; - sd.resourceEntityVersion = "1"; - - rr = new ResourceRequest(); - rr.endPointPosition = "VPE-Core2"; - status = resourceAllocator.release(sd, rr); - Assert.assertTrue(status == AllocationStatus.Success); - - resource.print(); - allocationItem.print(); - - } - - @Test - public void test011() throws Exception { - String t = "011"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test range-next-in-sequence = true"); - - String entityId = "reserve" + t; - String targetId = "port-id-1"; - String resourceName = "vlan-id-filter"; - - String assetId = "Site::" + targetId; - String resourceUnion = "SI::" + entityId; - String resourceSet = resourceUnion + "::1"; - - dataSetup.cleanup(); - dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008"); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL"); - ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2"); - ctx.setAttribute("ra-input.check-only", "false"); - - ctx.setAttribute("ra-input.resource-name", resourceName); - ctx.setAttribute("ra-input.range-next-in-sequence", "true"); - - ctx.setAttribute("ra-input.reservation-entity-type", "SI"); - ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test"); - ctx.setAttribute("ra-input.reservation-entity-version", "1"); - - ctx.setAttribute("ra-input.reservation-target-id", targetId); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - - QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1009")); - } - - @Test - public void test012() throws Exception { - String t = "012"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test range-next-in-sequence = false"); - - String entityId = "reserve" + t; - String targetId = "port-id-1"; - String resourceName = "vlan-id-filter"; - - String assetId = "Site::" + targetId; - String resourceUnion = "SI::" + entityId; - String resourceSet = resourceUnion + "::1"; - - dataSetup.cleanup(); - dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008"); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL"); - ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2"); - ctx.setAttribute("ra-input.check-only", "false"); - - ctx.setAttribute("ra-input.resource-name", resourceName); - ctx.setAttribute("ra-input.range-next-in-sequence", "false"); - - ctx.setAttribute("ra-input.reservation-entity-type", "SI"); - ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test"); - ctx.setAttribute("ra-input.reservation-entity-version", "1"); - - ctx.setAttribute("ra-input.reservation-target-id", targetId); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - - QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1003")); - } - - @Test - public void test013() throws Exception { - String t = "013"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test range-next-in-sequence = true - multiple ranges"); - - String entityId = "reserve" + t; - String targetId = "port-id-1"; - String resourceName = "vlan-id-filter"; - - String assetId = "Site::" + targetId; - String resourceUnion = "SI::" + entityId; - String resourceSet = resourceUnion + "::1"; - - dataSetup.cleanup(); - dataSetup.setupRangeItem(resourceName, assetId, resourceSet, resourceUnion, "1002,1004,1006,1008,2205-2221"); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL"); - ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2"); - ctx.setAttribute("ra-input.check-only", "false"); - - ctx.setAttribute("ra-input.resource-name", resourceName); - ctx.setAttribute("ra-input.range-next-in-sequence", "true"); - - ctx.setAttribute("ra-input.reservation-entity-type", "SI"); - ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test"); - ctx.setAttribute("ra-input.reservation-entity-version", "1"); - - ctx.setAttribute("ra-input.reservation-target-id", targetId); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - - QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "2222")); - } - - @Test - public void test014() throws Exception { - String t = "014"; - log.info("============== reserve " + t + " ================================"); - log.info("=== Test range-next-in-sequence = true - no previously reserved numbers"); - - String entityId = "reserve" + t; - String targetId = "port-id-1"; - String resourceName = "vlan-id-filter"; - - String assetId = "Site::" + targetId; - - dataSetup.cleanup(); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("ra-input.service-model", "MY-SERV-MODEL"); - ctx.setAttribute("ra-input.endpoint-position", "VPE-Core2"); - ctx.setAttribute("ra-input.check-only", "false"); - - ctx.setAttribute("ra-input.resource-name", resourceName); - ctx.setAttribute("ra-input.range-next-in-sequence", "true"); - - ctx.setAttribute("ra-input.reservation-entity-type", "SI"); - ctx.setAttribute("ra-input.reservation-entity-id", entityId + "_test"); - ctx.setAttribute("ra-input.reservation-entity-version", "1"); - - ctx.setAttribute("ra-input.reservation-target-id", targetId); - ctx.setAttribute("ra-input.reservation-target-type", "Site"); - - QueryStatus st = resourceAllocator.reserve("NetworkCapacity", null, null, null, ctx); - - Assert.assertTrue(st == QueryStatus.SUCCESS); - Assert.assertTrue(dataSetup.checkRangeItem(resourceName, assetId, "SI::" + entityId + "_test::VPE-Core2::1", "1002")); - } -} diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestResourceLockNode.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestResourceLockNode.java deleted file mode 100644 index dc0761c20..000000000 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestResourceLockNode.java +++ /dev/null @@ -1,39 +0,0 @@ -package jtest.org.onap.ccsdk.sli.adaptors.ra; - -import java.util.HashMap; -import java.util.Map; - -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.ResourceLockNode; -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 TestResourceLockNode { - - @SuppressWarnings("unused") - private static final Logger log = LoggerFactory.getLogger(TestResourceLockNode.class); - - @Autowired - private ResourceLockNode resourceLockNode; - - @Test - public void test1() throws Exception { - Map<String, String> paramMap = new HashMap<>(); - paramMap.put("resource-name", "test-resource-1"); - paramMap.put("lock-requester", "SDNA"); - - resourceLockNode.lockResource(paramMap, null); - resourceLockNode.unlockResource(paramMap, null); - Assert.assertNotNull(paramMap); - } -} diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/rm/util/LabelUtilTest.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/rm/util/LabelUtilTest.java deleted file mode 100644 index eb903ecdc..000000000 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/rm/util/LabelUtilTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package jtest.org.onap.ccsdk.sli.adaptors.rm.util; - -import org.junit.Test; -import org.onap.ccsdk.sli.adaptors.rm.data.AllocationItem; -import org.onap.ccsdk.sli.adaptors.rm.data.LabelAllocationRequest; -import org.onap.ccsdk.sli.adaptors.rm.data.LabelResource; -import org.onap.ccsdk.sli.adaptors.rm.util.LabelUtil; - -import java.util.Date; - -import static org.junit.Assert.*; - -public class LabelUtilTest { - - @Test - public void testLabelUtils() { - LabelAllocationRequest req = new LabelAllocationRequest(); - req.check = true; - req.allocate = true; - req.label = "testLabel"; - req.resourceUnionId = "123"; - req.applicationId = "testApp"; - req.assetId = "asset1"; - req.resourceName = "resource1"; - req.resourceSetId = "set1"; - - - - LabelResource resource = new LabelResource(); - resource.label = "testLabel"; - - LabelUtil.allocateLabel(resource, req); - LabelUtil.checkLabel(resource, req); - LabelUtil.recalculate(resource); - - - - - - - - } - - -}
\ No newline at end of file diff --git a/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestDb.java b/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestDb.java deleted file mode 100644 index 6446240dc..000000000 --- a/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestDb.java +++ /dev/null @@ -1,37 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package jtest.util.org.onap.ccsdk.sli.adaptors.ra; - -import org.springframework.jdbc.core.JdbcTemplate; - -public class TestDb { - - private JdbcTemplate jdbcTemplate; - - public TestTable table(String tableName, String idName, String... columnList) { - return new TestTable(jdbcTemplate, tableName, idName, columnList); - } - - public void setJdbcTemplate(JdbcTemplate jdbcTemplate) { - this.jdbcTemplate = jdbcTemplate; - } -} diff --git a/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestTable.java b/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestTable.java deleted file mode 100644 index e2541f393..000000000 --- a/resource-assignment/provider/src/test/java/jtest/util/org/onap/ccsdk/sli/adaptors/ra/TestTable.java +++ /dev/null @@ -1,135 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * openECOMP : SDN-C - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package jtest.util.org.onap.ccsdk.sli.adaptors.ra; - -import java.sql.ResultSetMetaData; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.support.rowset.SqlRowSet; - -public class TestTable { - - private String tableName; - private String[] columnList; - private String idName; - - private String insertSql; - - private JdbcTemplate jdbcTemplate; - - private static final Logger log = LoggerFactory.getLogger(TestTable.class); - - public TestTable(JdbcTemplate jdbcTemplate, String tableName, String idName, String... columnList) { - this.jdbcTemplate = jdbcTemplate; - this.tableName = tableName; - this.idName = idName; - this.columnList = columnList; - createInsertSql(); - } - - public TestTable(JdbcTemplate jdbcTemplate, String tableName) { - this.jdbcTemplate = jdbcTemplate; - this.tableName = tableName; - } - - private void createInsertSql() { - StringBuilder ss = new StringBuilder(); - ss.append("INSERT INTO ").append(tableName).append(" ("); - for (String s : columnList) - ss.append(s).append(", "); - ss.setLength(ss.length() - 2); - ss.append(") VALUES ("); - for (int i = 0; i < columnList.length; i++) - ss.append("?, "); - ss.setLength(ss.length() - 2); - ss.append(")"); - insertSql = ss.toString(); - } - - public void add(Object... values) { - jdbcTemplate.update(insertSql, values); - } - - public void update(String updateSql, Object... values) { - jdbcTemplate.update(updateSql, values); - } - - public long getLastId() { - return jdbcTemplate.queryForObject("SELECT max(" + idName + ") FROM " + tableName, Long.class); - } - - public Long getId(String where) { - String selectSql = "SELECT " + idName + " FROM " + tableName + " WHERE " + where; - SqlRowSet rs = jdbcTemplate.queryForRowSet(selectSql); - if (rs.first()) - return rs.getLong(idName); - return null; - } - - public Object getColumn(String columnName, String where) { - String selectSql = "SELECT " + columnName + " FROM " + tableName + " WHERE " + where; - SqlRowSet rs = jdbcTemplate.queryForRowSet(selectSql); - if (rs.first()) - return rs.getObject(columnName); - return null; - } - - public boolean exists(String where) { - String selectSql = "SELECT * FROM " + tableName + " WHERE " + where; - SqlRowSet rs = jdbcTemplate.queryForRowSet(selectSql); - return rs.first(); - } - - public void delete(String where) { - jdbcTemplate.update("DELETE FROM " + tableName + " WHERE " + where); - } - - public void print() { - - jdbcTemplate.query("SELECT * FROM " + tableName, - (rs, rowNum) -> { - String row = "Table Data for " + tableName +"\n"; - String col = ""; - - final ResultSetMetaData meta = rs.getMetaData(); - final int columnCount = meta.getColumnCount(); - - do { - col = ""; - - for (int column = 1; column <= columnCount; ++column) { - Object obj = rs.getObject(column); - if(!rs.wasNull()) { - col = col + obj + ","; - } - } - col = col.trim().length() == 0 ? "" : (col.trim().substring(0, col.trim().length() - 1)); - row = row + col + "\n"; - } while (rs.next()); - - return row; - }).forEach(row -> { - log.info(row); - }); - } -}
\ No newline at end of file |