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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.basicmodel.dao;
24 import static org.assertj.core.api.Assertions.assertThatThrownBy;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
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;
33 public class DaoMiscTest {
36 public void testUuid2StringMopUp() {
37 final Uuid2String uuid2String = new Uuid2String();
38 assertEquals("", uuid2String.convertToDatabaseColumn(null));
42 public void testCDataConditionerMopUp() {
43 assertNull(CDataConditioner.clean(null));
47 public void testDaoFactory() {
48 final DaoParameters daoParameters = new DaoParameters();
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");
60 public void testDaoParameters() {
61 final DaoParameters pars = new DaoParameters();
62 pars.setJdbcProperties(new Properties());
63 assertEquals(0, pars.getJdbcProperties().size());
65 pars.setJdbcProperty("name", "Dorothy");
66 assertEquals("Dorothy", pars.getJdbcProperty("name"));
68 pars.setPersistenceUnit("Kansas");
69 assertEquals("Kansas", pars.getPersistenceUnit());
71 pars.setPluginClass("somewhere.over.the.rainbow");
72 assertEquals("somewhere.over.the.rainbow", pars.getPluginClass());
74 assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, "
75 + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString());