2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 IBM
8 * ===================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.dmaap.dbcapi.database;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
28 import java.sql.PreparedStatement;
29 import java.sql.ResultSet;
30 import org.junit.Test;
31 import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
32 import org.onap.dmaap.dbcapi.model.ReplicationType;
33 import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
35 public class DBFieldHandlerTest extends BaseLoggingClass {
37 private static final String fmt = "%24s: %s%n";
39 ReflectionHarness rh = new ReflectionHarness();
41 private static class TopicReplicationTypeHandler implements DBFieldHandler.SqlOp {
42 public Object get(ResultSet rs, int index) throws Exception {
43 int val = rs.getInt(index);
45 return (ReplicationType.valueOf(val));
48 public void set(PreparedStatement ps, int index, Object val) throws Exception {
53 @SuppressWarnings("unchecked")
54 ReplicationType rep = (ReplicationType) val;
55 ps.setInt(index, rep.getValue());
61 // rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "get",
62 // "idNotSet@namespaceNotSet:pwdNotSet" );
67 String v = "Validate";
68 // rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "set", v );
74 DBFieldHandler fh = new DBFieldHandler(String.class, "aString", 1);
75 } catch (Exception e) {
76 errorLogger.error("Error", e);
83 DBFieldHandler fh = new DBFieldHandler(String.class, "aString", 1, null);
84 } catch (Exception e) {
85 errorLogger.error("Error", e);
90 public void testfesc() {
91 String sampleString = "@xyz,ww;,";
92 String finalString = DBFieldHandler.fesc(sampleString);
93 assertEquals("@axyz@cww@s@c", finalString);
97 public void testfunesc() {
98 String sampleString = "@axyz@cww@s@c";
99 String convertedString = DBFieldHandler.funesc(sampleString);
100 assertEquals("@xyz,ww;,", convertedString);
104 public void testfescWithNull() {
105 String sampleString1 = DBFieldHandler.fesc(null);
106 String sampleString2 = DBFieldHandler.funesc(null);
107 assertNull(null, sampleString1);
108 assertNull(null, sampleString2);