2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.batch.helpers.test;
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;
29 import java.util.ArrayList;
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;
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;
47 import junit.framework.Assert;
56 ns = new NS("name", "description", "parent", 1, 1);
57 nSSplit = new NSSplit("string", 1);
61 public void testToString() {
62 Assert.assertEquals("name", ns.toString());
66 public void testHashCode() {
67 Assert.assertEquals(3373707, ns.hashCode());
71 public void testEquals() {
72 Assert.assertEquals(true, ns.equals("name"));
73 Assert.assertEquals(false, ns.equals("name1"));
77 public void testCompareTo() {
78 NS nsValid = new NS("name", "description", "parent", 1, 1);
79 Assert.assertEquals(0, ns.compareTo(nsValid));
81 NS nsInvalid = new NS("name1", "description", "parent", 1, 1);
82 Assert.assertEquals(-1, ns.compareTo(nsInvalid));
86 public void testDeriveParent() {
87 ns.deriveParent("d.ot.te.d");
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();
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);
109 NS.load(trans, session, creator);
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();
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);
131 NS.loadOne(trans, session, creator, "text");
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();
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);
150 assertEquals(0, NS.count(trans, session));
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 ");