Replace ecomp references
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / controller / WebAnalyticsExtAppControllerTest.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  * 
37  */
38 package org.onap.portalapp.portal.controller;
39
40 import static org.junit.Assert.*;
41
42 import java.io.InputStream;
43 import java.nio.charset.StandardCharsets;
44
45 import javax.servlet.http.HttpServletRequest;
46 import javax.servlet.http.HttpServletResponse;
47
48 import org.apache.commons.io.IOUtils;
49 import org.junit.Before;
50 import org.junit.Test;
51 import org.junit.runner.RunWith;
52 import org.mockito.InjectMocks;
53 import org.mockito.Mock;
54 import org.mockito.Mockito;
55 import org.mockito.MockitoAnnotations;
56 import org.onap.portalapp.portal.controller.WebAnalyticsExtAppController;
57 import org.onap.portalapp.portal.domain.EPApp;
58 import org.onap.portalapp.portal.framework.MockitoTestSuite;
59 import org.onap.portalapp.portal.service.AdminRolesService;
60 import org.onap.portalapp.portal.service.AdminRolesServiceImpl;
61 import org.onap.portalapp.portal.service.AppsCacheService;
62 import org.onap.portalapp.portal.service.AppsCacheServiceImple;
63 import org.onap.portalapp.portal.transport.Analytics;
64 import org.onap.portalsdk.core.onboarding.crossapi.PortalAPIResponse;
65 import org.onap.portalsdk.core.service.AuditService;
66 import org.onap.portalsdk.core.service.AuditServiceImpl;
67 import org.onap.portalsdk.core.util.SystemProperties;
68 import org.powermock.api.mockito.PowerMockito;
69 import org.powermock.core.classloader.annotations.PrepareForTest;
70 import org.powermock.modules.junit4.PowerMockRunner;
71
72
73 @RunWith(PowerMockRunner.class)
74 @PrepareForTest({SystemProperties.class,IOUtils.class,Object.class})
75 public class WebAnalyticsExtAppControllerTest {
76
77         
78         
79         @InjectMocks
80         WebAnalyticsExtAppController webAnalyticsExtAppController = new WebAnalyticsExtAppController();
81
82         @Mock
83         AdminRolesService adminRolesService = new AdminRolesServiceImpl();
84         
85         @Mock
86         AppsCacheService appCacheService = new AppsCacheServiceImple();
87
88         @Mock
89         AuditService auditService = new AuditServiceImpl();
90
91 //      @Mock 
92 //      InputStream analyticsFileStream;
93
94
95         @Before
96         public void setup() {
97                 MockitoAnnotations.initMocks(this);
98         }
99
100         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
101
102         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
103         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
104         NullPointerException nullPointerException = new NullPointerException();
105         
106         /*@Test
107         public void getAnalyticsScriptTest() throws Exception
108         {
109                 String expectedResponse = "http://www.ecomp.com";
110
111                 InputStream analyticsFileStream = null;
112                 PowerMockito.mockStatic(SystemProperties.class);
113                 PowerMockito.mockStatic(IOUtils.class);
114                 Mockito.when(IOUtils.toString(analyticsFileStream, StandardCharsets.UTF_8.name())).thenReturn("PORTAL_ENV_URL");
115                 Mockito.when(SystemProperties.getProperty("frontend_url")).thenReturn("http://www.ecomp.com/test");
116                 String actualResponse = webAnalyticsExtAppController.getAnalyticsScript(mockedRequest);
117 //      assertNull(webAnalyticsExtAppController.getAnalyticsScript(mockedRequest));
118                 
119         //      System.out.println(actualResponse);
120                 assertTrue(actualResponse.equals(expectedResponse));    
121         }*/
122
123         /*@Test
124         public void getAnalyticsScriptExceptionTest() throws Exception
125         {
126                 String expectedResponse = "";
127                 InputStream analyticsFileStream = null;
128                 PowerMockito.mockStatic(SystemProperties.class);
129                 PowerMockito.mockStatic(IOUtils.class);
130                 Mockito.when(IOUtils.toString(analyticsFileStream, StandardCharsets.UTF_8.name())).thenThrow(nullPointerException);
131                 Mockito.when(SystemProperties.getProperty("frontend_url")).thenReturn("http://www.ecomp.com/test");
132        String actualResponse = webAnalyticsExtAppController.getAnalyticsScript(mockedRequest);
133           assertEquals(actualResponse,expectedResponse);
134         }*/
135
136         @Test
137         public void storeAnalyticsScriptIfAnalyticsNullTest() throws Exception
138         {
139                 PortalAPIResponse       expectedPortalAPIResponse = new PortalAPIResponse(true, "error");
140                 Analytics analytics= null;
141                 Mockito.when(mockedRequest.getHeader("uebkey")).thenReturn(null);
142                 PortalAPIResponse       actualPortalAPIResponse =       webAnalyticsExtAppController.storeAnalyticsScript(mockedRequest, analytics);
143                 assertTrue(expectedPortalAPIResponse.getMessage().equals(actualPortalAPIResponse.getMessage()));
144                 assertTrue(expectedPortalAPIResponse.getStatus().equals(actualPortalAPIResponse.getStatus()));  
145         }
146                 
147 }