Remove Tabs, per Jococo
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / helpers / test / JU_NS.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.batch.helpers.test;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28
29 import java.util.ArrayList;
30
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.aaf.auth.batch.helpers.Creator;
34 import org.onap.aaf.auth.batch.helpers.NS;
35 import org.onap.aaf.auth.batch.helpers.NS.NSSplit;
36 import org.onap.aaf.auth.batch.helpers.creators.RowCreator;
37 import org.onap.aaf.misc.env.Env;
38 import org.onap.aaf.misc.env.LogTarget;
39 import org.onap.aaf.misc.env.TimeTaken;
40 import org.onap.aaf.misc.env.Trans;
41
42 import com.datastax.driver.core.ResultSet;
43 import com.datastax.driver.core.Row;
44 import com.datastax.driver.core.Session;
45 import com.datastax.driver.core.SimpleStatement;
46
47 import junit.framework.Assert;
48
49 public class JU_NS {
50
51     NS ns;
52     NSSplit nSSplit;
53
54     @Before
55     public void setUp() {
56         ns = new NS("name", "description", "parent", 1, 1);
57         nSSplit = new NSSplit("string", 1);
58     }
59
60     @Test
61     public void testToString() {
62         Assert.assertEquals("name", ns.toString());
63     }
64
65     @Test
66     public void testHashCode() {
67         Assert.assertEquals(3373707, ns.hashCode());
68     }
69
70     @Test
71     public void testEquals() {
72         Assert.assertEquals(true, ns.equals("name"));
73         Assert.assertEquals(false, ns.equals("name1"));
74     }
75
76     @Test
77     public void testCompareTo() {
78         NS nsValid = new NS("name", "description", "parent", 1, 1);
79         Assert.assertEquals(0, ns.compareTo(nsValid));
80
81         NS nsInvalid = new NS("name1", "description", "parent", 1, 1);
82         Assert.assertEquals(-1, ns.compareTo(nsInvalid));
83     }
84
85     @Test
86     public void testDeriveParent() {
87         ns.deriveParent("d.ot.te.d");
88     }
89
90     @Test
91     public void testLoadWithoutNS() {
92         Trans trans = mock(Trans.class);
93         Session session = mock(Session.class);
94         Creator<NS> creator = mock(Creator.class);
95         LogTarget target = mock(LogTarget.class);
96         TimeTaken tt = mock(TimeTaken.class);
97         ResultSet results = mock(ResultSet.class);
98         ArrayList<Row> rows = new ArrayList<Row>();
99         Row row = RowCreator.getRow();
100         rows.add(row);
101
102         when(trans.info()).thenReturn(target);
103         when(trans.start("Read Namespaces", Env.REMOTE)).thenReturn(tt);
104         when(trans.start("Load Namespaces", Env.SUB)).thenReturn(tt);
105         when(session.execute(any(SimpleStatement.class))).thenReturn(results);
106         when(results.iterator()).thenReturn(rows.iterator());
107         when(creator.create(row)).thenReturn(ns);
108
109         NS.load(trans, session, creator);
110     }
111
112     @Test
113     public void testLoadOne() {
114         Trans trans = mock(Trans.class);
115         Session session = mock(Session.class);
116         Creator<NS> creator = mock(Creator.class);
117         LogTarget target = mock(LogTarget.class);
118         TimeTaken tt = mock(TimeTaken.class);
119         ResultSet results = mock(ResultSet.class);
120         ArrayList<Row> rows = new ArrayList<Row>();
121         Row row = RowCreator.getRow();
122         rows.add(row);
123
124         when(trans.info()).thenReturn(target);
125         when(trans.start("Read Namespaces", Env.REMOTE)).thenReturn(tt);
126         when(trans.start("Load Namespaces", Env.SUB)).thenReturn(tt);
127         when(session.execute(any(SimpleStatement.class))).thenReturn(results);
128         when(results.iterator()).thenReturn(rows.iterator());
129         when(creator.create(row)).thenReturn(ns);
130
131         NS.loadOne(trans, session, creator, "text");
132     }
133
134     @Test
135     public void testCount() {
136         Trans trans = mock(Trans.class);
137         Session session = mock(Session.class);
138         LogTarget target = mock(LogTarget.class);
139         TimeTaken tt = mock(TimeTaken.class);
140         ResultSet results = mock(ResultSet.class);
141         ArrayList<Row> rows = new ArrayList<Row>();
142         Row row = RowCreator.getRow();
143         rows.add(row);
144
145         when(trans.info()).thenReturn(target);
146         when(trans.start("Count Namespaces", Env.REMOTE)).thenReturn(tt);
147         when(session.execute(any(SimpleStatement.class))).thenReturn(results);
148         when(results.one()).thenReturn(row);
149
150         assertEquals(0, NS.count(trans, session));
151     }
152
153     @Test
154     public void testV2() {
155         NS.v2_0_11.create(RowCreator.getRow());
156         assertEquals(NS.v2_0_11.select(), "SELECT name, description, parent, type, scope FROM authz.ns ");
157     }
158
159 }