2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (C) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file 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.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.admin;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
27 import static org.mockito.Mockito.mock;
28 import static org.mockito.Mockito.when;
30 import java.util.ArrayList;
31 import java.util.List;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.policy.common.utils.network.NetworkUtil;
36 import org.onap.policy.controller.PolicyController;
37 import org.onap.policy.rest.dao.CommonClassDao;
38 import org.onap.policy.rest.jpa.PolicyVersion;
39 import org.onap.policy.rest.jpa.WatchPolicyNotificationTable;
41 public class PolicyNotificationMailTest {
43 private PolicyVersion version;
44 private String policyName = "com/Config_Test";
45 private CommonClassDao commonClassDao;
46 private List<Object> data = null;
49 public void setUp() throws Exception {
50 PolicyController.setjUnit(true);
51 PolicyController.setSmtpApplicationName("Test");
52 PolicyController.setSmtpEmailExtension("test.com");
53 PolicyController.setSmtpHost("localhost");
54 PolicyController.setSmtpPassword("test");
55 PolicyController.setSmtpUsername("test");
58 * Allocate a port to which the mail sender should connect, but don't actually
59 * start a listener on the port so that connection attempts will be immediately
62 PolicyController.setSmtpPort(String.valueOf(NetworkUtil.allocPort()));
64 version = new PolicyVersion();
65 version.setPolicyName("com/Config_Test");
66 version.setModifiedBy("xyz");
68 WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
69 watch.setPolicyName("com/Config_Test");
70 data = new ArrayList<>();
73 commonClassDao = mock(CommonClassDao.class);
74 PolicyController.setCommonClassDao(commonClassDao);
75 when(commonClassDao.getDataByQuery("from WatchPolicyNotificationTable where policyName like:policyFileName",
76 null)).thenReturn(data);
80 public final void testJavaMailSenderImpl() {
81 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
83 assertTrue(notificationMail.javaMailSenderImpl() != null);
84 } catch (Exception e) {
90 public final void testSendMail() {
91 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
93 notificationMail.sendMail(version, policyName, "EditPolicy", commonClassDao);
94 notificationMail.sendMail(version, policyName, "Rename", commonClassDao);
95 notificationMail.sendMail(version, policyName, "DeleteAll", commonClassDao);
96 notificationMail.sendMail(version, policyName, "DeleteOne", commonClassDao);
97 notificationMail.sendMail(version, policyName, "DeleteScope", commonClassDao);
98 notificationMail.sendMail(version, policyName, "SwitchVersion", commonClassDao);
99 notificationMail.sendMail(version, policyName, "Move", commonClassDao);
100 } catch (Exception e) {