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;
31 import org.apache.log4j.Logger;
32 import org.junit.Test;
33 import org.onap.dmaap.dbcapi.authentication.AafLurAndFish;
34 import org.onap.dmaap.dbcapi.model.ReplicationType;
35 import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
37 public class DBFieldHandlerTest {
39 private static final Logger logger = Logger.getLogger(AafLurAndFish.class);
41 private static final String fmt = "%24s: %s%n";
43 ReflectionHarness rh = new ReflectionHarness();
45 private static class TopicReplicationTypeHandler implements DBFieldHandler.SqlOp {
46 public Object get(ResultSet rs, int index) throws Exception {
47 int val = rs.getInt(index);
49 return (ReplicationType.valueOf(val));
52 public void set(PreparedStatement ps, int index, Object val) throws Exception {
57 @SuppressWarnings("unchecked")
58 ReplicationType rep = (ReplicationType) val;
59 ps.setInt(index, rep.getValue());
65 // rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "get",
66 // "idNotSet@namespaceNotSet:pwdNotSet" );
71 String v = "Validate";
72 // rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "set", v );
78 DBFieldHandler fh = new DBFieldHandler(String.class, "aString", 1);
79 } catch (Exception e) {
80 logger.error("Error", e);
87 DBFieldHandler fh = new DBFieldHandler(String.class, "aString", 1, null);
88 } catch (Exception e) {
89 logger.error("Error", e);
94 public void testfesc() {
95 String sampleString = "@xyz,ww;,";
96 String finalString = DBFieldHandler.fesc(sampleString);
97 assertEquals("@axyz@cww@s@c", finalString);
101 public void testfunesc() {
102 String sampleString = "@axyz@cww@s@c";
103 String convertedString = DBFieldHandler.funesc(sampleString);
104 assertEquals("@xyz,ww;,", convertedString);
108 public void testfescWithNull() {
109 String sampleString1 = DBFieldHandler.fesc(null);
110 String sampleString2 = DBFieldHandler.funesc(null);
111 assertNull(null, sampleString1);
112 assertNull(null, sampleString2);