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.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(
66 "from WatchPolicyNotificationTable where policyName like:policyFileName", null))
71 public final void testJavaMailSenderImpl() {
72 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
74 assertTrue(notificationMail.javaMailSenderImpl() != null);
75 } catch (Exception e) {
81 public final void testSendMail() {
82 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
84 notificationMail.sendMail(version, policyName, "EditPolicy", commonClassDao);
85 notificationMail.sendMail(version, policyName, "Rename", commonClassDao);
86 notificationMail.sendMail(version, policyName, "DeleteAll", commonClassDao);
87 notificationMail.sendMail(version, policyName, "DeleteOne", commonClassDao);
88 notificationMail.sendMail(version, policyName, "DeleteScope", commonClassDao);
89 notificationMail.sendMail(version, policyName, "SwitchVersion", commonClassDao);
90 notificationMail.sendMail(version, policyName, "Move", commonClassDao);
91 } catch (Exception e) {