Remove spaces from dockerbuild script
[aaf/authz.git] / auth / auth-cass / src / test / java / com / att / dao / aaf / test / JU_FastCalling.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 com.att.dao.aaf.test;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26
27 import java.io.IOException;
28 import java.nio.ByteBuffer;
29 import java.security.NoSuchAlgorithmException;
30 import java.util.Date;
31 import java.util.List;
32
33 import org.junit.Test;
34 import org.onap.aaf.auth.dao.CassAccess;
35 import org.onap.aaf.auth.dao.cass.CredDAO;
36 import org.onap.aaf.auth.dao.cass.CredDAO.Data;
37 import org.onap.aaf.auth.layer.Result;
38 import org.onap.aaf.misc.env.APIException;
39
40 public class JU_FastCalling extends AbsJUCass {
41
42         @Test
43         public void test() throws IOException, NoSuchAlgorithmException, APIException {
44                 trans.setProperty("cassandra.writeConsistency.cred","ONE");
45                 
46                 CredDAO udao = new CredDAO(env.newTransNoAvg(),cluster,CassAccess.KEYSPACE);
47                 System.out.println("Starting calls");
48                 for(iterations=0;iterations<8;++iterations) {
49                         try {
50                                 // Create
51                         CredDAO.Data data = new CredDAO.Data();
52                         data.id = "m55555@aaf.att.com";
53                         data.type = CredDAO.BASIC_AUTH;
54                         data.cred      = ByteBuffer.wrap(userPassToBytes("m55555","mypass"));
55                         data.expires = new Date(System.currentTimeMillis() + 60000*60*24*90);
56                                 udao.create(trans,data);
57                                 
58                                 // Validate Read with key fields in Data
59                                 Result<List<CredDAO.Data>> rlcd = udao.read(trans,data);
60                                 assertTrue(rlcd.isOKhasData());
61                                 for(CredDAO.Data d : rlcd.value) {
62                                         checkData1(data,d);
63                                 }
64                                 
65                                 // Update
66                                 data.cred = ByteBuffer.wrap(userPassToBytes("m55555","mynewpass"));
67                                 udao.update(trans,data);
68                                 rlcd = udao.read(trans,data);
69                                 assertTrue(rlcd.isOKhasData());
70                                 for(CredDAO.Data d : rlcd.value) {
71                                         checkData1(data,d);
72                                 }                       
73                                 
74                                 udao.delete(trans,data, true);
75                         } finally {
76                                 updateTotals();
77                                 newTrans();
78                         }
79                 }
80
81         }
82
83         private void checkData1(Data data, Data d) {
84                 assertEquals(data.id,d.id);
85                 assertEquals(data.type,d.type);
86                 assertEquals(data.cred,d.cred);
87                 assertEquals(data.expires,d.expires);
88         }
89
90 }