2ea64239fb4c210855aeda446e8f6f5f14200724
[policy/common.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2024 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * ============LICENSE_END=========================================================
17  */
18
19 package org.onap.policy.common.endpoints.features;
20
21 import static org.junit.jupiter.api.Assertions.assertFalse;
22
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25 import org.junit.jupiter.api.extension.ExtendWith;
26 import org.mockito.Mock;
27 import org.mockito.junit.jupiter.MockitoExtension;
28 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
29 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
30 import org.slf4j.Logger;
31
32 @ExtendWith(MockitoExtension.class)
33 class NetLoggerFeatureApiTest {
34
35     @Mock
36     private Logger mockLogger;
37
38     @Mock
39     private EventType mockEventType;
40
41     @Mock
42     private CommInfrastructure mockCommInfrastructure;
43
44     private NetLoggerFeatureApi featureApi;
45
46     @BeforeEach
47     public void setUp() {
48         featureApi = new NetLoggerFeatureApi() {
49             @Override
50             public boolean beforeLog(Logger eventLogger, EventType type, CommInfrastructure protocol, String topic,
51                                      String message) {
52                 return NetLoggerFeatureApi.super.beforeLog(eventLogger, type, protocol, topic, message);
53             }
54
55             @Override
56             public boolean afterLog(Logger eventLogger, EventType type, CommInfrastructure protocol, String topic,
57                                     String message) {
58                 return NetLoggerFeatureApi.super.afterLog(eventLogger, type, protocol, topic, message);
59             }
60
61             @Override
62             public int getSequenceNumber() {
63                 return 0;
64             }
65
66             @Override
67             public String getName() {
68                 return NetLoggerFeatureApi.super.getName();
69             }
70         };
71     }
72
73     @Test
74     void testBeforeLogDefaultBehavior() {
75         boolean result = featureApi.beforeLog(mockLogger, mockEventType, mockCommInfrastructure,
76             "testTopic", "testMessage");
77         assertFalse(result, "Expected beforeLog to return false by default");
78     }
79
80     @Test
81     void testAfterLogDefaultBehavior() {
82         boolean result = featureApi.afterLog(mockLogger, mockEventType, mockCommInfrastructure,
83             "testTopic", "testMessage");
84         assertFalse(result, "Expected afterLog to return false by default");
85     }
86 }