1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * Copyright © 2017 Amdocs
\r
7 * * ===========================================================================
\r
8 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * * you may not use this file except in compliance with the License.
\r
10 * * You may obtain a copy of the License at
\r
12 * * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * * Unless required by applicable law or agreed to in writing, software
\r
15 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * * See the License for the specific language governing permissions and
\r
18 * * limitations under the License.
\r
19 * * ============LICENSE_END====================================================
\r
21 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 ******************************************************************************/
\r
24 package com.att.dao.aaf.test;
\r
26 import static org.junit.Assert.assertEquals;
\r
27 import static org.junit.Assert.assertNotNull;
\r
28 import static org.junit.Assert.assertTrue;
\r
30 import java.nio.ByteBuffer;
\r
31 import java.util.List;
\r
32 import java.util.Random;
\r
34 import org.junit.Test;
\r
36 import com.att.authz.layer.Result;
\r
37 import com.att.dao.aaf.cass.HistoryDAO;
\r
39 public class JU_HistoryDAO extends AbsJUCass {
\r
42 public void testCreate() throws Exception {
\r
43 HistoryDAO historyDAO = new HistoryDAO(trans, cluster, AUTHZ);
\r
44 HistoryDAO.Data data = createHistoryData();
\r
47 historyDAO.create(trans,data);
\r
48 Thread.sleep(200);// History Create is Async
\r
49 Result<List<HistoryDAO.Data>> records = historyDAO.readByUser(trans,data.user,data.yr_mon);
\r
50 assertTrue(records.isOKhasData());
\r
51 for(HistoryDAO.Data d : records.value) {
\r
52 assertHistory(data, d);
\r
55 historyDAO.close(trans);
\r
60 public void tesReadByUser() throws Exception {
\r
61 HistoryDAO historyDAO = new HistoryDAO(trans,cluster, AUTHZ);
\r
62 HistoryDAO.Data data = createHistoryData();
\r
65 historyDAO.create(trans,data);
\r
66 Thread.sleep(200);// History Create is Async
\r
67 Result<List<HistoryDAO.Data>> records = historyDAO.readByUser(trans, data.user,data.yr_mon);
\r
68 assertTrue(records.isOKhasData());
\r
69 for(HistoryDAO.Data d : records.value) {
\r
70 assertHistory(data, d);
\r
73 historyDAO.close(trans);
\r
79 public void readByUserAndMonth() throws Exception {
\r
80 HistoryDAO historyDAO = new HistoryDAO(trans,cluster, AUTHZ);
\r
81 HistoryDAO.Data data = createHistoryData();
\r
84 historyDAO.create(trans,data);
\r
85 Thread.sleep(200);// History Create is Async
\r
86 Result<List<HistoryDAO.Data>> records = historyDAO.readByUserAndMonth(trans,
\r
87 data.user, Integer.valueOf(String.valueOf(data.yr_mon).substring(0, 4)),
\r
88 Integer.valueOf(String.valueOf(data.yr_mon).substring(4, 6)));
\r
89 assertTrue(records.isOKhasData());
\r
90 for(HistoryDAO.Data d : records.value) {
\r
91 assertHistory(data, d);
\r
94 historyDAO.close(trans);
\r
100 // public void readByUserAndDay() throws Exception {
\r
101 // HistoryDAO historyDAO = new HistoryDAO(trans, cluster, AUTHZ);
\r
102 // HistoryDAO.Data data = createHistoryData();
\r
105 // historyDAO.create(trans, data);
\r
106 // Thread.sleep(200);// History Create is Async
\r
108 // String dayTime = String.valueOf(data.day_time);
\r
109 // String day = null;
\r
110 // if (dayTime.length() < 8)
\r
111 // day = dayTime.substring(0, 1);
\r
113 // day = dayTime.substring(0, 2);
\r
115 // List<HistoryDAO.Data> records = historyDAO.readByUserBetweenDates(trans,
\r
116 // data.user, Integer.valueOf(String.valueOf(data.yr_mon).substring(0, 4)),
\r
117 // Integer.valueOf(String.valueOf(data.yr_mon).substring(4, 6)),
\r
118 // Integer.valueOf(day), 0);
\r
119 // assertEquals(1,records.size());
\r
120 // for(HistoryDAO.Data d : records) {
\r
121 // assertHistory(data, d);
\r
124 // historyDAO.close(trans);
\r
127 private HistoryDAO.Data createHistoryData() {
\r
128 HistoryDAO.Data data = HistoryDAO.newInitedData();
\r
129 Random random = new Random();
\r
130 data.user = "test" + random.nextInt();
\r
131 data.action = "add";
\r
132 data.target = "history";
\r
133 data.memo = "adding a row into history table";
\r
134 // data.detail().put("id", "test");
\r
135 // data.detail().put("name", "test");
\r
136 //String temp = "Test Blob Message";
\r
137 data.reconstruct = ByteBuffer.wrap("Temp Blob Message".getBytes());
\r
141 private void assertHistory(HistoryDAO.Data ip, HistoryDAO.Data op) {
\r
142 assertEquals(ip.yr_mon, op.yr_mon);
\r
143 // assertEquals(ip.day_time, op.day_time);
\r
144 assertEquals(ip.user, op.user);
\r
145 assertEquals(ip.action, op.action);
\r
146 assertEquals(ip.target, op.target);
\r
147 assertEquals(ip.memo, op.memo);
\r
148 //TODO : have to see if third party assert utility can be used
\r
149 // assertTrue(CollectionUtils.isEqualCollection(ip.detail, op.detail));
\r
150 // for (String key : ip.detail().keySet()) {
\r
151 // assertNotNull(op.detail().get(key));
\r
153 assertNotNull(op.reconstruct);
\r