From 3cb682fa71a1749fb99a47d7c8ede2b8984e2c07 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Tue, 16 Apr 2019 11:20:08 +0000 Subject: Fix Security and Unit Test DB issues This review removes more links to the Zookeeper version 3.5.4-beta with Zookeeper version 3.4.14. It also replaces the Derby in-memory database with the H2 in memory database for unit tests. Issue-ID: POLICY-1540 Change-Id: Ic44f2e866644114b7c0cf66aac7e528017b8206b Signed-off-by: liamfallon --- .../apex/model/basicmodel/dao/EntityTest.java | 18 ----------------- .../handling/SupportApexBasicModelTester.java | 17 +--------------- .../src/test/resources/META-INF/persistence.xml | 6 ++---- .../handling/ApexContextModelTest.java | 19 ++---------------- .../src/test/resources/META-INF/persistence.xml | 6 ++---- .../enginemodel/handling/ApexEngineModelTest.java | 23 ++++------------------ .../src/test/resources/META-INF/persistence.xml | 6 ++---- .../eventmodel/handling/ApexEventModelTest.java | 17 +--------------- .../src/test/resources/META-INF/persistence.xml | 6 ++---- .../apex/model/modelapi/ApexModelApiTest.java | 12 +++++------ .../src/test/resources/META-INF/persistence.xml | 8 +++----- .../policymodel/handling/ApexPolicyModelTest.java | 23 ++++------------------ .../src/test/resources/META-INF/persistence.xml | 6 ++---- model/pom.xml | 17 ++++++++-------- 14 files changed, 39 insertions(+), 145 deletions(-) (limited to 'model') diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java index 0258b9305..36b18d783 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/dao/EntityTest.java @@ -26,17 +26,12 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.TreeSet; import java.util.UUID; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey; @@ -48,21 +43,8 @@ import org.onap.policy.apex.model.basicmodel.concepts.DummyEntity; * JUnit test class. */ public class EntityTest { - private Connection connection; private ApexDao apexDao; - @Before - public void setup() throws Exception { - Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); - } - - @After - public void teardown() throws Exception { - connection.close(); - new File("derby.log").delete(); - } - @Test public void testEntityTestSanity() throws ApexException { final DaoParameters daoParameters = new DaoParameters(); diff --git a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java index a89be5477..375d15ae8 100644 --- a/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java +++ b/model/basic-model/src/test/java/org/onap/policy/apex/model/basicmodel/handling/SupportApexBasicModelTester.java @@ -23,11 +23,6 @@ package org.onap.policy.apex.model.basicmodel.handling; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; - -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.ApexException; @@ -37,28 +32,18 @@ import org.onap.policy.apex.model.basicmodel.dao.DaoParameters; import org.onap.policy.apex.model.basicmodel.test.TestApexModel; public class SupportApexBasicModelTester { - private Connection connection; TestApexModel testApexModel; /** * Set up the test. - * + * * @throws Exception any exception thrown by the test */ @Before public void setup() throws Exception { - Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); - testApexModel = new TestApexModel(AxModel.class, new DummyApexBasicModelCreator()); } - @After - public void teardown() throws Exception { - connection.close(); - new File("derby.log").delete(); - } - @Test public void testModelValid() throws Exception { final AxValidationResult result = testApexModel.testApexModelValid(); diff --git a/model/basic-model/src/test/resources/META-INF/persistence.xml b/model/basic-model/src/test/resources/META-INF/persistence.xml index 68f03e8e5..01a8989bb 100644 --- a/model/basic-model/src/test/resources/META-INF/persistence.xml +++ b/model/basic-model/src/test/resources/META-INF/persistence.xml @@ -33,10 +33,8 @@ org.onap.policy.apex.model.basicmodel.concepts.DummyEntity - - - - + + diff --git a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java index 948c2024c..f41c39fd2 100644 --- a/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java +++ b/model/context-model/src/test/java/org/onap/policy/apex/model/contextmodel/handling/ApexContextModelTest.java @@ -22,11 +22,6 @@ package org.onap.policy.apex.model.contextmodel.handling; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; - -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; @@ -36,33 +31,23 @@ import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel; /** * Apex context model tests. - * + * * @author liam * */ public class ApexContextModelTest { - private Connection connection; TestApexModel testApexModel; /** * Set up tests. - * + * * @throws Exception a testing exception */ @Before public void setup() throws Exception { - Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); - testApexModel = new TestApexModel(AxContextModel.class, new TestApexContextModelCreator()); } - @After - public void teardown() throws Exception { - connection.close(); - new File("derby.log").delete(); - } - @Test public void testModelValid() throws Exception { final AxValidationResult result = testApexModel.testApexModelValid(); diff --git a/model/context-model/src/test/resources/META-INF/persistence.xml b/model/context-model/src/test/resources/META-INF/persistence.xml index b7911caa2..b4ba68a38 100644 --- a/model/context-model/src/test/resources/META-INF/persistence.xml +++ b/model/context-model/src/test/resources/META-INF/persistence.xml @@ -38,10 +38,8 @@ org.onap.policy.apex.model.contextmodel.concepts.AxContextModel - - - - + + diff --git a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java index d0b8f3e78..770c29a93 100644 --- a/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java +++ b/model/engine-model/src/test/java/org/onap/policy/apex/model/enginemodel/handling/ApexEngineModelTest.java @@ -5,15 +5,15 @@ * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -22,11 +22,6 @@ package org.onap.policy.apex.model.enginemodel.handling; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; - -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; @@ -35,28 +30,18 @@ import org.onap.policy.apex.model.basicmodel.test.TestApexModel; import org.onap.policy.apex.model.enginemodel.concepts.AxEngineModel; public class ApexEngineModelTest { - private Connection connection; TestApexModel testApexModel; /** * Set up the test. - * + * * @throws Exception errors from test setup */ @Before public void setup() throws Exception { - Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); - testApexModel = new TestApexModel(AxEngineModel.class, new DummyTestApexEngineModelCreator()); } - @After - public void teardown() throws Exception { - connection.close(); - new File("derby.log").delete(); - } - @Test public void testModelValid() throws Exception { final AxValidationResult result = testApexModel.testApexModelValid(); diff --git a/model/engine-model/src/test/resources/META-INF/persistence.xml b/model/engine-model/src/test/resources/META-INF/persistence.xml index a157cf34f..42048d85d 100644 --- a/model/engine-model/src/test/resources/META-INF/persistence.xml +++ b/model/engine-model/src/test/resources/META-INF/persistence.xml @@ -59,10 +59,8 @@ org.onap.policy.apex.model.enginemodel.concepts.AxEngineStats - - - - + + diff --git a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java index 88736d1f0..db752a61b 100644 --- a/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java +++ b/model/event-model/src/test/java/org/onap/policy/apex/model/eventmodel/handling/ApexEventModelTest.java @@ -22,11 +22,6 @@ package org.onap.policy.apex.model.eventmodel.handling; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; - -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; @@ -35,28 +30,18 @@ import org.onap.policy.apex.model.basicmodel.test.TestApexModel; import org.onap.policy.apex.model.eventmodel.concepts.AxEventModel; public class ApexEventModelTest { - private Connection connection; TestApexModel testApexModel; /** * Set up the test. - * + * * @throws Exception exceptions from the test */ @Before public void setup() throws Exception { - Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); - testApexModel = new TestApexModel(AxEventModel.class, new DummyTestApexEventModelCreator()); } - @After - public void teardown() throws Exception { - connection.close(); - new File("derby.log").delete(); - } - @Test public void testModelValid() throws Exception { final AxValidationResult result = testApexModel.testApexModelValid(); diff --git a/model/event-model/src/test/resources/META-INF/persistence.xml b/model/event-model/src/test/resources/META-INF/persistence.xml index 9e61cbd73..0184cada6 100644 --- a/model/event-model/src/test/resources/META-INF/persistence.xml +++ b/model/event-model/src/test/resources/META-INF/persistence.xml @@ -44,10 +44,8 @@ org.onap.policy.apex.model.eventmodel.concepts.AxEventModel - - - - + + diff --git a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java index 462b1cd8b..df5e54ca9 100644 --- a/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java +++ b/model/model-api/src/test/java/org/onap/policy/apex/model/modelapi/ApexModelApiTest.java @@ -5,15 +5,15 @@ * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -48,14 +48,14 @@ public class ApexModelApiTest { @Before public void setup() throws Exception { - Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); + // Hold the h2 database up for entire tests + connection = DriverManager.getConnection("jdbc:h2:mem:testdb"); } @After public void teardown() throws Exception { + // Close the h2 database after tests connection.close(); - new File("derby.log").delete(); } @Test diff --git a/model/model-api/src/test/resources/META-INF/persistence.xml b/model/model-api/src/test/resources/META-INF/persistence.xml index f834e0f49..2603d5496 100644 --- a/model/model-api/src/test/resources/META-INF/persistence.xml +++ b/model/model-api/src/test/resources/META-INF/persistence.xml @@ -57,11 +57,9 @@ org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel - - - - - + + + diff --git a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java index 7a240e18b..a521272ae 100644 --- a/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java +++ b/model/policy-model/src/test/java/org/onap/policy/apex/model/policymodel/handling/ApexPolicyModelTest.java @@ -5,15 +5,15 @@ * 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. - * + * * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ @@ -23,11 +23,6 @@ package org.onap.policy.apex.model.policymodel.handling; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import java.io.File; -import java.sql.Connection; -import java.sql.DriverManager; - -import org.junit.After; import org.junit.Before; import org.junit.Test; import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult; @@ -36,28 +31,18 @@ import org.onap.policy.apex.model.basicmodel.test.TestApexModel; import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel; public class ApexPolicyModelTest { - private Connection connection; TestApexModel testApexModel; /** * Set up the policy model tests. - * + * * @throws Exception on setup errors */ @Before public void setup() throws Exception { - Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance(); - connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true"); - testApexModel = new TestApexModel(AxPolicyModel.class, new SupportApexPolicyModelCreator()); } - @After - public void teardown() throws Exception { - connection.close(); - new File("derby.log").delete(); - } - @Test public void testModelValid() throws Exception { final AxValidationResult result = testApexModel.testApexModelValid(); diff --git a/model/policy-model/src/test/resources/META-INF/persistence.xml b/model/policy-model/src/test/resources/META-INF/persistence.xml index cd9a420d0..0eee729a1 100644 --- a/model/policy-model/src/test/resources/META-INF/persistence.xml +++ b/model/policy-model/src/test/resources/META-INF/persistence.xml @@ -57,10 +57,8 @@ org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel - - - - + + diff --git a/model/pom.xml b/model/pom.xml index 187a043da..2ff6aa110 100644 --- a/model/pom.xml +++ b/model/pom.xml @@ -32,15 +32,6 @@ ${project.artifactId} The model for Apex, it comtains definitions of all Apex concepts and also has handling for Apex models. - - - org.apache.derby - derby - ${version.derby} - test - - - utilities basic-model @@ -51,6 +42,14 @@ model-api + + + com.h2database + h2 + test + + + apexSite -- cgit 1.2.3-korg