2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 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
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.models.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.models.dao.converters.CDataConditioner;
31 import org.onap.policy.models.dao.converters.Uuid2String;
33 public class DaoMiscTest {
35 private static final String SOMEWHERE_OVER_THE_RAINBOW = "somewhere.over.the.rainbow";
38 public void testUuid2StringMopUp() {
39 final Uuid2String uuid2String = new Uuid2String();
40 assertEquals("", uuid2String.convertToDatabaseColumn(null));
44 public void testCDataConditionerMopUp() {
45 assertNull(CDataConditioner.clean(null));
49 public void testDaoFactory() {
50 final DaoParameters daoParameters = new DaoParameters();
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\"");
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");
62 public void testDaoParameters() {
63 final DaoParameters pars = new DaoParameters();
64 pars.setJdbcProperties(new Properties());
65 assertEquals(0, pars.getJdbcProperties().size());
67 pars.setJdbcProperty("name", "Dorothy");
68 assertEquals("Dorothy", pars.getJdbcProperty("name"));
70 pars.setPersistenceUnit("Kansas");
71 assertEquals("Kansas", pars.getPersistenceUnit());
73 pars.setPluginClass(SOMEWHERE_OVER_THE_RAINBOW);
74 assertEquals(SOMEWHERE_OVER_THE_RAINBOW, pars.getPluginClass());
76 assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, "
77 + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString());