2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
25 package org.onap.ccsdk.sli.core.sli;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.fail;
30 import java.io.BufferedReader;
31 import java.io.IOException;
32 import java.io.InputStream;
33 import java.io.InputStreamReader;
35 import java.util.Properties;
37 import ch.vorburger.mariadb4j.DB;
38 import ch.vorburger.mariadb4j.DBConfigurationBuilder;
40 import org.junit.After;
41 import org.junit.AfterClass;
42 import org.junit.Before;
43 import org.junit.BeforeClass;
44 import org.junit.Test;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
52 public class ITCaseSvcLogicParser {
54 private static SvcLogicStore store;
55 private static final Logger LOG = LoggerFactory.getLogger(SvcLogicJdbcStore.class);
58 public static void setUpBeforeClass() throws Exception {
60 LOG.info("before class");
62 URL propUrl = ITCaseSvcLogicParser.class.getResource("/svclogic.properties");
64 InputStream propStr = ITCaseSvcLogicParser.class.getResourceAsStream("/svclogic.properties");
66 Properties props = new Properties();
71 // Start MariaDB4j database
72 DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder();
73 config.setPort(0); // 0 => autom. detect free port
74 DB db = DB.newEmbeddedDB(config.build());
78 // Override jdbc URL and database name
79 props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test");
80 props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test"));
85 public static void tearDownAfterClass() throws Exception {
86 LOG.info("after class");
90 public void setUp() throws Exception {
95 public void tearDown() throws Exception {
100 * Test method for {@link org.onap.ccsdk.sli.core.sli.SvcLogicParser#parse(java.lang.String)}.
103 public void testParseValidXml() {
106 InputStream testStr = getClass().getResourceAsStream("/parser-good.tests");
107 BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
108 String testCaseFile = null;
109 while ((testCaseFile = testsReader.readLine()) != null) {
111 testCaseFile = testCaseFile.trim();
113 if (testCaseFile.length() > 0) {
114 if (!testCaseFile.startsWith("/")) {
115 testCaseFile = "/" + testCaseFile;
117 URL testCaseUrl = getClass().getResource(testCaseFile);
118 if (testCaseUrl == null) {
119 fail("Could not resolve test case file " + testCaseFile);
123 SvcLogicParser.validate(testCaseUrl.getPath(), store);
124 } catch (Exception e) {
125 fail("Validation failure [" + e.getMessage() + "]");
129 } catch (SvcLogicParserException e) {
130 fail("Parser error : " + e.getMessage());
131 } catch (Exception e) {
133 fail("Caught exception processing test cases");
137 @Test(expected = SvcLogicException.class)
138 public void testParseInvalidXml() throws SvcLogicException, IOException {
140 InputStream testStr = getClass().getResourceAsStream("/parser-bad.tests");
141 BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
143 while ((testCaseFile = testsReader.readLine()) != null) {
145 testCaseFile = testCaseFile.trim();
147 if (testCaseFile.length() > 0) {
148 if (!testCaseFile.startsWith("/")) {
149 testCaseFile = "/" + testCaseFile;
151 URL testCaseUrl = getClass().getResource(testCaseFile);
152 if (testCaseUrl == null) {
153 fail("Could not resolve test case file " + testCaseFile);
155 SvcLogicParser.load(testCaseUrl.getPath(), store);