Remove Tabs, per Jococo
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / helpers / test / JU_Approval.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 import java.util.List;
31 import java.util.UUID;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aaf.auth.batch.helpers.Approval;
36 import org.onap.aaf.auth.dao.cass.ApprovalDAO;
37 import org.onap.aaf.auth.env.AuthzTrans;
38 import org.onap.aaf.auth.layer.Result;
39 import org.onap.aaf.misc.env.LogTarget;
40
41 import junit.framework.Assert;
42
43 public class JU_Approval {
44
45     Approval approval;
46     UUID id;
47     UUID ticket;
48
49
50     @Before
51     public void setUp() {
52         id = new UUID(0, 0);
53         ticket = new UUID(0, 0);
54
55         approval = new Approval(id, ticket, "approver","user", "memo", "operation", "status", "type", 100l);
56     }
57
58     @Test
59     public void testRoleFromMemo() {
60         Assert.assertNull(Approval.roleFromMemo(null));
61         Assert.assertEquals("org.onap.ns.admin",
62                 Approval.roleFromMemo(Approval.RE_VALIDATE_ADMIN + "org.onap.ns]"));
63         Assert.assertEquals("org.onap.ns.owner", Approval.roleFromMemo(Approval.RE_VALIDATE_OWNER + "org.onap.ns]"));
64         Assert.assertEquals("org.onap.ns.member", Approval.roleFromMemo(Approval.RE_APPROVAL_IN_ROLE 
65                 + "bob] + [org.onap.ns.member] - Expires 2018-12-25"));
66     }
67
68     @Test
69     public void testExpunge() {
70         approval.expunge();
71     }
72
73 //    @Test
74 //    public void testGetLast_notified() {
75 //        Assert.assertTrue(approval.getLast_notified() instanceof Date);
76 //    }
77 //
78 //    @Test
79 //    public void testSetLastNotified() {
80 //        approval.setLastNotified(date);
81 //    }
82
83     @Test
84     public void testGetStatus() {
85         Assert.assertEquals("status", approval.getStatus());
86     }
87
88     @Test
89     public void testSetStatus() {
90         approval.setStatus("status");
91     }
92
93     @Test
94     public void testGetId() {
95         Assert.assertTrue(approval.getId() instanceof UUID);
96     }
97
98     @Test
99     public void testGetTicket() {
100         Assert.assertTrue(approval.getTicket() instanceof UUID);
101     }
102
103     @Test
104     public void testGetMemo() {
105         Assert.assertEquals("memo", approval.getMemo());
106     }
107
108     @Test
109     public void testGetOperation() {
110         Assert.assertEquals("operation", approval.getOperation());
111     }
112
113     @Test
114     public void testGetType() {
115         Assert.assertEquals("type", approval.getType());
116     }
117
118     @Test
119     public void testLapsed() {
120         approval.lapsed();
121     }
122
123     @Test
124     public void testGetRole() {
125         Assert.assertNull(approval.getRole());
126     }
127
128     @Test
129     public void testToString() {
130         Assert.assertEquals("user memo", approval.toString());
131     }
132
133     @Test
134     public void testResetLocalData() {
135         approval.resetLocalData();
136     }
137
138     @Test
139     public void testPendingDelete() {
140         Assert.assertFalse(approval.pendingDelete(approval));
141     }
142
143     @Test
144     public void testUpdateNonDryRun() {
145         approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
146         AuthzTrans trans = mock(AuthzTrans.class);
147         ApprovalDAO dao = mock(ApprovalDAO.class);
148         LogTarget target = mock(LogTarget.class);
149
150         when(trans.info()).thenReturn(target);
151
152 //        approval.update(trans, dao, false);
153     }
154
155     @Test
156     public void testUpdateDryRun() {
157         approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
158         AuthzTrans trans = mock(AuthzTrans.class);
159         ApprovalDAO dao = mock(ApprovalDAO.class);
160         LogTarget target = mock(LogTarget.class);
161
162         when(trans.info()).thenReturn(target);
163
164 //        approval.update(trans, dao, true);
165     }
166
167     @Test
168     public void testDelayDeleteDryRun() {
169         approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
170         AuthzTrans trans = mock(AuthzTrans.class);
171         ApprovalDAO dao = mock(ApprovalDAO.class);
172         LogTarget target = mock(LogTarget.class);
173
174         when(trans.info()).thenReturn(target);
175
176         List<Approval> list = new ArrayList<Approval>();
177         list.add(approval);
178         Approval.delayDelete(trans, dao, true, list, "text");
179     }
180
181     @Test
182     public void testDelayDeleteNonDryRun() {
183         approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
184         AuthzTrans trans = mock(AuthzTrans.class);
185         ApprovalDAO dao = mock(ApprovalDAO.class);
186         LogTarget target = mock(LogTarget.class);
187
188         when(trans.info()).thenReturn(target);
189         Result<Void> rv = Result.ok();
190         when(dao.delete(any(AuthzTrans.class), any(ApprovalDAO.Data.class), any(Boolean.class))).thenReturn(rv);
191
192         List<Approval> list = new ArrayList<Approval>();
193         list.add(approval);
194         Approval.delayDelete(trans, dao, false, list, "text");
195     }
196
197     @Test
198     public void testDelayDeleteResultNotOk() {
199         approval = new Approval(id, ticket, "approver",  "user", "memo", "operation", "status", "type", 100l);
200         AuthzTrans trans = mock(AuthzTrans.class);
201         ApprovalDAO dao = mock(ApprovalDAO.class);
202         LogTarget target = mock(LogTarget.class);
203
204         when(trans.info()).thenReturn(target);
205         Result<Void> rv = Result.err(new Exception());
206         when(dao.delete(any(AuthzTrans.class), any(ApprovalDAO.Data.class), any(Boolean.class))).thenReturn(rv);
207
208         List<Approval> list = new ArrayList<Approval>();
209         list.add(approval);
210         Approval.delayDelete(trans, dao, false, list, "text");
211     }
212
213
214 }