From a07f58226c3a42ed2e658d06806df74252e909cc Mon Sep 17 00:00:00 2001 From: "ramu.n" Date: Wed, 20 Sep 2017 02:17:00 +0530 Subject: Use Junit4 instead of Junit3 in sli/common Modified sli/common pom.xml file to take Junit version from parent pom file and modified one Testfile as per Junit4 Change-Id: Iee4397125d9873def60c77ba8be5d541e0df62fa Issue-Id: CCSDK-98 Signed-off-by: Ramu N --- sli/common/pom.xml | 2 +- .../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 e6bac8ada..bd9ec696a 100755 --- a/sli/common/pom.xml +++ b/sli/common/pom.xml @@ -16,7 +16,7 @@ junit junit - 3.8.1 + ${junit.version} test 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 07f40a2ec..8bf748aa4 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"); } - } - - } -- cgit 1.2.3-korg