summaryrefslogtreecommitdiffstats
path: root/auth/auth-cass/src/test/java/com/att/dao/aaf/test/JU_DelegateDAO.java
blob: 1a4d21c42fddd43dcaf37d733206d9cc3f1e4e5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
 * ============LICENSE_START====================================================
 * org.onap.aaf
 * ===========================================================================
 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
 * ===========================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END====================================================
 *
 */

package com.att.dao.aaf.test;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.nio.ByteBuffer;
import java.util.Date;
import java.util.List;

import org.junit.Test;
import org.onap.aaf.auth.dao.cass.DelegateDAO;
import org.onap.aaf.auth.dao.cass.DelegateDAO.Data;
import org.onap.aaf.auth.layer.Result;


public class JU_DelegateDAO  extends AbsJUCass {
	@Test
	public void testCRUD() throws Exception {
		DelegateDAO dao = new DelegateDAO(trans, cluster, AUTHZ);
		DelegateDAO.Data data = new DelegateDAO.Data();
//		TODO: Clean out AT&T specific data
		data.user = "jg1555";
		data.delegate = "rd8227";
		data.expires = new Date();
		
//        Bytification
        ByteBuffer bb = data.bytify();
        Data bdata = new DelegateDAO.Data();
        bdata.reconstitute(bb);
        compare(data, bdata);

		try {
			// Test create
			Result<Data> ddcr = dao.create(trans,data);
			assertTrue(ddcr.isOK());
			
			
			// Read by User
			Result<List<DelegateDAO.Data>> records = dao.read(trans,data.user);
			assertTrue(records.isOKhasData());
			for(DelegateDAO.Data rdata : records.value) 
				compare(data,rdata);

			// Read by Delegate
			records = dao.readByDelegate(trans,data.delegate);
			assertTrue(records.isOKhasData());
			for(DelegateDAO.Data rdata : records.value) 
				compare(data,rdata);
			
			// Update
			// TODO: Clean out AT&T specific data
			data.delegate = "pf2819";
			data.expires = new Date();
			assertTrue(dao.update(trans, data).isOK());

			// Read by User
			records = dao.read(trans,data.user);
			assertTrue(records.isOKhasData());
			for(DelegateDAO.Data rdata : records.value) 
				compare(data,rdata);

			// Read by Delegate
			records = dao.readByDelegate(trans,data.delegate);
			assertTrue(records.isOKhasData());
			for(DelegateDAO.Data rdata : records.value) 
				compare(data,rdata);

			// Test delete
			dao.delete(trans,data, true);
			records = dao.read(trans,data.user);
			assertTrue(records.isEmpty());
			
			
		} finally {
			dao.close(trans);
		}
	}
	
	private void compare(Data d1, Data d2) {
		assertEquals(d1.user, d2.user);
		assertEquals(d1.delegate, d2.delegate);
		assertEquals(d1.expires,d2.expires);
	}


}