Batch, Remove unneeded Classes, refine, etc
[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.mockito.Matchers.any;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.when;
27
28 import java.io.PrintStream;
29 import java.util.ArrayList;
30 import java.util.Date;
31 import java.util.List;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aaf.auth.batch.helpers.Creator;
36 import org.onap.aaf.auth.batch.helpers.UserRole;
37 import org.onap.aaf.auth.dao.cass.UserRoleDAO;
38 import org.onap.aaf.misc.env.Env;
39 import org.onap.aaf.misc.env.LogTarget;
40 import org.onap.aaf.misc.env.TimeTaken;
41 import org.onap.aaf.misc.env.Trans;
42
43 import com.datastax.driver.core.ResultSet;
44 import com.datastax.driver.core.Row;
45 import com.datastax.driver.core.Session;
46 import com.datastax.driver.core.SimpleStatement;
47
48 import junit.framework.Assert;
49
50 public class JU_UserRole {
51
52         UserRole userRole;
53         UserRole userRole1;
54         Date date;
55         PrintStream ds;
56
57         @Before
58         public void setUp() {
59                 date = new Date();
60                 userRole = new UserRole("user", "ns", "rname", date);
61                 userRole = new UserRole("user", "role", "ns", "rname", date);
62         }
63
64         @Test
65         public void testTotalLoaded() {
66                 Assert.assertEquals(0, userRole.totalLoaded());
67         }
68
69         @Test
70         public void testDeleted() {
71                 Assert.assertEquals(0, userRole.deleted());
72         }
73
74         @Test
75         public void testExpunge() {
76                 userRole.expunge();
77         }
78
79         @Test
80         public void testSetDeleteStream() {
81                 userRole.setDeleteStream(ds);
82         }
83
84         @Test
85         public void testSetRecoverStream() {
86                 userRole.setRecoverStream(ds);
87         }
88
89         @Test
90         public void testUrdd() {
91                 Assert.assertTrue(userRole.urdd() instanceof UserRoleDAO.Data);
92         }
93
94         @Test
95         public void testUser() {
96                 Assert.assertEquals("user", userRole.user());
97         }
98
99         @Test
100         public void testRole() {
101                 Assert.assertEquals("role", userRole.role());
102         }
103
104         @Test
105         public void testNs() {
106                 Assert.assertEquals("ns", userRole.ns());
107         }
108
109         @Test
110         public void testRName() {
111                 Assert.assertEquals("rname", userRole.rname());
112         }
113
114         @Test
115         public void testExpires() {
116                 Assert.assertEquals(date, userRole.expires());
117                 userRole.expires(date);
118         }
119
120         @Test
121         public void testToString() {
122                 Assert.assertTrue(userRole.toString() instanceof String);
123         }
124
125         @Test
126         public void testGet() {
127                 userRole.get("u", "r");
128         }
129
130         @Test
131         public void testResetLocalData() {
132                 userRole.resetLocalData();
133         }
134
135         @Test
136         public void testLoad() {
137                 Creator<UserRole> creator = mock(Creator.class);
138                 Trans trans = mock(Trans.class);
139                 Session session = mock(Session.class);
140                 LogTarget target = mock(LogTarget.class);
141                 TimeTaken tt = mock(TimeTaken.class);
142                 ResultSet results = mock(ResultSet.class);
143
144                 List<Row> rows = new ArrayList<Row>();
145
146                 when(trans.info()).thenReturn(target);
147                 when(trans.start("Read UserRoles", Env.REMOTE)).thenReturn(tt);
148                 when(trans.start("Load UserRole", Env.SUB)).thenReturn(tt);
149                 when(session.execute(any(SimpleStatement.class))).thenReturn(results);
150                 when(results.iterator()).thenReturn(rows.iterator());
151
152         }
153
154 }