2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2018 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright © 2018 IBM.
8 * ===================================================================
10 * Unless otherwise specified, all software contained herein is licensed
11 * under the Apache License, Version 2.0 (the "License");
12 * you may not use this software except in compliance with the License.
13 * You may obtain a copy of the License at
15 * http://www.apache.org/licenses/LICENSE-2.0
17 * Unless required by applicable law or agreed to in writing, software
18 * distributed under the License is distributed on an "AS IS" BASIS,
19 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 * See the License for the specific language governing permissions and
21 * limitations under the License.
23 * Unless otherwise specified, all documentation contained herein is licensed
24 * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25 * you may not use this documentation except in compliance with the License.
26 * You may obtain a copy of the License at
28 * https://creativecommons.org/licenses/by/4.0/
30 * Unless required by applicable law or agreed to in writing, documentation
31 * distributed under the License is distributed on an "AS IS" BASIS,
32 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33 * See the License for the specific language governing permissions and
34 * limitations under the License.
36 * ============LICENSE_END============================================
40 package org.onap.portalapp.portal.utils;
42 import org.junit.Assert;
43 import org.junit.Test;
44 import org.mockito.Mockito;
46 import ch.qos.logback.classic.Level;
47 import ch.qos.logback.classic.spi.ILoggingEvent;
48 import ch.qos.logback.core.spi.FilterReply;
50 public class CustomLoggingFilterTest {
53 public void decideTest(){
54 ILoggingEvent event = Mockito.mock(ILoggingEvent.class);
55 Mockito.when(event.getLevel()).thenReturn(Level.ERROR);
56 Mockito.when(event.getThreadName()).thenReturn("UEBConsumerThread");
57 Mockito.when(event.getLoggerName()).thenReturn("org.onap.nsa");
58 CustomLoggingFilter customLoggingFilter = new CustomLoggingFilter();
59 FilterReply reply = customLoggingFilter.decide(event);
60 Assert.assertEquals( FilterReply.DENY, reply);
64 public void decideNEUTRALTest(){
65 ILoggingEvent event = Mockito.mock(ILoggingEvent.class);
66 Mockito.when(event.getLevel()).thenReturn(Level.ERROR);
67 Mockito.when(event.getThreadName()).thenReturn("UEBConsumerThread");
68 Mockito.when(event.getLoggerName()).thenReturn("test");
69 CustomLoggingFilter customLoggingFilter = new CustomLoggingFilter();
70 FilterReply reply = customLoggingFilter.decide(event);
71 Assert.assertEquals( FilterReply.NEUTRAL, reply);
75 public void decideExceptionTest(){
76 ILoggingEvent event = Mockito.mock(ILoggingEvent.class);
77 Mockito.when(event.getLevel()).thenReturn(Level.ERROR);
78 Mockito.when(event.getThreadName()).thenReturn("UEBConsumerThread");
79 CustomLoggingFilter customLoggingFilter = new CustomLoggingFilter();
80 FilterReply reply = customLoggingFilter.decide(event);
81 Assert.assertEquals( FilterReply.NEUTRAL, reply);
85 public void decideExceptionTestWithLevelWarn(){
86 ILoggingEvent event = Mockito.mock(ILoggingEvent.class);
87 Mockito.when(event.getLevel()).thenReturn(Level.WARN);
88 Mockito.when(event.getThreadName()).thenReturn("org.apache.http");
89 CustomLoggingFilter customLoggingFilter = new CustomLoggingFilter();
90 FilterReply reply = customLoggingFilter.decide(event);
91 Assert.assertEquals( FilterReply.NEUTRAL, reply);