2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.policy.admin;
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24 import static org.mockito.Mockito.mock;
26 import java.util.ArrayList;
27 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.controller.PolicyController;
33 import org.onap.policy.rest.dao.CommonClassDao;
34 import org.onap.policy.rest.jpa.PolicyVersion;
35 import org.onap.policy.rest.jpa.WatchPolicyNotificationTable;
37 public class PolicyNotificationMailTest {
39 private PolicyVersion version;
40 private String policyName = "com/Config_Test";
41 private CommonClassDao commonClassDao;
42 private List<Object> data = null;
45 public void setUp() throws Exception {
46 PolicyController.setjUnit(true);
47 PolicyController.setSmtpApplicationName("Test");
48 PolicyController.setSmtpEmailExtension("test.com");
49 PolicyController.setSmtpHost("test");
50 PolicyController.setSmtpPort("23");
51 PolicyController.setSmtpPassword("test");
52 PolicyController.setSmtpUsername("test");
54 version = new PolicyVersion();
55 version.setPolicyName("com/Config_Test");
56 version.setModifiedBy("xyz");
58 WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
59 watch.setPolicyName("com/Config_Test");
60 data = new ArrayList<>();
63 commonClassDao = mock(CommonClassDao.class);
64 PolicyController.setCommonClassDao(commonClassDao);
65 when(commonClassDao.getDataByQuery("from WatchPolicyNotificationTable where policyName like:policyFileName", null)).thenReturn(data);
69 public final void testJavaMailSenderImpl() {
70 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
72 assertTrue(notificationMail.javaMailSenderImpl() != null);
79 public final void testSendMail() {
80 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
82 notificationMail.sendMail(version, policyName, "EditPolicy", commonClassDao);
83 notificationMail.sendMail(version, policyName, "Rename", commonClassDao);
84 notificationMail.sendMail(version, policyName, "DeleteAll", commonClassDao);
85 notificationMail.sendMail(version, policyName, "DeleteOne", commonClassDao);
86 notificationMail.sendMail(version, policyName, "DeleteScope", commonClassDao);
87 notificationMail.sendMail(version, policyName, "SwitchVersion", commonClassDao);
88 notificationMail.sendMail(version, policyName, "Move", commonClassDao);