From 7703d8d1f66f7a3709f7d44202833cb8fe0e4274 Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Fri, 1 Sep 2017 15:41:27 -0700 Subject: Enable surefire unit testing Issue-Id: CCSDK-67 Change-Id: I955938365dd62b2125b73f8a668568e3343db015 Signed-off-by: Marcus G K Williams --- pom.xml | 2 +- .../ccsdk/sli/adaptors/ra/TestIsAvailable.java | 23 +-- .../adaptors/resource/sql/ITCaseSqlResource.java | 218 +++++++++++++++++++++ .../sli/adaptors/resource/sql/SqlResourceTest.java | 218 --------------------- 4 files changed, 221 insertions(+), 240 deletions(-) create mode 100644 sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/ITCaseSqlResource.java delete mode 100644 sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResourceTest.java diff --git a/pom.xml b/pom.xml index f641ef50..eefdf04e 100755 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ maven-surefire-plugin 2.17 - true + false diff --git a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestIsAvailable.java b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestIsAvailable.java index 5b942342..4dee2d61 100644 --- a/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestIsAvailable.java +++ b/resource-assignment/provider/src/test/java/jtest/org/onap/ccsdk/sli/adaptors/ra/TestIsAvailable.java @@ -367,25 +367,6 @@ public class TestIsAvailable { public void test011() throws Exception { String t = "011"; log.info("============== isAvailable " + t + " ================================"); - log.info("=== Test input validations - no speed in input"); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("tmp.resource-allocator.speed-unit", "Gbps"); - ctx.setAttribute("tmp.resource-allocator.aic-site-id", "MTSNJA4LCP1"); - - try { - resourceAllocator.isAvailable("NetworkCapacity", null, null, ctx); - } catch (SvcLogicException e) { - Assert.assertTrue(e.getMessage().equals("tmp.resource-allocator.speed is required in ResourceAllocator")); - return; - } - Assert.fail("SvcLogicException expected"); - } - - @Test - public void test012() throws Exception { - String t = "012"; - log.info("============== isAvailable " + t + " ================================"); log.info("=== Test input validations - speed not a number in input"); SvcLogicContext ctx = new SvcLogicContext(); @@ -403,8 +384,8 @@ public class TestIsAvailable { } @Test - public void test013() throws Exception { - String t = "013"; + public void test012() throws Exception { + String t = "012"; log.info("============== isAvailable " + t + " ================================"); log.info("=== Test input validations - speed-unit missing in input"); diff --git a/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/ITCaseSqlResource.java b/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/ITCaseSqlResource.java new file mode 100644 index 00000000..f0ab6037 --- /dev/null +++ b/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/ITCaseSqlResource.java @@ -0,0 +1,218 @@ +/*- + * ============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 org.onap.ccsdk.sli.adaptors.resource.sql; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Enumeration; +import java.util.Properties; + +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 junit.framework.TestCase; + +public class ITCaseSqlResource extends TestCase { + + private static final Logger LOG = LoggerFactory + .getLogger(ITCaseSqlResource.class); + + + public void testExists() { + + + Properties props = new Properties(); + InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); + if (propStr == null) { + fail("src/test/resources/svclogic.properties missing"); + } + + try { + props.load(propStr); + propStr.close(); + } catch (Exception e) { + e.printStackTrace(); + fail("Could not initialize properties"); + } + + // Add properties to global properties + + Enumeration propNames = props.keys(); + + while (propNames.hasMoreElements()) { + String propName = (String) propNames.nextElement(); + + System.setProperty(propName, props.getProperty(propName)); + } + + SqlResource sqlResource = new SqlResource(); + + + + InputStream testStr = getClass().getResourceAsStream("/save.tests"); + BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); + SvcLogicContext ctx = new SvcLogicContext(); + + try { + String testExpr = null; + + int testNum = 0; + while ((testExpr = testsReader.readLine()) != null) { + testExpr = testExpr.trim(); + + if (testExpr.startsWith("#")) { + testExpr = testExpr.substring(1).trim(); + String[] nameValue = testExpr.split("="); + String name = nameValue[0].trim(); + String value = nameValue[1].trim(); + + LOG.info("Setting context attribute " + name + " = " + + value); + ctx.setAttribute(name, value); + + } else { + + testNum++; + String sqlStmt = testExpr; + QueryStatus status = sqlResource.save("SQL", true, false, sqlStmt, null, "savetest"+testNum, ctx); + + switch (status) { + case SUCCESS: + LOG.info("Found data for query [" + sqlStmt + "]"); + break; + case NOT_FOUND: + LOG.info("Did not data for query [" + sqlStmt + "]"); + break; + default: + fail("Failure executing query [" + sqlStmt + "]"); + + } + } + } + + } catch (Exception e) { + e.printStackTrace(); + fail("Caught exception running tests"); + } + + + testStr = getClass().getResourceAsStream("/query.tests"); + testsReader = new BufferedReader(new InputStreamReader(testStr)); + + try { + String testExpr = null; + + int testNum = 0; + while ((testExpr = testsReader.readLine()) != null) { + testExpr = testExpr.trim(); + if (testExpr.startsWith("#")) { + testExpr = testExpr.substring(1).trim(); + String[] nameValue = testExpr.split("="); + String name = nameValue[0].trim(); + String value = nameValue[1].trim(); + + LOG.info("Setting context attribute " + name + " = " + + value); + ctx.setAttribute(name, value); + + } else { + + testNum++; + + String sqlStmt = testExpr; + QueryStatus status = sqlResource.query("SQL", false, null, + sqlStmt, "querytest" + testNum, null, ctx); + + switch (status) { + case SUCCESS: + LOG.info("Found data for query [" + sqlStmt + "]"); + break; + case NOT_FOUND: + LOG.info("Did not data for query [" + sqlStmt + "]"); + break; + default: + fail("Failure executing query [" + sqlStmt + "]"); + + } + } + } + + } catch (Exception e) { + e.printStackTrace(); + fail("Caught exception running tests"); + } + + + testStr = getClass().getResourceAsStream("/delete.tests"); + testsReader = new BufferedReader(new InputStreamReader(testStr)); + + try { + String testExpr = null; + + int testNum = 0; + while ((testExpr = testsReader.readLine()) != null) { + testExpr = testExpr.trim(); + if (testExpr.startsWith("#")) { + testExpr = testExpr.substring(1).trim(); + String[] nameValue = testExpr.split("="); + String name = nameValue[0].trim(); + String value = nameValue[1].trim(); + + LOG.info("Setting context attribute " + name + " = " + + value); + ctx.setAttribute(name, value); + + } else { + + testNum++; + + String sqlStmt = testExpr; + QueryStatus status = sqlResource.delete("SQL", sqlStmt, ctx); + + switch (status) { + case SUCCESS: + LOG.info("Found data for query [" + sqlStmt + "]"); + break; + case NOT_FOUND: + LOG.info("Did not data for query [" + sqlStmt + "]"); + break; + default: + fail("Failure executing query [" + sqlStmt + "]"); + + } + } + } + + } catch (Exception e) { + e.printStackTrace(); + fail("Caught exception running tests"); + } + + for (String attrName : ctx.getAttributeKeySet()) { + LOG.info("ctx.getAttribute("+attrName+") = "+ctx.getAttribute(attrName)); + } + } + +} diff --git a/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResourceTest.java b/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResourceTest.java deleted file mode 100644 index 2d48ff3f..00000000 --- a/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResourceTest.java +++ /dev/null @@ -1,218 +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 org.onap.ccsdk.sli.adaptors.resource.sql; - -import java.io.BufferedReader; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.Enumeration; -import java.util.Properties; - -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 junit.framework.TestCase; - -public class SqlResourceTest extends TestCase { - - private static final Logger LOG = LoggerFactory - .getLogger(SqlResourceTest.class); - - - public void testExists() { - - - Properties props = new Properties(); - InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); - if (propStr == null) { - fail("src/test/resources/svclogic.properties missing"); - } - - try { - props.load(propStr); - propStr.close(); - } catch (Exception e) { - e.printStackTrace(); - fail("Could not initialize properties"); - } - - // Add properties to global properties - - Enumeration propNames = props.keys(); - - while (propNames.hasMoreElements()) { - String propName = (String) propNames.nextElement(); - - System.setProperty(propName, props.getProperty(propName)); - } - - SqlResource sqlResource = new SqlResource(); - - - - InputStream testStr = getClass().getResourceAsStream("/save.tests"); - BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); - SvcLogicContext ctx = new SvcLogicContext(); - - try { - String testExpr = null; - - int testNum = 0; - while ((testExpr = testsReader.readLine()) != null) { - testExpr = testExpr.trim(); - - if (testExpr.startsWith("#")) { - testExpr = testExpr.substring(1).trim(); - String[] nameValue = testExpr.split("="); - String name = nameValue[0].trim(); - String value = nameValue[1].trim(); - - LOG.info("Setting context attribute " + name + " = " - + value); - ctx.setAttribute(name, value); - - } else { - - testNum++; - String sqlStmt = testExpr; - QueryStatus status = sqlResource.save("SQL", true, false, sqlStmt, null, "savetest"+testNum, ctx); - - switch (status) { - case SUCCESS: - LOG.info("Found data for query [" + sqlStmt + "]"); - break; - case NOT_FOUND: - LOG.info("Did not data for query [" + sqlStmt + "]"); - break; - default: - fail("Failure executing query [" + sqlStmt + "]"); - - } - } - } - - } catch (Exception e) { - e.printStackTrace(); - fail("Caught exception running tests"); - } - - - testStr = getClass().getResourceAsStream("/query.tests"); - testsReader = new BufferedReader(new InputStreamReader(testStr)); - - try { - String testExpr = null; - - int testNum = 0; - while ((testExpr = testsReader.readLine()) != null) { - testExpr = testExpr.trim(); - if (testExpr.startsWith("#")) { - testExpr = testExpr.substring(1).trim(); - String[] nameValue = testExpr.split("="); - String name = nameValue[0].trim(); - String value = nameValue[1].trim(); - - LOG.info("Setting context attribute " + name + " = " - + value); - ctx.setAttribute(name, value); - - } else { - - testNum++; - - String sqlStmt = testExpr; - QueryStatus status = sqlResource.query("SQL", false, null, - sqlStmt, "querytest" + testNum, null, ctx); - - switch (status) { - case SUCCESS: - LOG.info("Found data for query [" + sqlStmt + "]"); - break; - case NOT_FOUND: - LOG.info("Did not data for query [" + sqlStmt + "]"); - break; - default: - fail("Failure executing query [" + sqlStmt + "]"); - - } - } - } - - } catch (Exception e) { - e.printStackTrace(); - fail("Caught exception running tests"); - } - - - testStr = getClass().getResourceAsStream("/delete.tests"); - testsReader = new BufferedReader(new InputStreamReader(testStr)); - - try { - String testExpr = null; - - int testNum = 0; - while ((testExpr = testsReader.readLine()) != null) { - testExpr = testExpr.trim(); - if (testExpr.startsWith("#")) { - testExpr = testExpr.substring(1).trim(); - String[] nameValue = testExpr.split("="); - String name = nameValue[0].trim(); - String value = nameValue[1].trim(); - - LOG.info("Setting context attribute " + name + " = " - + value); - ctx.setAttribute(name, value); - - } else { - - testNum++; - - String sqlStmt = testExpr; - QueryStatus status = sqlResource.delete("SQL", sqlStmt, ctx); - - switch (status) { - case SUCCESS: - LOG.info("Found data for query [" + sqlStmt + "]"); - break; - case NOT_FOUND: - LOG.info("Did not data for query [" + sqlStmt + "]"); - break; - default: - fail("Failure executing query [" + sqlStmt + "]"); - - } - } - } - - } catch (Exception e) { - e.printStackTrace(); - fail("Caught exception running tests"); - } - - for (String attrName : ctx.getAttributeKeySet()) { - LOG.info("ctx.getAttribute("+attrName+") = "+ctx.getAttribute(attrName)); - } - } - -} -- cgit 1.2.3-korg