2b4cd5c308344de901c7767ab3d2d17bf392713f
[policy/apex-pdp.git] / model / basic-model / src / test / java / org / onap / policy / apex / model / basicmodel / dao / DaoMiscTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
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.apex.model.basicmodel.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 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.dao.converters.CDataConditioner;
30 import org.onap.policy.apex.model.basicmodel.dao.converters.Uuid2String;
31
32 public class DaoMiscTest {
33
34     @Test
35     public void testUuid2StringMopUp() {
36         final Uuid2String uuid2String = new Uuid2String();
37         assertEquals("", uuid2String.convertToDatabaseColumn(null));
38     }
39
40     @Test
41     public void testCDataConditionerMopUp() {
42         assertNull(CDataConditioner.clean(null));
43     }
44
45     @Test
46     public void testDaoFactory() {
47         final DaoParameters daoParameters = new DaoParameters();
48
49         daoParameters.setPluginClass("somewhere.over.the.rainbow");
50         try {
51             new ApexDaoFactory().createApexDao(daoParameters);
52             fail("test shold throw an exception here");
53         } catch (final Exception e) {
54             assertEquals("Apex DAO class not found for DAO plugin \"somewhere.over.the.rainbow\"", e.getMessage());
55         }
56
57         daoParameters.setPluginClass("java.lang.String");
58         try {
59             new ApexDaoFactory().createApexDao(daoParameters);
60             fail("test shold throw an exception here");
61         } catch (final Exception e) {
62             assertEquals("Specified Apex DAO plugin class \"java.lang.String\" "
63                             + "does not implement the ApexDao interface", e.getMessage());
64         }
65     }
66
67     @Test
68     public void testDaoParameters() {
69         final DaoParameters pars = new DaoParameters();
70         pars.setJdbcProperties(new Properties());
71         assertEquals(0, pars.getJdbcProperties().size());
72
73         pars.setJdbcProperty("name", "Dorothy");
74         assertEquals("Dorothy", pars.getJdbcProperty("name"));
75
76         pars.setPersistenceUnit("Kansas");
77         assertEquals("Kansas", pars.getPersistenceUnit());
78
79         pars.setPluginClass("somewhere.over.the.rainbow");
80         assertEquals("somewhere.over.the.rainbow", pars.getPluginClass());
81
82         assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, "
83                         + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString());
84     }
85 }