2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
22 package org.onap.policy.admin;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import static org.mockito.Mockito.mock;
27 import java.util.ArrayList;
28 import java.util.List;
29 import org.junit.Before;
30 import org.junit.Test;
31 import static org.mockito.Mockito.when;
32 import org.onap.policy.common.utils.network.NetworkUtil;
33 import org.onap.policy.controller.PolicyController;
34 import org.onap.policy.rest.dao.CommonClassDao;
35 import org.onap.policy.rest.jpa.PolicyVersion;
36 import org.onap.policy.rest.jpa.WatchPolicyNotificationTable;
38 public class PolicyNotificationMailTest {
40 private PolicyVersion version;
41 private String policyName = "com/Config_Test";
42 private CommonClassDao commonClassDao;
43 private List<Object> data = null;
46 public void setUp() throws Exception {
47 PolicyController.setjUnit(true);
48 PolicyController.setSmtpApplicationName("Test");
49 PolicyController.setSmtpEmailExtension("test.com");
50 PolicyController.setSmtpHost("localhost");
51 PolicyController.setSmtpPassword("test");
52 PolicyController.setSmtpUsername("test");
55 * Allocate a port to which the mail sender should connect, but don't actually
56 * start a listener on the port so that connection attempts will be immediately
59 PolicyController.setSmtpPort(String.valueOf(NetworkUtil.allocPort()));
61 version = new PolicyVersion();
62 version.setPolicyName("com/Config_Test");
63 version.setModifiedBy("xyz");
65 WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
66 watch.setPolicyName("com/Config_Test");
67 data = new ArrayList<>();
70 commonClassDao = mock(CommonClassDao.class);
71 PolicyController.setCommonClassDao(commonClassDao);
72 when(commonClassDao.getDataByQuery(
73 "from WatchPolicyNotificationTable where policyName like:policyFileName", null))
78 public final void testJavaMailSenderImpl() {
79 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
81 assertTrue(notificationMail.javaMailSenderImpl() != null);
82 } catch (Exception e) {
88 public final void testSendMail() {
89 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
91 notificationMail.sendMail(version, policyName, "EditPolicy", commonClassDao);
92 notificationMail.sendMail(version, policyName, "Rename", commonClassDao);
93 notificationMail.sendMail(version, policyName, "DeleteAll", commonClassDao);
94 notificationMail.sendMail(version, policyName, "DeleteOne", commonClassDao);
95 notificationMail.sendMail(version, policyName, "DeleteScope", commonClassDao);
96 notificationMail.sendMail(version, policyName, "SwitchVersion", commonClassDao);
97 notificationMail.sendMail(version, policyName, "Move", commonClassDao);
98 } catch (Exception e) {