From bebf6ea5839c87799602da01b166000f8b746b86 Mon Sep 17 00:00:00 2001 From: Gaurav Agrawal Date: Wed, 27 Sep 2017 16:13:04 +0530 Subject: Refinements to core Changes includes: 1. Simplifying the test cases. 2. Critical Sonar issue fix for MdsalHelper 3. Critical sonar issue fix for SvcLogicServiceImpl 4. Use logger in-built formatting. https://sonar.onap.org/component_issues/index?id=org.onap.ccsdk.sli.core%3Accsdk-sli-core#resolved=false|severities=CRITICAL Change-Id: Ib85637fcd2351970f8d96bf6b855db05cf7d9834 Issue-Id: CCSDK-67 Signed-off-by: Gaurav Agrawal --- .../ccsdk/sli/core/sli/ITCaseSvcLogicParser.java | 191 +++++++++------------ 1 file changed, 78 insertions(+), 113 deletions(-) (limited to 'sli/common/src/test/java/org/onap/ccsdk/sli/core/sli/ITCaseSvcLogicParser.java') 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 7af4c1c5..0912ee9f 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 @@ -28,6 +28,7 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.fail; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URL; @@ -103,117 +104,81 @@ public class ITCaseSvcLogicParser { store.registerNodeType("save"); store.registerNodeType("update"); store.registerNodeType("break"); - } - - @Before - public void setUp() throws Exception { - LOG.info("before"); - } - - @After - public void tearDown() throws Exception { - LOG.info("after"); - } - - @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; - while ((testCaseFile = testsReader.readLine()) != null) { - - testCaseFile = testCaseFile.trim(); - - if (testCaseFile.length() > 0) - { - if (!testCaseFile.startsWith("/")) - { - testCaseFile = "/"+testCaseFile; - } - URL testCaseUrl = getClass().getResource(testCaseFile); - if (testCaseUrl == null) - { - fail("Could not resolve test case file "+testCaseFile); - } - - try { - 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() { - - 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(); - - if (testCaseFile.length() > 0) - { - if (!testCaseFile.startsWith("/")) - { - testCaseFile = "/"+testCaseFile; - } - URL testCaseUrl = getClass().getResource(testCaseFile); - if (testCaseUrl == null) - { - fail("Could not resolve test case file "+testCaseFile); - } - - boolean valid = true; - try { - SvcLogicParser.load(testCaseUrl.getPath(), store); - } catch (Exception e) { - System.out.println(e.getMessage()); - valid = false; - } - - if (valid) { - fail("Expected compiler error on "+testCaseFile+", but got success"); - } - } - } - } - catch (SvcLogicParserException e) - { - fail("Parser error : "+e.getMessage()); - } - catch (Exception e) - { - LOG.error("", e); - fail("Caught exception processing test cases"); - } - - } - + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + LOG.info("after class"); + } + + @Before + public void setUp() throws Exception { + LOG.info("before"); + } + + @After + public void tearDown() throws Exception { + LOG.info("after"); + } + + /** + * 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; + while ((testCaseFile = testsReader.readLine()) != null) { + + testCaseFile = testCaseFile.trim(); + + if (testCaseFile.length() > 0) { + if (!testCaseFile.startsWith("/")) { + testCaseFile = "/" + testCaseFile; + } + URL testCaseUrl = getClass().getResource(testCaseFile); + if (testCaseUrl == null) { + fail("Could not resolve test case file " + testCaseFile); + } + + try { + 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(expected = SvcLogicException.class) + public void testParseInvalidXml() throws SvcLogicException, IOException { + + InputStream testStr = getClass().getResourceAsStream("/parser-bad.tests"); + BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr)); + String testCaseFile; + while ((testCaseFile = testsReader.readLine()) != null) { + + testCaseFile = testCaseFile.trim(); + + if (testCaseFile.length() > 0) { + if (!testCaseFile.startsWith("/")) { + testCaseFile = "/" + testCaseFile; + } + URL testCaseUrl = getClass().getResource(testCaseFile); + if (testCaseUrl == null) { + fail("Could not resolve test case file " + testCaseFile); + } + SvcLogicParser.load(testCaseUrl.getPath(), store); + } + } + } } -- cgit 1.2.3-korg