2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.batch.helpers;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.MockitoAnnotations.initMocks;
27 import java.io.IOException;
28 import java.nio.ByteBuffer;
29 import java.util.Date;
30 import java.util.List;
31 import java.util.UUID;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.mockito.Mock;
36 import org.mockito.Mockito;
37 import org.onap.aaf.auth.dao.cass.ApprovalDAO;
38 import org.onap.aaf.auth.dao.cass.FutureDAO;
39 import org.onap.aaf.auth.dao.cass.NsDAO;
40 import org.onap.aaf.auth.dao.cass.RoleDAO;
41 import org.onap.aaf.auth.dao.cass.UserRoleDAO;
42 import org.onap.aaf.auth.env.AuthzTrans;
43 import org.onap.aaf.auth.layer.Result;
44 import org.onap.aaf.cadi.PropAccess;
45 import org.onap.aaf.misc.env.APIException;
46 import org.onap.aaf.misc.env.TimeTaken;
48 import com.datastax.driver.core.Session;
50 public class JU_BatchDataViewTest {
61 BatchDataView batchDataViewObj;
64 public void setUp() throws APIException, IOException {
66 batchDataViewObj = new BatchDataView(trans, session, true);
67 Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(
68 Mockito.anyString(), Mockito.anyInt(), Mockito.anyString());
72 public void testNs() {
73 Result<NsDAO.Data> retVal = batchDataViewObj.ns(trans, "test");
74 assertTrue(retVal.status == 9);
76 NS n = new NS("test1", "test2", "test3", 1, 2);
77 NS.data.put("test", n);
78 retVal = batchDataViewObj.ns(trans, "test");
79 assertTrue(retVal.status == 0);
83 public void testRoleByName() {
84 Result<RoleDAO.Data> retVal = batchDataViewObj.roleByName(trans,
86 assertTrue(retVal.status == 9);
88 Role n = new Role("test1");
89 n.rdd = new RoleDAO.Data();
90 Role.byName.put("test", n);
91 retVal = batchDataViewObj.roleByName(trans, "test");
92 assertTrue(retVal.status == 0);
95 Role.byName.put("test", n);
96 retVal = batchDataViewObj.roleByName(trans, "test");
97 assertTrue(retVal.status == 9);
100 public void testUrsByRole() {
101 Result<List<UserRoleDAO.Data>> retVal = batchDataViewObj
102 .ursByRole(trans, "test");
103 assertTrue(retVal.status == 9);
105 Role n = new Role("test1");
106 n.rdd = new RoleDAO.Data();
107 UserRole ur = new UserRole("user", "role", "ns", "rname", new Date());
108 (new UserRole.DataLoadVisitor()).visit(ur);
109 retVal = batchDataViewObj.ursByRole(trans, "role");
110 assertTrue(retVal.status == 0);
114 public void testUrsByUser() {
115 Result<List<UserRoleDAO.Data>> retVal = batchDataViewObj
116 .ursByUser(trans, "test");
117 assertTrue(retVal.status == 9);
119 Role n = new Role("test1");
120 n.rdd = new RoleDAO.Data();
121 UserRole ur = new UserRole("user", "role", "ns", "rname", new Date());
122 (new UserRole.DataLoadVisitor()).visit(ur);
123 retVal = batchDataViewObj.ursByUser(trans, "user");
124 assertTrue(retVal.status == 0);
128 public void testDeleteFuture() {
129 FutureDAO.Data dataObj = new FutureDAO.Data();
130 dataObj.id = new UUID(1000L, 1000L);
131 Result<FutureDAO.Data> retVal = batchDataViewObj.delete(trans, dataObj);
132 assertTrue(retVal.status == 0);
136 public void testDeleteApproval() {
137 ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
138 dataObj.id = new UUID(1000L, 1000L);
139 Result<ApprovalDAO.Data> retVal = batchDataViewObj.delete(trans,
141 assertTrue(retVal.status == 0);
146 public void testInsertApproval() {
147 ApprovalDAO.Data dataObj = new ApprovalDAO.Data();
148 dataObj.id = new UUID(1000L, 1000L);
149 dataObj.memo = "memo";
150 dataObj.ticket = new UUID(1000L, 1000L);
151 Result<ApprovalDAO.Data> retVal = batchDataViewObj.insert(trans,
153 assertTrue(retVal.status == 0);
157 public void testInsertFuture() {
158 FutureDAO.Data dataObj = new FutureDAO.Data();
159 dataObj.id = new UUID(1000L, 1000L);
160 dataObj.memo = "memo";
161 dataObj.construct = ByteBuffer.allocate(1000);
162 Result<FutureDAO.Data> retVal = batchDataViewObj.insert(trans, dataObj);
163 assertTrue(retVal.status == 0);
165 dataObj.target_key = "memo";
166 retVal = batchDataViewObj.insert(trans, dataObj);
167 assertTrue(retVal.status == 0);
170 public void testFlush() {
171 batchDataViewObj.flush();