diff options
author | Dan Timoney <dtimoney@att.com> | 2017-09-19 23:58:10 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-19 23:58:10 +0000 |
commit | 9a236162e1c3fd5dcc425544c5ecf5290b0fafb2 (patch) | |
tree | 0e104585832f110fe33f3b3624777c394247b698 | |
parent | 5469072378877daa9e9d709fa0f49bacc04e3e1d (diff) | |
parent | a07f58226c3a42ed2e658d06806df74252e909cc (diff) |
Merge "Use Junit4 instead of Junit3 in sli/common"
-rwxr-xr-x | sli/common/pom.xml | 2 | ||||
-rw-r--r-- | sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java | 137 |
2 files changed, 85 insertions, 54 deletions
diff --git a/sli/common/pom.xml b/sli/common/pom.xml index e6bac8ad..bd9ec696 100755 --- a/sli/common/pom.xml +++ b/sli/common/pom.xml @@ -16,7 +16,7 @@ <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>3.8.1</version> + <version>${junit.version}</version> <scope>test</scope> </dependency> <dependency> diff --git a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java index 07f40a2e..8bf748aa 100644 --- a/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java +++ b/sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java @@ -24,6 +24,9 @@ */ package org.onap.ccsdk.sli.core.sli; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; @@ -32,69 +35,92 @@ import java.util.Properties; import ch.vorburger.mariadb4j.DB; import ch.vorburger.mariadb4j.DBConfigurationBuilder; -import junit.framework.TestCase; + +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author dt5972 * */ -public class ITCaseSvcLogicParser extends TestCase { - - /** - * Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}. - */ +public class ITCaseSvcLogicParser { + private static SvcLogicStore store; + private static final Logger LOG = LoggerFactory.getLogger(SvcLogicJdbcStore.class); - public void testParse() { + @BeforeClass + public static void setUpBeforeClass() throws Exception { + LOG.info("before class"); - try - { - + URL propUrl = ITCaseSvcLogicParser.class.getResource("/svclogic.properties"); + InputStream propStr = ITCaseSvcLogicParser.class.getResourceAsStream("/svclogic.properties"); - URL propUrl = getClass().getResource("/svclogic.properties"); + Properties props = new Properties(); - InputStream propStr = getClass().getResourceAsStream("/svclogic.properties"); + props.load(propStr); - Properties props = new Properties(); - props.load(propStr); + // Start MariaDB4j database + DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); + config.setPort(0); // 0 => autom. detect free port + DB db = DB.newEmbeddedDB(config.build()); + db.start(); - // Start MariaDB4j database - DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder(); - config.setPort(0); // 0 => autom. detect free port - DB db = DB.newEmbeddedDB(config.build()); - db.start(); + // Override jdbc URL and database name + props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); + props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); + store = SvcLogicStoreFactory.getSvcLogicStore(props); - // Override jdbc URL and database name - props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test"); - props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test")); - + assertNotNull(store); + store.registerNodeType("switch"); + store.registerNodeType("block"); + store.registerNodeType("get-resource"); + store.registerNodeType("reserve"); + store.registerNodeType("is-available"); + store.registerNodeType("exists"); + store.registerNodeType("configure"); + store.registerNodeType("return"); + store.registerNodeType("record"); + store.registerNodeType("allocate"); + store.registerNodeType("release"); + store.registerNodeType("for"); + store.registerNodeType("set"); + } - SvcLogicStore store = SvcLogicStoreFactory.getSvcLogicStore(props); + @Before + public void setUp() throws Exception { + LOG.info("before"); + } - assertNotNull(store); + @After + public void tearDown() throws Exception { + LOG.info("after"); + } - store.registerNodeType("switch"); - store.registerNodeType("block"); - store.registerNodeType("get-resource"); - store.registerNodeType("reserve"); - store.registerNodeType("is-available"); - store.registerNodeType("exists"); - store.registerNodeType("configure"); - store.registerNodeType("return"); - store.registerNodeType("record"); - store.registerNodeType("allocate"); - store.registerNodeType("release"); - store.registerNodeType("for"); - store.registerNodeType("set"); + @AfterClass + public static void tearDownAfterClass() throws Exception { + LOG.info("after class"); + } + /** + * Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}. + */ + @Test + public void testParseValidXml() { + try + { InputStream testStr = getClass().getResourceAsStream("/parser-good.tests"); BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); String testCaseFile = null; @@ -118,19 +144,29 @@ public class ITCaseSvcLogicParser extends TestCase { SvcLogicParser.validate(testCaseUrl.getPath(), store); } catch (Exception e) { fail("Validation failure ["+e.getMessage()+"]"); - } - - - - - } } + } + catch (SvcLogicParserException e) + { + fail("Parser error : "+e.getMessage()); + } + catch (Exception e) + { + LOG.error("", e); + fail("Caught exception processing test cases"); + } + } + + @Test + public void testParseInvalidXml() { - testStr = getClass().getResourceAsStream("/parser-bad.tests"); - testsReader = new BufferedReader(new InputStreamReader(testStr)); - testCaseFile = null; + try + { + InputStream testStr = getClass().getResourceAsStream("/parser-bad.tests"); + BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); + String testCaseFile = null; while ((testCaseFile = testsReader.readLine()) != null) { testCaseFile = testCaseFile.trim(); @@ -158,8 +194,6 @@ public class ITCaseSvcLogicParser extends TestCase { if (valid) { fail("Expected compiler error on "+testCaseFile+", but got success"); } - - } } } @@ -169,13 +203,10 @@ public class ITCaseSvcLogicParser extends TestCase { } catch (Exception e) { - e.printStackTrace(); + LOG.error("", e); fail("Caught exception processing test cases"); } - } - - } |