[DMAAP-BC] Consolidate bus controller repos
[dmaap/buscontroller.git] / dmaap-bc / src / test / java / org / onap / dmaap / dbcapi / database / DBFieldHandlerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
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
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
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=========================================================
21  */
22
23 package org.onap.dmaap.dbcapi.database;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
27
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;
34
35 public class DBFieldHandlerTest extends BaseLoggingClass {
36
37     private static final String fmt = "%24s: %s%n";
38
39     ReflectionHarness rh = new ReflectionHarness();
40
41     private static class TopicReplicationTypeHandler implements DBFieldHandler.SqlOp {
42         public Object get(ResultSet rs, int index) throws Exception {
43             int val = rs.getInt(index);
44
45             return (ReplicationType.valueOf(val));
46         }
47
48         public void set(PreparedStatement ps, int index, Object val) throws Exception {
49             if (val == null) {
50                 ps.setInt(index, 0);
51                 return;
52             }
53             @SuppressWarnings("unchecked")
54             ReplicationType rep = (ReplicationType) val;
55             ps.setInt(index, rep.getValue());
56         }
57     }
58
59     @Test
60     public void test1() {
61         // rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "get",
62         // "idNotSet@namespaceNotSet:pwdNotSet" );
63     }
64
65     @Test
66     public void test2() {
67         String v = "Validate";
68         // rh.reflect( "org.onap.dmaap.dbcapi.aaf.client.MrTopicConnection", "set", v );
69     }
70
71     @Test
72     public void test3() {
73         try {
74             DBFieldHandler fh = new DBFieldHandler(String.class, "aString", 1);
75         } catch (Exception e) {
76             errorLogger.error("Error", e);
77         }
78     }
79
80     @Test
81     public void test4() {
82         try {
83             DBFieldHandler fh = new DBFieldHandler(String.class, "aString", 1, null);
84         } catch (Exception e) {
85             errorLogger.error("Error", e);
86         }
87     }
88
89     @Test
90     public void testfesc() {
91         String sampleString = "@xyz,ww;,";
92         String finalString = DBFieldHandler.fesc(sampleString);
93         assertEquals("@axyz@cww@s@c", finalString);
94     }
95
96     @Test
97     public void testfunesc() {
98         String sampleString = "@axyz@cww@s@c";
99         String convertedString = DBFieldHandler.funesc(sampleString);
100         assertEquals("@xyz,ww;,", convertedString);
101     }
102
103     @Test
104     public void testfescWithNull() {
105         String sampleString1 = DBFieldHandler.fesc(null);
106         String sampleString2 = DBFieldHandler.funesc(null);
107         assertNull(null, sampleString1);
108         assertNull(null, sampleString2);
109     }
110 }