Merge "Change Batch Packaging"
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / helpers / test / JU_UserRole.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.io.PrintStream;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.List;
33
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.aaf.auth.batch.actions.URDelete;
37 import org.onap.aaf.auth.batch.helpers.Creator;
38 import org.onap.aaf.auth.batch.helpers.UserRole;
39 import org.onap.aaf.auth.batch.helpers.creators.RowCreator;
40 import org.onap.aaf.auth.dao.cass.UserRoleDAO;
41 import org.onap.aaf.auth.env.AuthzTrans;
42 import org.onap.aaf.misc.env.Env;
43 import org.onap.aaf.misc.env.LogTarget;
44 import org.onap.aaf.misc.env.TimeTaken;
45 import org.onap.aaf.misc.env.Trans;
46
47 import com.datastax.driver.core.ResultSet;
48 import com.datastax.driver.core.Row;
49 import com.datastax.driver.core.Session;
50 import com.datastax.driver.core.SimpleStatement;
51
52 import junit.framework.Assert;
53
54 public class JU_UserRole {
55
56         UserRole userRole;
57         UserRole userRole1;
58         Date date;
59         PrintStream ds;
60
61         @Before
62         public void setUp() {
63                 date = new Date();
64                 userRole = new UserRole("user", "ns", "rname", date);
65                 userRole = new UserRole("user", "role", "ns", "rname", date);
66         }
67
68         @Test
69         public void testTotalLoaded() {
70                 Assert.assertEquals(0, userRole.totalLoaded());
71         }
72
73         @Test
74         public void testDeleted() {
75                 Assert.assertEquals(0, userRole.deleted());
76         }
77
78         @Test
79         public void testExpunge() {
80                 userRole.expunge();
81         }
82
83         @Test
84         public void testSetDeleteStream() {
85                 userRole.setDeleteStream(ds);
86         }
87
88         @Test
89         public void testSetRecoverStream() {
90                 userRole.setRecoverStream(ds);
91         }
92
93         @Test
94         public void testUrdd() {
95                 Assert.assertTrue(userRole.urdd() instanceof UserRoleDAO.Data);
96         }
97
98         @Test
99         public void testUser() {
100                 Assert.assertEquals("user", userRole.user());
101         }
102
103         @Test
104         public void testRole() {
105                 Assert.assertEquals("role", userRole.role());
106         }
107
108         @Test
109         public void testNs() {
110                 Assert.assertEquals("ns", userRole.ns());
111         }
112
113         @Test
114         public void testRName() {
115                 Assert.assertEquals("rname", userRole.rname());
116         }
117
118         @Test
119         public void testExpires() {
120                 Assert.assertEquals(date, userRole.expires());
121                 userRole.expires(date);
122         }
123
124         @Test
125         public void testToString() {
126                 Assert.assertTrue(userRole.toString() instanceof String);
127         }
128
129         @Test
130         public void testGet() {
131                 userRole.get("u", "r");
132         }
133
134         @Test
135         public void testResetLocalData() {
136                 userRole.resetLocalData();
137         }
138
139         @Test
140         public void testSizeForDeletion() {
141                 Assert.assertEquals(0, userRole.sizeForDeletion());
142         }
143
144         @Test
145         public void testPendingDelete() {
146                 Assert.assertFalse(userRole.pendingDelete(userRole));
147         }
148
149         @Test
150         public void testActuateDeletionNow() {
151                 AuthzTrans trans = mock(AuthzTrans.class);
152                 URDelete urd = mock(URDelete.class);
153                 userRole.actuateDeletionNow(trans, urd);
154         }
155
156         @Test
157         public void testV2() {
158                 UserRole.v2_0_11.create(RowCreator.getRow());
159                 assertEquals("select user,role,ns,rname,expires from authz.user_role", UserRole.v2_0_11.select());
160         }
161
162         @Test
163         public void testLoad() {
164                 Creator<UserRole> creator = mock(Creator.class);
165                 Trans trans = mock(Trans.class);
166                 Session session = mock(Session.class);
167                 LogTarget target = mock(LogTarget.class);
168                 TimeTaken tt = mock(TimeTaken.class);
169                 ResultSet results = mock(ResultSet.class);
170
171                 List<Row> rows = new ArrayList<Row>();
172
173                 when(trans.info()).thenReturn(target);
174                 when(trans.start("Read UserRoles", Env.REMOTE)).thenReturn(tt);
175                 when(trans.start("Load UserRole", Env.SUB)).thenReturn(tt);
176                 when(session.execute(any(SimpleStatement.class))).thenReturn(results);
177                 when(results.iterator()).thenReturn(rows.iterator());
178
179                 List<Row> list = new ArrayList<Row>();
180                 list.add(RowCreator.getRow());
181                 list.add(RowCreator.getRow());
182
183                 UserRole.load(trans, session, creator, new UserRole.DataLoadVisitor());
184         }
185
186 }