2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.dao;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.fail;
27 import java.util.Properties;
29 import org.junit.Test;
30 import org.onap.policy.models.dao.DaoParameters;
31 import org.onap.policy.models.dao.PfDaoFactory;
32 import org.onap.policy.models.dao.converters.CDataConditioner;
33 import org.onap.policy.models.dao.converters.Uuid2String;
35 public class DaoMiscTest {
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");
54 new PfDaoFactory().createPfDao(daoParameters);
55 fail("test shold throw an exception here");
56 } catch (final Exception e) {
57 assertEquals("Policy Framework DAO class not found for DAO plugin \"somewhere.over.the.rainbow\"",
61 daoParameters.setPluginClass("java.lang.String");
63 new PfDaoFactory().createPfDao(daoParameters);
64 fail("test shold throw an exception here");
65 } catch (final Exception e) {
66 assertEquals("Specified DAO plugin class \"java.lang.String\" " + "does not implement the PfDao interface",
72 public void testDaoParameters() {
73 final DaoParameters pars = new DaoParameters();
74 pars.setJdbcProperties(new Properties());
75 assertEquals(0, pars.getJdbcProperties().size());
77 pars.setJdbcProperty("name", "Dorothy");
78 assertEquals("Dorothy", pars.getJdbcProperty("name"));
80 pars.setPersistenceUnit("Kansas");
81 assertEquals("Kansas", pars.getPersistenceUnit());
83 pars.setPluginClass("somewhere.over.the.rainbow");
84 assertEquals("somewhere.over.the.rainbow", pars.getPluginClass());
86 assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, "
87 + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString());