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;
51 * @throws Exception should not throw one
54 public void setUp() throws Exception {
55 PolicyController.setjUnit(true);
56 PolicyController.setSmtpApplicationName("Test");
57 PolicyController.setSmtpEmailExtension("test.com");
58 PolicyController.setSmtpHost("localhost");
59 PolicyController.setSmtpPassword("test");
60 PolicyController.setSmtpUsername("test");
63 * Allocate a port to which the mail sender should connect, but don't actually
64 * start a listener on the port so that connection attempts will be immediately
67 PolicyController.setSmtpPort(String.valueOf(NetworkUtil.allocPort()));
69 version = new PolicyVersion();
70 version.setPolicyName("com/Config_Test");
71 version.setModifiedBy("xyz");
73 WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
74 watch.setPolicyName("com/Config_Test");
75 data = new ArrayList<>();
78 commonClassDao = mock(CommonClassDao.class);
79 PolicyController.setCommonClassDao(commonClassDao);
80 when(commonClassDao.getDataByQuery("from WatchPolicyNotificationTable where policyName like:policyFileName",
81 null)).thenReturn(data);
85 public final void testJavaMailSenderImpl() {
86 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
88 assertTrue(notificationMail.javaMailSenderImpl() != null);
89 } catch (Exception e) {
95 public final void testSendMail() {
96 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
98 notificationMail.sendMail(version, policyName, "EditPolicy", commonClassDao);
99 notificationMail.sendMail(version, policyName, "Rename", commonClassDao);
100 notificationMail.sendMail(version, policyName, "DeleteAll", commonClassDao);
101 notificationMail.sendMail(version, policyName, "DeleteOne", commonClassDao);
102 notificationMail.sendMail(version, policyName, "DeleteScope", commonClassDao);
103 notificationMail.sendMail(version, policyName, "SwitchVersion", commonClassDao);
104 notificationMail.sendMail(version, policyName, "Move", commonClassDao);
105 } catch (Exception e) {