Fix database properties 85/85085/1
authorliamfallon <liam.fallon@est.tech>
Thu, 11 Apr 2019 15:59:47 +0000 (15:59 +0000)
committerliamfallon <liam.fallon@est.tech>
Thu, 11 Apr 2019 15:59:47 +0000 (15:59 +0000)
Issue-ID: POLICY-1095
Change-Id: I3edd70898836d3bd978643857d1ba29599b1cf6c
Signed-off-by: liamfallon <liam.fallon@est.tech>
20 files changed:
models-dao/src/test/java/org/onap/policy/models/dao/EntityTest.java
models-dao/src/test/resources/META-INF/persistence.xml
models-pdp/src/test/java/org/onap/policy/models/pdp/persistence/provider/PdpProviderTest.java
models-pdp/src/test/resources/META-INF/persistence.xml
models-provider/src/main/java/org/onap/policy/models/provider/PolicyModelsProviderParameters.java
models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
models-provider/src/test/java/org/onap/policy/models/provider/PolicyModelsProviderParametersTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyGuardPersistenceTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyLegacyOperationalPersistenceTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyPersistenceTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyToscaPersistenceTest.java
models-provider/src/test/java/org/onap/policy/models/provider/impl/PolicyTypePersistenceTest.java
models-provider/src/test/resources/META-INF/persistence.xml
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/provider/AuthorativeToscaProviderPolicyTypeTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyGuardTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/legacy/provider/LegacyProvider4LegacyOperationalTest.java
models-tosca/src/test/java/org/onap/policy/models/tosca/simple/provider/SimpleToscaProviderTest.java
models-tosca/src/test/resources/META-INF/persistence.xml

index 4bf39a0..863eda1 100644 (file)
@@ -26,16 +26,13 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Properties;
 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.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfModelException;
@@ -49,23 +46,20 @@ import org.onap.policy.models.dao.impl.DefaultPfDao;
  * JUnit test class.
  */
 public class EntityTest {
-    private Connection connection;
     private PfDao pfDao;
 
-    @Before
-    public void setup() throws Exception {
-        connection = DriverManager.getConnection("jdbc:h2:mem:test");
-    }
-
-    @After
-    public void teardown() throws Exception {
-        connection.close();
-    }
-
     @Test
     public void testEntityTestSanity() throws PfModelException {
         final DaoParameters daoParameters = new DaoParameters();
 
+        Properties jdbcProperties = new Properties();
+        jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
+        jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:testdb");
+        jdbcProperties.setProperty("javax.persistence.jdbc.user", "sa");
+        jdbcProperties.setProperty("javax.persistence.jdbc.password", "");
+
+        daoParameters.setJdbcProperties(jdbcProperties);
+
         pfDao = new PfDaoFactory().createPfDao(daoParameters);
 
         try {
@@ -101,10 +95,19 @@ public class EntityTest {
 
     @Test
     public void testEntityTestAllOpsJpa() throws PfModelException {
+
         final DaoParameters daoParameters = new DaoParameters();
         daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
         daoParameters.setPersistenceUnit("DaoTest");
 
+        Properties jdbcProperties = new Properties();
+        jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
+        jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:testdb");
+        jdbcProperties.setProperty("javax.persistence.jdbc.user", "sa");
+        jdbcProperties.setProperty("javax.persistence.jdbc.password", "");
+
+        daoParameters.setJdbcProperties(jdbcProperties);
+
         pfDao = new PfDaoFactory().createPfDao(daoParameters);
         pfDao.init(daoParameters);
 
index 25858ca..5314ebb 100644 (file)
         <class>org.onap.policy.models.dao.DummyReferenceEntity</class>
 
         <properties>
-            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
-            <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb" />
-            <property name="javax.persistence.jdbc.user" value="sa" />
-            <property name="javax.persistence.jdbc.password" value="" />
             <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
             <property name="eclipselink.ddl-generation.output-mode" value="database" />
             <property name="eclipselink.logging.level" value="INFO" />
index bc77e4b..3b37168 100644 (file)
@@ -26,10 +26,9 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotEquals;
 import static org.junit.Assert.assertTrue;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Properties;
 
 import org.junit.After;
 import org.junit.Before;
@@ -60,7 +59,6 @@ import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class PdpProviderTest {
-    private Connection connection;
     private PfDao pfDao;
     private StandardCoder standardCoder;
 
@@ -72,17 +70,25 @@ public class PdpProviderTest {
      */
     @Before
     public void setupDao() throws Exception {
-        // Use the JDBC UI "jdbc:h2:mem:testdb" to test towards the h2 database
-        // Use the JDBC UI "jdbc:mariadb://localhost:3306/policy" to test towards a locally installed mariadb instance
-        connection = DriverManager.getConnection("jdbc:h2:mem:testdb", "policy", "P01icY");
-
         final DaoParameters daoParameters = new DaoParameters();
         daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
 
-        // Use the persistence unit ToscaConceptTest to test towards the h2 database
-        // Use the persistence unit ToscaConceptMariaDBTest to test towards a locally installed mariadb instance
         daoParameters.setPersistenceUnit("ToscaConceptTest");
 
+        Properties jdbcProperties = new Properties();
+        jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy");
+        jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY");
+
+        // H2
+        jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
+        jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:testdb");
+
+        // MariaDB
+        //jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+        //jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy");
+
+        daoParameters.setJdbcProperties(jdbcProperties );
+
         pfDao = new PfDaoFactory().createPfDao(daoParameters);
         pfDao.init(daoParameters);
     }
@@ -98,7 +104,6 @@ public class PdpProviderTest {
     @After
     public void teardown() throws Exception {
         pfDao.close();
-        connection.close();
     }
 
     @Test
@@ -416,13 +421,6 @@ public class PdpProviderTest {
             new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", "1.2.3", existingSubGroup);
         }).hasMessageContaining("INVALID:the desired instance count of a PDP sub group may not be negative");
         existingSubGroup.setDesiredInstanceCount(10);
-
-        existingSubGroup.setPdpType("Loooooooooooooooooooooooooooooooooooooooo"
-                + "ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongKey");
-        assertThatThrownBy(() -> {
-            new PdpProvider().updatePdpSubGroup(pfDao, "PdpGroup0", "1.2.3", existingSubGroup);
-        }).hasMessageContaining("Value too long for column");
-        existingSubGroup.setPdpType("APEX");
     }
 
     @Test
index 079ba49..9d78e3a 100644 (file)
         <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
 
         <properties>
-            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
-            <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb" />
-            <property name="javax.persistence.jdbc.user" value="policy" />
-            <property name="javax.persistence.jdbc.password" value="P01icY" />
             <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
             <property name="eclipselink.ddl-generation.output-mode" value="database" />
             <property name="eclipselink.logging.level" value="INFO" />
-        </properties>
-    </persistence-unit>
-
-    <persistence-unit name="ToscaConceptMariaDBTest" transaction-type="RESOURCE_LOCAL">
-        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
-        <class>org.onap.policy.models.dao.converters.CDataConditioner</class>
-        <class>org.onap.policy.models.dao.converters.Uuid2String</class>
-        <class>org.onap.policy.models.base.PfConceptKey</class>
-        <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
-        <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
-        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
-        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
-        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
-
-        <properties>
-            <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
-            <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/policy" />
-            <property name="javax.persistence.jdbc.user" value="policy" />
-            <property name="javax.persistence.jdbc.password" value="P01icY" />
-            <property name="javax.persistence.schema-generation.database.action" value="create" />
 
             <property name="eclipselink.logging.level" value="ALL" />
             <property name="eclipselink.logging.level.jpa" value="ALL" />
             <property name="eclipselink.logging.level.server" value="ALL" />
             <property name="eclipselink.logging.level.query" value="ALL" />
             <property name="eclipselink.logging.level.properties" value="ALL" />
-
-            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
-            <property name="eclipselink.ddl-generation.output-mode" value="database" />
-            <property name="eclipselink.logging.level" value="INFO" />
         </properties>
     </persistence-unit>
 </persistence>
index 5abafed..65aa72e 100644 (file)
@@ -55,6 +55,7 @@ public class PolicyModelsProviderParameters implements ParameterGroup {
 
     private String name;
     private String implementation = DEFAULT_IMPLEMENTATION;
+    private String databaseDriver;
     private String databaseUrl;
     private String databaseUser;
     private String databasePassword;
@@ -73,6 +74,11 @@ public class PolicyModelsProviderParameters implements ParameterGroup {
                     "a PolicyModelsProvider implementation must be specified");
         }
 
+        if (!ParameterValidationUtils.validateStringParameter(databaseDriver)) {
+            validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
+                    "a driver must be specified for the JDBC connection to the database");
+        }
+
         if (!ParameterValidationUtils.validateStringParameter(databaseUrl)) {
             validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
                     "a URL must be specified for the JDBC connection to the database");
index cc70df9..475e576 100644 (file)
 
 package org.onap.policy.models.provider.impl;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
 import java.util.Base64;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 
 import javax.ws.rs.core.Response;
 
@@ -64,12 +63,20 @@ import org.slf4j.LoggerFactory;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
+
     private static final Logger LOGGER = LoggerFactory.getLogger(DefaultPfDao.class);
 
+    // Constants for persistence properties
+    // @formatter:off
+    private static final String JAVAX_PERSISTENCE_JDBC_DRIVER = "javax.persistence.jdbc.driver";
+    private static final String JAVAX_PERSISTENCE_JDBC_URL    = "javax.persistence.jdbc.url";
+    private static final String JAVAX_PERSISTENCE_JDBC_USER   = "javax.persistence.jdbc.user";
+    private static final String JAVAX_PERSISTENCE_JDBC_PWORD  = "javax.persistence.jdbc.password";
+    // @formatter:on
+
     private final PolicyModelsProviderParameters parameters;
 
     // Database connection and the DAO for reading and writing Policy Framework concepts
-    private Connection connection;
     private PfDao pfDao;
 
     /**
@@ -86,30 +93,31 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
         LOGGER.debug("opening the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
                 parameters.getPersistenceUnit());
 
-        if (connection != null || pfDao != null) {
+        if (pfDao != null) {
             String errorMessage = "provider is already initialized";
             LOGGER.warn(errorMessage);
             throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage);
         }
 
-        // Decode the password using Base64
-        String decodedPassword = new String(Base64.getDecoder().decode(parameters.getDatabasePassword()));
-
-        // Connect to the database, call does not implement AutoCloseable for try-with-resources
-        try {
-            connection = DriverManager.getConnection(parameters.getDatabaseUrl(), parameters.getDatabaseUser(),
-                    decodedPassword);
-        } catch (Exception exc) {
-            String errorMessage = "could not connect to database with URL \"" + parameters.getDatabaseUrl() + "\"";
-            LOGGER.warn(errorMessage, exc);
-            throw new PfModelException(Response.Status.NOT_ACCEPTABLE, errorMessage, exc);
-        }
-
         // Parameters for the DAO
         final DaoParameters daoParameters = new DaoParameters();
         daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
         daoParameters.setPersistenceUnit(parameters.getPersistenceUnit());
 
+        // Decode the password using Base64
+        String decodedPassword = new String(Base64.getDecoder().decode(parameters.getDatabasePassword()));
+
+        // @formatter:off
+        Properties jdbcProperties = new Properties();
+        jdbcProperties.setProperty(JAVAX_PERSISTENCE_JDBC_DRIVER, parameters.getDatabaseDriver());
+        jdbcProperties.setProperty(JAVAX_PERSISTENCE_JDBC_URL,    parameters.getDatabaseUrl());
+        jdbcProperties.setProperty(JAVAX_PERSISTENCE_JDBC_USER,   parameters.getDatabaseUser());
+        jdbcProperties.setProperty(JAVAX_PERSISTENCE_JDBC_PWORD,  decodedPassword);
+        // @formatter:on
+
+        daoParameters.setJdbcProperties(jdbcProperties);
+
+        pfDao = new PfDaoFactory().createPfDao(daoParameters);
         try {
             pfDao = new PfDaoFactory().createPfDao(daoParameters);
             pfDao.init(daoParameters);
@@ -133,20 +141,6 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
             pfDao = null;
         }
 
-        if (connection != null) {
-            try {
-                connection.close();
-            } catch (Exception exc) {
-
-                String errorMessage =
-                        "could not close connection to database with URL \"" + parameters.getDatabaseUrl() + "\"";
-                LOGGER.warn(errorMessage, exc);
-                throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, errorMessage, exc);
-            } finally {
-                connection = null;
-            }
-        }
-
         LOGGER.debug("closed the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),
                 parameters.getPersistenceUnit());
     }
@@ -328,8 +322,8 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
     }
 
     @Override
-    public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion,
-            @NonNull String pdpSubGroup, @NonNull Pdp pdp) throws PfModelException {
+    public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion, @NonNull String pdpSubGroup,
+            @NonNull Pdp pdp) throws PfModelException {
         new PdpProvider().updatePdp(pfDao, pdpGroupName, pdpGroupVersion, pdpSubGroup, pdp);
     }
 
@@ -364,13 +358,4 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
             throw new PfModelRuntimeException(Response.Status.BAD_REQUEST, errorMessage);
         }
     }
-
-    /**
-     * Hook for unit test mocking of database connection.
-     *
-     * @param client the mocked client
-     */
-    protected void setConnection(final Connection connection) {
-        this.connection = connection;
-    }
 }
index 626d2bf..2f3f89c 100644 (file)
@@ -36,6 +36,7 @@ public class PolicyModelsProviderParametersTest {
     @Test
     public void testParameters() {
         PolicyModelsProviderParameters pars = new PolicyModelsProviderParameters();
+        pars.setDatabaseDriver("MichaelsShumacher");
         pars.setDatabaseUrl("jdbc://www.acmecorp/roadrunner");
         pars.setPersistenceUnit("WileECoyote");
 
index 99358c4..ff8dfe3 100644 (file)
@@ -66,11 +66,11 @@ public class DatabasePolicyModelsProviderTest {
     @Before
     public void setupParameters() {
         parameters = new PolicyModelsProviderParameters();
+        parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
         parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
         parameters.setPersistenceUnit("ToscaConceptTest");
-
     }
 
     @Test
@@ -84,27 +84,21 @@ public class DatabasePolicyModelsProviderTest {
 
         parameters.setDatabaseUrl("jdbc://www.acmecorp.nonexist");
 
-        assertThatThrownBy(() -> {
-            databaseProvider.close();
-            databaseProvider.init();
-        }).hasMessage("could not connect to database with URL \"jdbc://www.acmecorp.nonexist\"");
-
-        parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
-
         try {
-            databaseProvider.init();
             databaseProvider.close();
+            databaseProvider.init();
         } catch (Exception pfme) {
             fail("test shold not throw an exception here");
         }
+        databaseProvider.close();
+
+        parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
 
         parameters.setPersistenceUnit("WileECoyote");
 
-        String errorMessage = "could not create Data Access Object (DAO) using url "
-                + "\"jdbc:h2:mem:testdb\" and persistence unit \"WileECoyote\"";
         assertThatThrownBy(() -> {
             databaseProvider.init();
-        }).hasMessage(errorMessage);
+        }).hasMessageContaining("could not create Data Access Object (DAO)");
 
         parameters.setPersistenceUnit("ToscaConceptTest");
 
@@ -112,6 +106,7 @@ public class DatabasePolicyModelsProviderTest {
             databaseProvider.init();
             databaseProvider.close();
         } catch (Exception pfme) {
+            pfme.printStackTrace();
             fail("test shold not throw an exception here");
         }
 
@@ -131,13 +126,6 @@ public class DatabasePolicyModelsProviderTest {
         } catch (Exception pfme) {
             fail("test shold not throw an exception here");
         }
-
-        assertThatThrownBy(() -> {
-            DatabasePolicyModelsProviderImpl databaseProviderImpl = (DatabasePolicyModelsProviderImpl) databaseProvider;
-            databaseProvider.init();
-            databaseProviderImpl.setConnection(new DummyConnection());
-            databaseProvider.close();
-        }).hasMessage("could not close connection to database with URL \"jdbc:h2:mem:testdb\"");
     }
 
     @Test
index 5ebb448..741ae89 100644 (file)
@@ -76,6 +76,7 @@ public class PolicyLegacyGuardPersistenceTest {
     @Before
     public void setupParameters() throws PfModelException {
         PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
+        parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
         parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
index af6c4a4..2e33a11 100644 (file)
@@ -76,6 +76,7 @@ public class PolicyLegacyOperationalPersistenceTest {
     @Before
     public void setupParameters() throws PfModelException {
         PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
+        parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
         parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
index 81795db..668f634 100644 (file)
@@ -85,6 +85,7 @@ public class PolicyPersistenceTest {
     @Before
     public void setupParameters() throws PfModelException {
         PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
+        parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
         parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
index 8f05244..613c5a2 100644 (file)
@@ -83,6 +83,7 @@ public class PolicyToscaPersistenceTest {
     @Before
     public void setupParameters() throws PfModelException {
         PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
+        parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
         parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
index 528395e..7b541e1 100644 (file)
@@ -84,6 +84,7 @@ public class PolicyTypePersistenceTest {
     @Before
     public void setupParameters() throws PfModelException {
         PolicyModelsProviderParameters parameters = new PolicyModelsProviderParameters();
+        parameters.setDatabaseDriver("org.h2.Driver");
         parameters.setDatabaseUrl("jdbc:h2:mem:testdb");
         parameters.setDatabaseUser("policy");
         parameters.setDatabasePassword(Base64.getEncoder().encodeToString("P01icY".getBytes()));
index c7d6d1e..7b5bc14 100644 (file)
         <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
 
         <properties>
-            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
-            <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb" />
-            <property name="javax.persistence.jdbc.user" value="policy" />
-            <property name="javax.persistence.jdbc.password" value="P01icY" />
             <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
             <property name="eclipselink.ddl-generation.output-mode" value="database" />
             <property name="eclipselink.logging.level" value="INFO" />
-        </properties>
-    </persistence-unit>
-
-    <persistence-unit name="ToscaConceptMariaDBTest" transaction-type="RESOURCE_LOCAL">
-        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
-        <class>org.onap.policy.models.dao.converters.CDataConditioner</class>
-        <class>org.onap.policy.models.dao.converters.Uuid2String</class>
-        <class>org.onap.policy.models.base.PfConceptKey</class>
-        <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
-        <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
-        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpGroup</class>
-        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdpSubGroup</class>
-        <class>org.onap.policy.models.pdp.persistence.concepts.JpaPdp</class>
-
-        <properties>
-            <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
-            <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/policy" />
-            <property name="javax.persistence.jdbc.user" value="policy" />
-            <property name="javax.persistence.jdbc.password" value="P01icY" />
-            <property name="javax.persistence.schema-generation.database.action" value="create" />
 
             <!-- property name="eclipselink.logging.level" value="ALL" />
             <property name="eclipselink.logging.level.jpa" value="ALL" />
             <property name="eclipselink.logging.level.server" value="ALL" />
             <property name="eclipselink.logging.level.query" value="ALL" />
             <property name="eclipselink.logging.level.properties" value="ALL" /-->
-
-            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
-            <property name="eclipselink.ddl-generation.output-mode" value="database" />
-            <property name="eclipselink.logging.level" value="INFO" />
         </properties>
     </persistence-unit>
 </persistence>
index a7d016b..175ea20 100644 (file)
@@ -25,10 +25,9 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Properties;
 
 import org.junit.After;
 import org.junit.Before;
@@ -52,7 +51,6 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaTopologyTemplate;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class AuthorativeToscaProviderPolicyTest {
-    private Connection connection;
     private PfDao pfDao;
     private StandardCoder standardCoder;
 
@@ -63,17 +61,25 @@ public class AuthorativeToscaProviderPolicyTest {
      */
     @Before
     public void setupDao() throws Exception {
-        // Use the JDBC UI "jdbc:h2:mem:testdb" to test towards the h2 database
-        // Use the JDBC UI "jdbc:mariadb://localhost:3306/policy" to test towards a locally installed mariadb instance
-        connection = DriverManager.getConnection("jdbc:h2:mem:testdb", "policy", "P01icY");
-
         final DaoParameters daoParameters = new DaoParameters();
         daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
 
-        // Use the persistence unit ToscaConceptTest to test towards the h2 database
-        // Use the persistence unit ToscaConceptMariaDBTest to test towards a locally installed mariadb instance
         daoParameters.setPersistenceUnit("ToscaConceptTest");
 
+        Properties jdbcProperties = new Properties();
+        jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy");
+        jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY");
+
+        // H2
+        jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
+        jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:testdb");
+
+        // MariaDB
+        //jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+        //jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy");
+
+        daoParameters.setJdbcProperties(jdbcProperties );
+
         pfDao = new PfDaoFactory().createPfDao(daoParameters);
         pfDao.init(daoParameters);
     }
@@ -89,7 +95,7 @@ public class AuthorativeToscaProviderPolicyTest {
     @After
     public void teardown() throws Exception {
         pfDao.close();
-        connection.close();
+        //connection.close();
     }
 
     @Test
index 7dc4a94..ec1b347 100644 (file)
@@ -26,10 +26,9 @@ import static org.junit.Assert.assertNotNull;
 
 import com.google.gson.GsonBuilder;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Properties;
 
 import org.apache.commons.lang3.ObjectUtils;
 import org.junit.After;
@@ -57,7 +56,6 @@ import org.yaml.snakeyaml.Yaml;
  */
 public class AuthorativeToscaProviderPolicyTypeTest {
     private static String yamlAsJsonString;
-    private Connection connection;
     private PfDao pfDao;
     private StandardCoder standardCoder;
 
@@ -83,17 +81,25 @@ public class AuthorativeToscaProviderPolicyTypeTest {
      */
     @Before
     public void setupDao() throws Exception {
-        // Use the JDBC UI "jdbc:h2:mem:testdb" to test towards the h2 database
-        // Use the JDBC UI "jdbc:mariadb://localhost:3306/policy" to test towards a locally installed mariadb instance
-        connection = DriverManager.getConnection("jdbc:h2:mem:testdb", "policy", "P01icY");
-
         final DaoParameters daoParameters = new DaoParameters();
         daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
 
-        // Use the persistence unit ToscaConceptTest to test towards the h2 database
-        // Use the persistence unit ToscaConceptMariaDBTest to test towards a locally installed mariadb instance
         daoParameters.setPersistenceUnit("ToscaConceptTest");
 
+        Properties jdbcProperties = new Properties();
+        jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy");
+        jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY");
+
+        // H2
+        jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
+        jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:testdb");
+
+        // MariaDB
+        //jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+        //jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy");
+
+        daoParameters.setJdbcProperties(jdbcProperties );
+
         pfDao = new PfDaoFactory().createPfDao(daoParameters);
         pfDao.init(daoParameters);
     }
@@ -109,7 +115,6 @@ public class AuthorativeToscaProviderPolicyTypeTest {
     @After
     public void teardown() throws Exception {
         pfDao.close();
-        connection.close();
     }
 
     @Test
index 2fdc3aa..076064c 100644 (file)
@@ -24,9 +24,8 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
 import java.util.Map;
+import java.util.Properties;
 
 import org.junit.After;
 import org.junit.Before;
@@ -47,7 +46,6 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class LegacyProvider4LegacyGuardTest {
-    private Connection connection;
     private PfDao pfDao;
     private StandardCoder standardCoder;
 
@@ -59,17 +57,25 @@ public class LegacyProvider4LegacyGuardTest {
      */
     @Before
     public void setupDao() throws Exception {
-        // Use the JDBC UI "jdbc:h2:mem:testdb" to test towards the h2 database
-        // Use the JDBC UI "jdbc:mariadb://localhost:3306/policy" to test towards a locally installed mariadb instance
-        connection = DriverManager.getConnection("jdbc:h2:mem:testdb", "policy", "P01icY");
-
         final DaoParameters daoParameters = new DaoParameters();
         daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
 
-        // Use the persistence unit ToscaConceptTest to test towards the h2 database
-        // Use the persistence unit ToscaConceptMariaDBTest to test towards a locally installed mariadb instance
         daoParameters.setPersistenceUnit("ToscaConceptTest");
 
+        Properties jdbcProperties = new Properties();
+        jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy");
+        jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY");
+
+        // H2
+        jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
+        jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:testdb");
+
+        // MariaDB
+        //jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+        //jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy");
+
+        daoParameters.setJdbcProperties(jdbcProperties);
+
         pfDao = new PfDaoFactory().createPfDao(daoParameters);
         pfDao.init(daoParameters);
     }
@@ -85,7 +91,6 @@ public class LegacyProvider4LegacyGuardTest {
     @After
     public void teardown() throws Exception {
         pfDao.close();
-        connection.close();
     }
 
     @Test
index d198bd4..cc1f515 100644 (file)
@@ -24,8 +24,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
+import java.util.Properties;
 
 import org.junit.After;
 import org.junit.Before;
@@ -44,7 +43,6 @@ import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class LegacyProvider4LegacyOperationalTest {
-    private Connection connection;
     private PfDao pfDao;
     private StandardCoder standardCoder;
 
@@ -55,17 +53,25 @@ public class LegacyProvider4LegacyOperationalTest {
      */
     @Before
     public void setupDao() throws Exception {
-        // Use the JDBC UI "jdbc:h2:mem:testdb" to test towards the h2 database
-        // Use the JDBC UI "jdbc:mariadb://localhost:3306/policy" to test towards a locally installed mariadb instance
-        connection = DriverManager.getConnection("jdbc:h2:mem:testdb", "policy", "P01icY");
-
         final DaoParameters daoParameters = new DaoParameters();
         daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
 
-        // Use the persistence unit ToscaConceptTest to test towards the h2 database
-        // Use the persistence unit ToscaConceptMariaDBTest to test towards a locally installed mariadb instance
         daoParameters.setPersistenceUnit("ToscaConceptTest");
 
+        Properties jdbcProperties = new Properties();
+        jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy");
+        jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY");
+
+        // H2
+        jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
+        jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:testdb");
+
+        // MariaDB
+        //jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+        //jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy");
+
+        daoParameters.setJdbcProperties(jdbcProperties );
+
         pfDao = new PfDaoFactory().createPfDao(daoParameters);
         pfDao.init(daoParameters);
     }
@@ -81,7 +87,6 @@ public class LegacyProvider4LegacyOperationalTest {
     @After
     public void teardown() throws Exception {
         pfDao.close();
-        connection.close();
     }
 
     @Test
index ddfb567..4ed4c5c 100644 (file)
@@ -26,8 +26,7 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
+import java.util.Properties;
 
 import org.junit.After;
 import org.junit.Before;
@@ -51,7 +50,6 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaTopologyTemplate;
  * @author Liam Fallon (liam.fallon@est.tech)
  */
 public class SimpleToscaProviderTest {
-    private Connection connection;
     private PfDao pfDao;
     private StandardCoder standardCoder;
 
@@ -62,17 +60,25 @@ public class SimpleToscaProviderTest {
      */
     @Before
     public void setupDao() throws Exception {
-        // Use the JDBC UI "jdbc:h2:mem:testdb" to test towards the h2 database
-        // Use the JDBC UI "jdbc:mariadb://localhost:3306/policy" to test towards a locally installed mariadb instance
-        connection = DriverManager.getConnection("jdbc:h2:mem:testdb", "policy", "P01icY");
-
         final DaoParameters daoParameters = new DaoParameters();
         daoParameters.setPluginClass(DefaultPfDao.class.getCanonicalName());
 
-        // Use the persistence unit ToscaConceptTest to test towards the h2 database
-        // Use the persistence unit ToscaConceptMariaDBTest to test towards a locally installed mariadb instance
         daoParameters.setPersistenceUnit("ToscaConceptTest");
 
+        Properties jdbcProperties = new Properties();
+        jdbcProperties.setProperty("javax.persistence.jdbc.user", "policy");
+        jdbcProperties.setProperty("javax.persistence.jdbc.password", "P01icY");
+
+        // H2
+        jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
+        jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:testdb");
+
+        // MariaDB
+        //jdbcProperties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+        //jdbcProperties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/policy");
+
+        daoParameters.setJdbcProperties(jdbcProperties );
+
         pfDao = new PfDaoFactory().createPfDao(daoParameters);
         pfDao.init(daoParameters);
     }
@@ -88,7 +94,6 @@ public class SimpleToscaProviderTest {
     @After
     public void teardown() throws Exception {
         pfDao.close();
-        connection.close();
     }
 
     @Test
index 23e8567..936e5a1 100644 (file)
         <class>org.onap.policy.models.dao.converters.CDataConditioner</class>
         <class>org.onap.policy.models.dao.converters.Uuid2String</class>
         <class>org.onap.policy.models.base.PfConceptKey</class>
-        <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
         <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
+        <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicyType</class>
 
         <properties>
-            <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
-            <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb" />
-            <property name="javax.persistence.jdbc.user" value="policy" />
-            <property name="javax.persistence.jdbc.password" value="P01icY" />
             <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
             <property name="eclipselink.ddl-generation.output-mode" value="database" />
             <property name="eclipselink.logging.level" value="INFO" />
-        </properties>
-    </persistence-unit>
-
-    <persistence-unit name="ToscaConceptMariaDBTest" transaction-type="RESOURCE_LOCAL">
-        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
-        <class>org.onap.policy.models.dao.converters.CDataConditioner</class>
-        <class>org.onap.policy.models.dao.converters.Uuid2String</class>
-        <class>org.onap.policy.models.base.PfConceptKey</class>
-        <class>org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy</class>
-
-        <properties>
-            <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
-            <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://localhost:3306/policy" />
-            <property name="javax.persistence.jdbc.user" value="policy" />
-            <property name="javax.persistence.jdbc.password" value="P01icY" />
-            <property name="javax.persistence.schema-generation.database.action" value="create" />
 
             <!-- property name="eclipselink.logging.level" value="ALL" />
             <property name="eclipselink.logging.level.jpa" value="ALL" />
             <property name="eclipselink.logging.level.server" value="ALL" />
             <property name="eclipselink.logging.level.query" value="ALL" />
             <property name="eclipselink.logging.level.properties" value="ALL" /-->
-
-            <property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
-            <property name="eclipselink.ddl-generation.output-mode" value="database" />
-            <property name="eclipselink.logging.level" value="INFO" />
         </properties>
     </persistence-unit>
 </persistence>