2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
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
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.
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
26 * https://creativecommons.org/licenses/by/4.0/
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.
34 * ============LICENSE_END============================================
36 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
38 package org.onap.portalapp.portal.logging.aop;
40 import static org.junit.Assert.assertNotEquals;
42 import java.util.ArrayList;
43 import java.util.List;
45 import org.junit.Before;
46 import org.junit.Test;
47 import org.junit.runner.RunWith;
48 import org.mockito.InjectMocks;
49 import org.mockito.Mock;
50 import org.mockito.Mockito;
51 import org.mockito.MockitoAnnotations;
52 import org.onap.portalapp.portal.core.MockEPUser;
53 import org.onap.portalapp.portal.domain.EPUser;
54 import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
55 import org.onap.portalapp.portal.utils.EcompPortalUtils;
56 import org.onap.portalapp.util.EPUserUtils;
57 import org.onap.portalsdk.core.util.SystemProperties;
58 import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
59 import org.onap.portalsdk.core.web.support.AppUtils;
60 import org.powermock.api.mockito.PowerMockito;
61 import org.powermock.core.classloader.annotations.PrepareForTest;
62 import org.powermock.modules.junit4.PowerMockRunner;
63 import org.springframework.mock.web.MockHttpServletRequest;
64 import org.springframework.mock.web.MockHttpSession;
66 @RunWith(PowerMockRunner.class)
67 @PrepareForTest({ EcompPortalUtils.class, SystemProperties.class,
68 EPCommonSystemProperties.class })
69 public class EPEELFLoggerAdviceTest {
73 MockitoAnnotations.initMocks(this);
77 SecurityEventTypeEnum securityEventTypeEnum;
80 EPEELFLoggerAdvice epEELFLoggerAdvice = new EPEELFLoggerAdvice();
83 @SuppressWarnings("static-access")
84 public void getCurrentDateTimeUTCTest(){
85 String actual = epEELFLoggerAdvice.getCurrentDateTimeUTC();
86 assertNotEquals("", actual);
89 MockEPUser mockUser = new MockEPUser();
92 public void loadServletRequestBasedDefaultsTest(){
93 PowerMockito.mockStatic(EPCommonSystemProperties.class);
94 PowerMockito.mockStatic(EcompPortalUtils.class);
95 PowerMockito.mockStatic(EPUserUtils.class);
96 PowerMockito.mockStatic(AppUtils.class);
97 PowerMockito.mockStatic(SystemProperties.class);
98 EPUser user = mockUser.mockEPUser();
99 MockHttpSession session = new MockHttpSession();
100 session.setAttribute("user_attribute_name", user);
101 MockHttpServletRequest request = new MockHttpServletRequest();
102 request.setServletPath("http:test.com");
103 request.setSession(session);
104 request.addHeader("user-agent", "Mozilla/5.0");
105 Mockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("user_attribute_name");
106 epEELFLoggerAdvice.loadServletRequestBasedDefaults(request, securityEventTypeEnum);
110 public void afterTest(){
111 PowerMockito.mockStatic(EPCommonSystemProperties.class);
112 PowerMockito.mockStatic(EcompPortalUtils.class);
113 PowerMockito.mockStatic(EPUserUtils.class);
114 PowerMockito.mockStatic(AppUtils.class);
115 PowerMockito.mockStatic(SystemProperties.class);
116 EPUser user = mockUser.mockEPUser();
117 MockHttpSession session = new MockHttpSession();
118 session.setAttribute("user_attribute_name", user);
119 MockHttpServletRequest request = new MockHttpServletRequest();
120 request.setServletPath("http:test.com");
121 request.setSession(session);
122 request.addHeader("user-agent", "Mozilla/5.0");
123 Mockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("user_attribute_name");
124 List<Object> args = new ArrayList<>();
125 args.add("testClassName");
126 args.add("testMethodName");
127 Object[] passOnArgs = args.toArray(new Object[args.size()]);
128 List<Object> args2 = new ArrayList<>();
130 Object[] httpArgs = args2.toArray(new Object[args2.size()]);
131 epEELFLoggerAdvice.after(securityEventTypeEnum, "200", "200", httpArgs, null, passOnArgs);
135 public void BeforeTest(){
136 PowerMockito.mockStatic(EPCommonSystemProperties.class);
137 PowerMockito.mockStatic(EcompPortalUtils.class);
138 PowerMockito.mockStatic(EPUserUtils.class);
139 PowerMockito.mockStatic(AppUtils.class);
140 PowerMockito.mockStatic(SystemProperties.class);
141 EPUser user = mockUser.mockEPUser();
142 MockHttpSession session = new MockHttpSession();
143 session.setAttribute("user_attribute_name", user);
144 MockHttpServletRequest request = new MockHttpServletRequest();
145 request.setServletPath("http:test.com");
146 request.setSession(session);
147 request.addHeader("user-agent", "Mozilla/5.0");
148 Mockito.when(SystemProperties.getProperty(SystemProperties.USER_ATTRIBUTE_NAME)).thenReturn("user_attribute_name");
149 List<Object> args = new ArrayList<>();
150 args.add("testClassName");
151 args.add("testMethodName");
152 Object[] passOnArgs = args.toArray(new Object[args.size()]);
153 List<Object> args2 = new ArrayList<>();
155 Object[] httpArgs = args2.toArray(new Object[args2.size()]);
156 epEELFLoggerAdvice.before(securityEventTypeEnum, httpArgs, passOnArgs);