2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
8 * Unless otherwise specified, all software contained herein is licensed
9 * under the Apache License, Version 2.0 (the "License");
10 * you may not use this software except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * Unless otherwise specified, all documentation contained herein is licensed
22 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23 * you may not use this documentation except in compliance with the License.
24 * You may obtain a copy of the License at
26 * https://creativecommons.org/licenses/by/4.0/
28 * Unless required by applicable law or agreed to in writing, documentation
29 * distributed under the License is distributed on an "AS IS" BASIS,
30 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31 * See the License for the specific language governing permissions and
32 * limitations under the License.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalsdk.analytics.scheduler;
40 import static org.mockito.Mockito.mock;
41 import static org.mockito.Mockito.when;
43 import java.sql.Connection;
44 import java.sql.DatabaseMetaData;
45 import java.sql.ResultSet;
46 import java.sql.Statement;
48 import javax.sql.DataSource;
50 import org.junit.Before;
51 import org.junit.Test;
52 import org.junit.runner.RunWith;
53 import org.mockito.Matchers;
54 import org.mockito.Mock;
55 import org.mockito.MockitoAnnotations;
56 import org.mockito.invocation.InvocationOnMock;
57 import org.mockito.stubbing.Answer;
58 import org.onap.portalsdk.analytics.error.RaptorException;
59 import org.onap.portalsdk.analytics.scheduler.SchedulerUtil.Executor;
60 import org.onap.portalsdk.analytics.system.DbUtils;
61 import org.onap.portalsdk.analytics.system.Globals;
62 import org.onap.portalsdk.analytics.util.AppConstants;
63 import org.onap.portalsdk.core.web.support.AppUtils;
64 import org.powermock.api.mockito.PowerMockito;
65 import org.powermock.core.classloader.annotations.PrepareForTest;
66 import org.powermock.modules.junit4.PowerMockRunner;
68 @RunWith(PowerMockRunner.class)
69 @PrepareForTest({ AppConstants.class, SendNotifications.class, SchedulerUtil.class, SendEmail.class, Globals.class, AppUtils.class,
71 public class SendNotificationsTest {
74 SchedulerUtil schedulerUtil;
83 DatabaseMetaData dMData;
89 public void init() throws Exception {
90 PowerMockito.mockStatic(Globals.class);
91 PowerMockito.mockStatic(AppUtils.class);
92 PowerMockito.mockStatic(DbUtils.class);
93 DataSource ds = mock(DataSource.class);
94 when(ds.getConnection()).thenReturn(conn);
95 when(DbUtils.getConnection()).thenReturn(conn);
96 MockitoAnnotations.initMocks(this);
97 PowerMockito.whenNew(SchedulerUtil.class).withNoArguments().thenReturn(schedulerUtil);
98 PowerMockito.doNothing().when(sendEmail).setSchedulerUtil(schedulerUtil);
103 public void send_notificationTest() throws RaptorException, Exception {
104 SendNotifications sendNotifications = new SendNotifications();
105 Statement stat = mock(Statement.class);
106 ResultSet rset = mock(ResultSet.class);
107 when(Globals.getSchedulerInterval()).thenReturn(2147483647);
108 when(Globals.getAvailableSchedules()).thenReturn("test");
109 when(Globals.getCurrentDateString()).thenReturn("test");
110 when(schedulerUtil.getConnection()).thenReturn(conn);
111 when(conn.createStatement()).thenReturn(stat);
112 when(rset.getInt(Matchers.anyInt())).thenReturn(10);
113 when(rset.next()).thenReturn(true).thenReturn(false);
114 when(rset.getTimestamp("run_date")).thenReturn(new java.sql.Timestamp(0));
115 when(stat.executeQuery(Matchers.anyString())).thenReturn(rset);
116 sendNotifications.send_notification("test", "test", "test", "test", 30);