Add DAO module for Models
[policy/models.git] / models-dao / src / test / java / org / onap / policy / models / dao / DaoMiscTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.dao;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.fail;
26
27 import java.util.Properties;
28
29 import org.junit.Test;
30 import org.onap.policy.models.dao.DaoParameters;
31 import org.onap.policy.models.dao.PfDaoFactory;
32 import org.onap.policy.models.dao.converters.CDataConditioner;
33 import org.onap.policy.models.dao.converters.Uuid2String;
34
35 public class DaoMiscTest {
36
37     @Test
38     public void testUuid2StringMopUp() {
39         final Uuid2String uuid2String = new Uuid2String();
40         assertEquals("", uuid2String.convertToDatabaseColumn(null));
41     }
42
43     @Test
44     public void testCDataConditionerMopUp() {
45         assertNull(CDataConditioner.clean(null));
46     }
47
48     @Test
49     public void testDaoFactory() {
50         final DaoParameters daoParameters = new DaoParameters();
51
52         daoParameters.setPluginClass("somewhere.over.the.rainbow");
53         try {
54             new PfDaoFactory().createPfDao(daoParameters);
55             fail("test shold throw an exception here");
56         } catch (final Exception e) {
57             assertEquals("Policy Framework DAO class not found for DAO plugin \"somewhere.over.the.rainbow\"",
58                     e.getMessage());
59         }
60
61         daoParameters.setPluginClass("java.lang.String");
62         try {
63             new PfDaoFactory().createPfDao(daoParameters);
64             fail("test shold throw an exception here");
65         } catch (final Exception e) {
66             assertEquals("Specified DAO plugin class \"java.lang.String\" " + "does not implement the PfDao interface",
67                     e.getMessage());
68         }
69     }
70
71     @Test
72     public void testDaoParameters() {
73         final DaoParameters pars = new DaoParameters();
74         pars.setJdbcProperties(new Properties());
75         assertEquals(0, pars.getJdbcProperties().size());
76
77         pars.setJdbcProperty("name", "Dorothy");
78         assertEquals("Dorothy", pars.getJdbcProperty("name"));
79
80         pars.setPersistenceUnit("Kansas");
81         assertEquals("Kansas", pars.getPersistenceUnit());
82
83         pars.setPluginClass("somewhere.over.the.rainbow");
84         assertEquals("somewhere.over.the.rainbow", pars.getPluginClass());
85
86         assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, "
87                 + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString());
88     }
89 }