Modification in JU_BatchDataViewTest.java
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / helpers / JU_BatchDataViewTest.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Modification Copyright © 2020 IBM.
8  * ===========================================================================
9  *
10  * Licensed under the Apache License, Version 2.0 (the "License");
11  * you may not use this file except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *      http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  * ============LICENSE_END====================================================
22  *
23  */
24
25 package org.onap.aaf.auth.batch.helpers;
26
27 import static org.junit.Assert.assertEquals;
28 import static org.mockito.MockitoAnnotations.initMocks;
29
30 import java.io.IOException;
31 import java.nio.ByteBuffer;
32 import java.util.Date;
33 import java.util.List;
34 import java.util.UUID;
35
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.mockito.Mock;
39 import org.mockito.Mockito;
40 import org.onap.aaf.auth.dao.cass.ApprovalDAO;
41 import org.onap.aaf.auth.dao.cass.FutureDAO;
42 import org.onap.aaf.auth.dao.cass.NsDAO;
43 import org.onap.aaf.auth.dao.cass.RoleDAO;
44 import org.onap.aaf.auth.dao.cass.UserRoleDAO;
45 import org.onap.aaf.auth.env.AuthzTrans;
46 import org.onap.aaf.auth.layer.Result;
47 import org.onap.aaf.cadi.PropAccess;
48 import org.onap.aaf.misc.env.APIException;
49 import org.onap.aaf.misc.env.TimeTaken;
50
51 import com.datastax.driver.core.Session;
52
53 public class JU_BatchDataViewTest {
54
55     @Mock
56     AuthzTrans trans;
57
58     @Mock
59     Session session;
60
61     @Mock
62     PropAccess access;
63
64     BatchDataView batchDataViewObj;
65
66     @Before
67     public void setUp() throws APIException, IOException {
68         initMocks(this);
69         batchDataViewObj = new BatchDataView(trans, session, true);
70         Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(
71                 Mockito.anyString(), Mockito.anyInt(), Mockito.anyString());
72     }
73
74     @Test
75     public void testNs() {
76         Result<NsDAO.Data> retVal = batchDataViewObj.ns(trans, "test");
77                 assertEquals(9,retVal.status);
78
79         NS n = new NS("test1", "test2", "test3", 1, 2);
80         NS.data.put("test", n);
81         retVal = batchDataViewObj.ns(trans, "test");
82                 assertEquals(0,retVal.status);
83     }
84
85     @Test
86     public void testRoleByName() {
87         Result<RoleDAO.Data> retVal = batchDataViewObj.roleByName(trans,
88                 "test");
89         assertEquals(9,retVal.status);
90
91         Role n = new Role("test1");
92         n.rdd = new RoleDAO.Data();
93         Role.byName.put("test", n);
94         retVal = batchDataViewObj.roleByName(trans, "test");
95         assertEquals(0,retVal.status);
96
97         n.rdd = null;
98         Role.byName.put("test", n);
99         retVal = batchDataViewObj.roleByName(trans, "test");
100         assertEquals(9,retVal.status);
101     }
102     @Test
103     public void testUrsByRole() {
104         Result<List<UserRoleDAO.Data>> retVal = batchDataViewObj
105                 .ursByRole(trans, "test");
106         assertEquals(9,retVal.status);
107
108         Role n = new Role("test1");
109         n.rdd = new RoleDAO.Data();
110         UserRole ur = new UserRole("user", "role", "ns", "rname", new Date());
111         (new UserRole.DataLoadVisitor()).visit(ur);
112         retVal = batchDataViewObj.ursByRole(trans, "role");
113         assertEquals(retVal.status,0);
114
115     }
116     @Test
117     public void testUrsByUser() {
118         Result<List<UserRoleDAO.Data>> retVal = batchDataViewObj
119                 .ursByUser(trans, "test");
120         assertEquals(retVal.status,9);
121
122         Role n = new Role("test1");
123         n.rdd = new RoleDAO.Data();
124         UserRole ur = new UserRole("user", "role", "ns", "rname", new Date());
125         (new UserRole.DataLoadVisitor()).visit(ur);
126         retVal = batchDataViewObj.ursByUser(trans, "user");
127         assertEquals(retVal.status,0);
128
129     }
130     @Test
131     public void testDeleteFuture() {
132         FutureDAO.Data dataObj = new FutureDAO.Data();
133         dataObj.id = new UUID(1000L, 1000L);
134         Result<FutureDAO.Data> retVal = batchDataViewObj.delete(trans, dataObj);
135         assertEquals(retVal.status,0);
136
137     }
138     @Test
139     public void testDeleteApproval() {
140         ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
141         dataObj.id = new UUID(1000L, 1000L);
142         Result<ApprovalDAO.Data> retVal = batchDataViewObj.delete(trans,
143                 dataObj);
144         assertEquals(retVal.status, 0);
145
146     }
147
148     @Test
149     public void testInsertApproval() {
150         ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
151         dataObj.id = new UUID(1000L, 1000L);
152         dataObj.memo = "memo";
153         dataObj.ticket = new UUID(1000L, 1000L);
154         Result<ApprovalDAO.Data> retVal = batchDataViewObj.insert(trans,
155                 dataObj);
156         assertEquals(retVal.status, 0);
157
158     }
159     @Test
160     public void testInsertFuture() {
161         FutureDAO.Data dataObj = new FutureDAO.Data();
162         dataObj.id = new UUID(1000L, 1000L);
163         dataObj.memo = "memo";
164         dataObj.construct = ByteBuffer.allocate(1000);
165         Result<FutureDAO.Data> retVal = batchDataViewObj.insert(trans, dataObj);
166         assertEquals(retVal.status, 0);
167
168         dataObj.target_key = "memo";
169         retVal = batchDataViewObj.insert(trans, dataObj);
170         assertEquals(retVal.status, 0);
171     }
172     @Test
173     public void testFlush() {
174         batchDataViewObj.flush();
175
176     }
177 }