2ddd984b5b08734381d13ff7d18ceab51f8ec4dc
[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  * 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;
23
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.MockitoAnnotations.initMocks;
26
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;
32
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;
47
48 import com.datastax.driver.core.Session;
49
50 public class JU_BatchDataViewTest {
51
52     @Mock
53     AuthzTrans trans;
54
55     @Mock
56     Session session;
57
58     @Mock
59     PropAccess access;
60
61     BatchDataView batchDataViewObj;
62
63     @Before
64     public void setUp() throws APIException, IOException {
65         initMocks(this);
66         batchDataViewObj = new BatchDataView(trans, session, true);
67         Mockito.doReturn(Mockito.mock(TimeTaken.class)).when(trans).start(
68                 Mockito.anyString(), Mockito.anyInt(), Mockito.anyString());
69     }
70
71     @Test
72     public void testNs() {
73         Result<NsDAO.Data> retVal = batchDataViewObj.ns(trans, "test");
74         assertTrue(retVal.status == 9);
75
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);
80     }
81
82     @Test
83     public void testRoleByName() {
84         Result<RoleDAO.Data> retVal = batchDataViewObj.roleByName(trans,
85                 "test");
86         assertTrue(retVal.status == 9);
87
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);
93
94         n.rdd = null;
95         Role.byName.put("test", n);
96         retVal = batchDataViewObj.roleByName(trans, "test");
97         assertTrue(retVal.status == 9);
98     }
99     @Test
100     public void testUrsByRole() {
101         Result<List<UserRoleDAO.Data>> retVal = batchDataViewObj
102                 .ursByRole(trans, "test");
103         assertTrue(retVal.status == 9);
104
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);
111
112     }
113     @Test
114     public void testUrsByUser() {
115         Result<List<UserRoleDAO.Data>> retVal = batchDataViewObj
116                 .ursByUser(trans, "test");
117         assertTrue(retVal.status == 9);
118
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);
125
126     }
127     @Test
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);
133
134     }
135     @Test
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,
140                 dataObj);
141         assertTrue(retVal.status == 0);
142
143     }
144
145     @Test
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,
152                 dataObj);
153         assertTrue(retVal.status == 0);
154
155     }
156     @Test
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);
164
165         dataObj.target_key = "memo";
166         retVal = batchDataViewObj.insert(trans, dataObj);
167         assertTrue(retVal.status == 0);
168     }
169     @Test
170     public void testFlush() {
171         batchDataViewObj.flush();
172
173     }
174 }