Merge "Fixed TOSCA parsing bugs"
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / admin / PolicyNotificationMailTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20 package org.onap.policy.admin;
21
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24 import static org.mockito.Mockito.mock;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
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;
36
37 public class PolicyNotificationMailTest {
38
39         private PolicyVersion version;
40         private String policyName = "com/Config_Test";
41         private CommonClassDao commonClassDao;
42         private List<Object> data = null;
43         
44         @Before
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");
53                 
54                 version = new PolicyVersion();
55                 version.setPolicyName("com/Config_Test");
56                 version.setModifiedBy("xyz");
57                 
58                 WatchPolicyNotificationTable watch = new WatchPolicyNotificationTable();
59                 watch.setPolicyName("com/Config_Test");
60                 data = new ArrayList<>();
61                 data.add(watch);
62                 
63                 commonClassDao = mock(CommonClassDao.class);
64         PolicyController.setCommonClassDao(commonClassDao);
65         when(commonClassDao.getDataByQuery("from WatchPolicyNotificationTable where policyName like:policyFileName", null)).thenReturn(data);
66         }
67
68         @Test
69         public final void testJavaMailSenderImpl() {
70                 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
71                 try{
72                         assertTrue(notificationMail.javaMailSenderImpl() != null);
73                 }catch(Exception e){
74                         fail();
75                 }
76         }
77
78         @Test
79         public final void testSendMail() {
80                 PolicyNotificationMail notificationMail = new PolicyNotificationMail();
81                 try{
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);
89                 }catch(Exception e){
90                         fail();
91                 }
92         }
93
94 }