Security/ Package Name changes
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / service / AppContactUsServiceImplTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
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  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.portal.service;
39
40 import static org.junit.Assert.assertEquals;
41
42 import java.util.ArrayList;
43 import java.util.HashMap;
44 import java.util.List;
45
46 import javax.servlet.http.HttpServletRequest;
47 import javax.servlet.http.HttpServletResponse;
48
49 import org.junit.Before;
50 import org.junit.Test;
51 import org.mockito.InjectMocks;
52 import org.mockito.Mock;
53 import org.mockito.Mockito;
54 import org.mockito.MockitoAnnotations;
55 import org.onap.portalapp.portal.domain.AppContactUs;
56 import org.onap.portalapp.portal.domain.EPApp;
57 import org.onap.portalapp.portal.ecomp.model.AppCategoryFunctionsItem;
58 import org.onap.portalapp.portal.ecomp.model.AppContactUsItem;
59 import org.onap.portalapp.portal.framework.MockitoTestSuite;
60 import org.onap.portalapp.portal.service.AppContactUsService;
61 import org.onap.portalapp.portal.service.AppContactUsServiceImpl;
62 import org.onap.portalsdk.core.service.DataAccessService;
63 import org.onap.portalsdk.core.service.DataAccessServiceImpl;
64
65 public class AppContactUsServiceImplTest {
66
67         
68      @Mock
69          DataAccessService dataAccessService = new DataAccessServiceImpl();
70     
71      @Mock
72      AppContactUsService AppContactUsService = new AppContactUsServiceImpl();
73      
74      @Before
75         public void setup() {
76                 MockitoAnnotations.initMocks(this);
77         }
78         
79      @InjectMocks
80      AppContactUsServiceImpl appContactUsServiceImpl = new AppContactUsServiceImpl();
81
82         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
83
84         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
85         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
86         NullPointerException nullPointerException = new NullPointerException();
87         
88         
89         public EPApp getApp() {
90                 EPApp app = new EPApp();
91                 app.setName("Test");
92                 app.setImageUrl("test");
93                 app.setDescription("test");
94                 app.setNotes("test");
95                 app.setUrl("test");
96                 app.setId((long) 1);
97                 app.setAppRestEndpoint("test");
98                 app.setAlternateUrl("test");
99                 app.setName("test");
100                 app.setMlAppName("test");
101                 app.setMlAppAdminId("test");
102                 app.setUsername("test");
103                 app.setAppPassword("test");
104                 app.setOpen(true);
105                 app.setEnabled(false);
106                 app.setUebKey("test");
107                 app.setUebSecret("test");
108                 app.setUebTopicName("test");
109                 app.setAppType(1);
110                 return app;
111         }
112         @Test
113         public void getAppContactUsTest() throws Exception
114         {
115                 
116                 List<AppContactUsItem> contactUsItemList  = new ArrayList<>();
117                 AppContactUsItem appContactUsItem= new AppContactUsItem();
118                 appContactUsItem.setAppName("testNew");
119                 contactUsItemList.add(appContactUsItem);
120                 AppContactUsItem appContactUsItem1= new AppContactUsItem();
121                 appContactUsItem1.setAppName("test");
122                 contactUsItemList.add(appContactUsItem1);
123                 Mockito.when(dataAccessService.executeNamedQuery("getAppContactUsItems", null, null)).thenReturn(contactUsItemList);
124                 List<AppContactUsItem> expectedcontactUsItemList = appContactUsServiceImpl.getAppContactUs();
125                 assertEquals(expectedcontactUsItemList, contactUsItemList);             
126         }
127         
128         @Test
129         public void getAppsAndContactsTest() throws Exception
130         {
131                 List<AppContactUsItem> contactUsItemList  = new ArrayList<>();
132                 AppContactUsItem appContactUsItem= new AppContactUsItem();
133                 appContactUsItem.setAppName("testNew");
134                 contactUsItemList.add(appContactUsItem);
135                 AppContactUsItem appContactUsItem1= new AppContactUsItem();
136                 appContactUsItem1.setAppName("test");
137                 contactUsItemList.add(appContactUsItem1);
138                 Mockito.when(dataAccessService.executeNamedQuery("getAppsAndContacts", null, null)).thenReturn(contactUsItemList);
139                 List<AppContactUsItem> expectedcontactUsItemList = appContactUsServiceImpl.getAppsAndContacts();
140                 assertEquals(expectedcontactUsItemList, contactUsItemList);             
141         }
142         
143         @Test
144         public void getAppCategoryFunctionsTest() throws Exception
145         {
146                 List<AppCategoryFunctionsItem> list  = new ArrayList<>();
147                 Mockito.when(dataAccessService.executeNamedQuery("getAppCategoryFunctions", null, null)).thenReturn(list);
148                 List<AppCategoryFunctionsItem> expectedlist = appContactUsServiceImpl.getAppCategoryFunctions();
149                 assertEquals(list, expectedlist); 
150         }
151         
152         @Test(expected = java.lang.Exception.class)
153         public void saveAppContactUsTest() throws Exception
154         {
155                 HashMap<String, Object> map = new HashMap<String, Object>();
156                 List<AppContactUsItem> contactUsModelList = new ArrayList<>();
157                 AppContactUsItem appContactUsItem= new AppContactUsItem();
158                 appContactUsItem.setAppId((long) 1);
159                 contactUsModelList.add(appContactUsItem);
160                 AppContactUs appContact = new AppContactUs();
161                 Mockito.when(dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(appContact);
162                 EPApp app = getApp();
163                 Mockito.when(dataAccessService.getDomainObject(EPApp.class, 1, new HashMap<String, Object>())).thenReturn(app);
164                 AppContactUs contactUs  = new AppContactUs();
165                 contactUs.setApp(app);
166                 contactUs.setDescription(appContactUsItem.getDescription());
167                 contactUs.setContactName(appContactUsItem.getContactName());
168                 contactUs.setContactEmail(appContactUsItem.getContactEmail());
169                 contactUs.setActiveYN(appContactUsItem.getActiveYN());
170                 contactUs.setUrl(appContactUsItem.getUrl());
171                 Mockito.doNothing().when(dataAccessService).saveDomainObject(contactUs,map);
172                 appContactUsServiceImpl.saveAppContactUs(contactUsModelList);
173         }
174         
175         @Test(expected = java.lang.NullPointerException.class)
176         public void deleteContactUsTest() throws Exception
177         {
178                 HashMap<String, Object> map = new HashMap<String, Object>();
179                 AppContactUs contactUs = new AppContactUs();
180                 Mockito.when((AppContactUs) dataAccessService.getDomainObject(AppContactUs.class, 1, map)).thenReturn(contactUs);
181                 appContactUsServiceImpl.deleteContactUs((long) 1);
182         }
183         
184 }