Improve Batches
[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.env.AuthzTrans;
37 import org.onap.aaf.misc.env.Env;
38 import org.onap.aaf.misc.env.LogTarget;
39 import org.onap.aaf.misc.env.TimeTaken;
40
41 public class JU_NotificationTest {
42
43         @Mock
44         private AuthzTrans trans;
45         @Mock
46         private Creator<Notification> creator;
47         @Mock
48         private TimeTaken tt;
49
50         @Mock
51         private LogTarget logTarget;
52         private Message msg;
53
54         @Before
55         public void setUp() throws Exception {
56                 initMocks(this);
57
58                 msg = new Message();
59                 msg.line("%n", "Message");
60
61                 when(trans.info()).thenReturn(logTarget);
62                 when(trans.start("Load Notify", Env.REMOTE)).thenReturn(tt);
63         }
64
65         @Test
66         public void test() {
67                 Notification notification = Notification.create("user", TYPE.CN);
68                 assertEquals(notification.checksum(), 0);
69                 notification.set(msg);
70                 assertEquals(notification.checksum(), 10);
71                 assertNull(Notification.get("user", TYPE.CN));
72                 assertTrue(notification.update(trans, null, true));
73                 assertTrue(notification.toString().contains("\"user\",\"CN\","));
74
75
76         }
77 }