Merge "Sonar Fix: Owner.java"
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / test / JU_NotificationTest.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 package org.onap.aaf.auth.batch.test;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.Mockito.when;
27 import static org.mockito.MockitoAnnotations.initMocks;
28
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.onap.aaf.auth.batch.actions.Message;
33 import org.onap.aaf.auth.batch.helpers.Creator;
34 import org.onap.aaf.auth.batch.helpers.Notification;
35 import org.onap.aaf.auth.batch.helpers.Notification.TYPE;
36 import org.onap.aaf.auth.batch.helpers.creators.RowCreator;
37 import org.onap.aaf.auth.env.AuthzTrans;
38 import org.onap.aaf.misc.env.Env;
39 import org.onap.aaf.misc.env.LogTarget;
40 import org.onap.aaf.misc.env.TimeTaken;
41
42 public class JU_NotificationTest {
43
44         @Mock
45         private AuthzTrans trans;
46         @Mock
47         private Creator<Notification> creator;
48         @Mock
49         private TimeTaken tt;
50
51         @Mock
52         private LogTarget logTarget;
53         private Message msg;
54
55         @Before
56         public void setUp() throws Exception {
57                 initMocks(this);
58
59                 msg = new Message();
60                 msg.line("%n", "Message");
61
62                 when(trans.info()).thenReturn(logTarget);
63                 when(trans.start("Load Notify", Env.REMOTE)).thenReturn(tt);
64         }
65
66         @Test
67         public void test() {
68                 Notification notification = Notification.create("user", TYPE.CN);
69                 assertEquals(notification.checksum(), 0);
70                 notification.set(msg);
71                 assertEquals(notification.checksum(), 10);
72                 assertNull(Notification.get("user", TYPE.CN));
73                 assertTrue(notification.update(trans, null, true));
74                 assertTrue(notification.toString().contains("\"user\",\"CN\","));
75
76                 Notification.v2_0_18.create(RowCreator.getRow());
77                 assertEquals(Notification.v2_0_18.select(), "SELECT user,type,last,checksum FROM authz.notify LIMIT 100000");
78
79         }
80 }