Release patch 2.0.4
[dmaap/dbcapi.git] / src / test / java / org / onap / dmaap / dbcapi / model / MRClientTest.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.model;
24
25 import static org.junit.Assert.*;
26
27 import org.junit.After;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.dmaap.dbcapi.testframework.ReflectionHarness;
31
32 public class MRClientTest {
33
34     private static final String fmt = "%24s: %s%n";
35
36     ReflectionHarness rh = new ReflectionHarness();
37
38     String d, t, f, c, m;
39
40     @Before
41     public void setUp() throws Exception {
42         d = "central-onap";
43         t = "org.onap.dmaap.interestingTopic";
44         f = "mrc.onap.org:3904/events/org.onap.dmaap.interestingTopic";
45         c = "publisher";
46         m = "m12345";
47     }
48
49     @After
50     public void tearDown() throws Exception {
51     }
52
53     @Test
54     public void test1() {
55
56         // can't use simple reflection to test for null since null constructor
57         // initializes some fields.
58         // rh.reflect( "org.onap.dmaap.dbcapi.model.MR_Client", "get", null );
59         // so brute force instead...
60         String[] a = { "put", "view" };
61         MR_Client m = new MR_Client();
62
63         assertTrue(null == m.getDcaeLocationName());
64         assertTrue(null == m.getFqtn());
65         assertTrue(null == m.getClientRole());
66         assertTrue(null == m.getAction());
67
68     }
69
70     @Test
71     public void test2() {
72         String[] a = { "put", "view" };
73         MR_Client m = new MR_Client(d, f, c, a);
74
75         assertTrue(d.equals(m.getDcaeLocationName()));
76         assertTrue(f.equals(m.getFqtn()));
77         assertTrue(c.equals(m.getClientRole()));
78         String[] ma = m.getAction();
79         assertTrue(a.length == ma.length);
80         for (int i = 0; i < a.length; i++) {
81             assertTrue(a[i].equals(ma[i]));
82         }
83     }
84
85     @Test
86     public void test3() {
87
88         String v = "Validate";
89         rh.reflect("org.onap.dmaap.dbcapi.model.MR_Client", "set", v);
90     }
91
92     @Test
93     public void test4() {
94         MR_Client mrClient = new MR_Client();
95         String stringArray[] = { "test" };
96         mrClient.setAction(stringArray);
97         mrClient.hasAction("");
98         mrClient.setMrClientId("mrClientId");
99         mrClient.setTopicURL("testTopicURL");
100         mrClient.setClientIdentity("clientIdentity");
101
102         assertEquals("clientIdentity", mrClient.getClientIdentity());
103         assertEquals("testTopicURL", mrClient.getTopicURL());
104         assertEquals("mrClientId", mrClient.getMrClientId());
105         assertEquals(false, mrClient.isPublisher());
106         assertEquals(false, mrClient.isSubscriber());
107         assertEquals("test", mrClient.getAction()[0]);
108
109     }
110
111 }