Use lombok for events, base, dao
[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  *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.dao;
23
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
27
28 import java.util.Properties;
29 import org.junit.Test;
30 import org.onap.policy.models.dao.converters.CDataConditioner;
31 import org.onap.policy.models.dao.converters.Uuid2String;
32
33 public class DaoMiscTest {
34
35     private static final String SOMEWHERE_OVER_THE_RAINBOW = "somewhere.over.the.rainbow";
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         assertThatThrownBy(() -> new PfDaoFactory().createPfDao(daoParameters)).hasMessage(
54                         "Policy Framework DAO class not found for DAO plugin \"somewhere.over.the.rainbow\"");
55
56         daoParameters.setPluginClass("java.lang.String");
57         assertThatThrownBy(() -> new PfDaoFactory().createPfDao(daoParameters)).hasMessage(
58                         "Specified DAO plugin class \"java.lang.String\" " + "does not implement the PfDao interface");
59     }
60
61     @Test
62     public void testDaoParameters() {
63         final DaoParameters pars = new DaoParameters();
64         pars.setJdbcProperties(new Properties());
65         assertEquals(0, pars.getJdbcProperties().size());
66
67         pars.setJdbcProperty("name", "Dorothy");
68         assertEquals("Dorothy", pars.getJdbcProperty("name"));
69
70         pars.setPersistenceUnit("Kansas");
71         assertEquals("Kansas", pars.getPersistenceUnit());
72
73         pars.setPluginClass(SOMEWHERE_OVER_THE_RAINBOW);
74         assertEquals(SOMEWHERE_OVER_THE_RAINBOW, pars.getPluginClass());
75
76         assertEquals("DaoParameters(pluginClass=somewhere.over.the.rainbow, "
77                 + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy})", pars.toString());
78     }
79 }