2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2016-2018 Ericsson. All rights reserved.
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.apex.model.basicmodel.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.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");
52 new ApexDaoFactory().createApexDao(daoParameters);
53 fail("test shold throw an exception here");
54 } catch (final Exception e) {
55 assertEquals("Apex DAO class not found for DAO plugin \"somewhere.over.the.rainbow\"", e.getMessage());
58 daoParameters.setPluginClass("java.lang.String");
60 new ApexDaoFactory().createApexDao(daoParameters);
61 fail("test shold throw an exception here");
62 } catch (final Exception e) {
63 assertEquals("Specified Apex DAO plugin class \"java.lang.String\" "
64 + "does not implement the ApexDao interface", e.getMessage());
69 public void testDaoParameters() {
70 final DaoParameters pars = new DaoParameters();
71 pars.setJdbcProperties(new Properties());
72 assertEquals(0, pars.getJdbcProperties().size());
74 pars.setJdbcProperty("name", "Dorothy");
75 assertEquals("Dorothy", pars.getJdbcProperty("name"));
77 pars.setPersistenceUnit("Kansas");
78 assertEquals("Kansas", pars.getPersistenceUnit());
80 pars.setPluginClass("somewhere.over.the.rainbow");
81 assertEquals("somewhere.over.the.rainbow", pars.getPluginClass());
83 assertEquals("DAOParameters [pluginClass=somewhere.over.the.rainbow, "
84 + "persistenceUnit=Kansas, jdbcProperties={name=Dorothy}]", pars.toString());