Remove try/catch blocks with assertj - apex-pdp
[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  *  Modifications Copyright (C) 2020 Nordix Foundation
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.apex.model.basicmodel.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.apex.model.basicmodel.dao.converters.CDataConditioner;
31 import org.onap.policy.apex.model.basicmodel.dao.converters.Uuid2String;
32
33 public class DaoMiscTest {
34
35     @Test
36     public void testUuid2StringMopUp() {
37         final Uuid2String uuid2String = new Uuid2String();
38         assertEquals("", uuid2String.convertToDatabaseColumn(null));
39     }
40
41     @Test
42     public void testCDataConditionerMopUp() {
43         assertNull(CDataConditioner.clean(null));
44     }
45
46     @Test
47     public void testDaoFactory() {
48         final DaoParameters daoParameters = new DaoParameters();
49
50         daoParameters.setPluginClass("somewhere.over.the.rainbow");
51         assertThatThrownBy(() -> new ApexDaoFactory().createApexDao(daoParameters))
52             .hasMessage("Apex DAO class not found for DAO plugin \"somewhere.over.the.rainbow\"");
53         daoParameters.setPluginClass("java.lang.String");
54         assertThatThrownBy(() -> new ApexDaoFactory().createApexDao(daoParameters))
55             .hasMessage("Specified Apex DAO plugin class \"java.lang.String\" "
56                             + "does not implement the ApexDao interface");
57     }
58
59     @Test
60     public void testDaoParameters() {
61         final DaoParameters pars = new DaoParameters();
62         pars.setJdbcProperties(new Properties());
63         assertEquals(0, pars.getJdbcProperties().size());
64
65         pars.setJdbcProperty("name", "Dorothy");
66         assertEquals("Dorothy", pars.getJdbcProperty("name"));
67
68         pars.setPersistenceUnit("Kansas");
69         assertEquals("Kansas", pars.getPersistenceUnit());
70
71         pars.setPluginClass("somewhere.over.the.rainbow");
72         assertEquals("somewhere.over.the.rainbow", pars.getPluginClass());
73
74         assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, "
75                         + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString());
76     }
77 }