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