Add SvcLogicContext interaction with netbox-client
[ccsdk/sli/adaptors.git] / netbox-client / provider / src / test / java / org / onap / ccsdk / sli / adaptors / netbox / property / NetboxPropertiesTest.java
1 /*
2  * Copyright (C) 2018 Bell Canada.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.ccsdk.sli.adaptors.netbox.property;
17
18 import static org.mockito.Mockito.times;
19 import static org.mockito.Mockito.verify;
20
21 import ch.qos.logback.classic.spi.ILoggingEvent;
22 import ch.qos.logback.core.Appender;
23 import java.util.List;
24 import org.junit.Assert;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.junit.runner.RunWith;
28 import org.mockito.ArgumentCaptor;
29 import org.mockito.Captor;
30 import org.mockito.Mock;
31 import org.mockito.runners.MockitoJUnitRunner;
32 import org.slf4j.LoggerFactory;
33
34 @RunWith(MockitoJUnitRunner.class)
35 public class NetboxPropertiesTest {
36
37     private NetboxProperties props;
38
39     @Mock
40     private Appender<ILoggingEvent> appender;
41     @Captor
42     private ArgumentCaptor<ILoggingEvent> captor;
43
44     @Before
45     public void setup() {
46         ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory
47             .getLogger(org.slf4j.Logger.ROOT_LOGGER_NAME);
48         logger.addAppender(appender);
49     }
50
51     @Test
52     public void testMissingFile() {
53         props = new NetboxProperties();
54
55         verifyLogEntry(
56             "Missing configuration properties resource for Netbox: netbox.properties");
57     }
58
59     private void verifyLogEntry(String message) {
60         verify(appender, times(1)).doAppend(captor.capture());
61         List<ILoggingEvent> allValues = captor.getAllValues();
62         for (ILoggingEvent loggingEvent : allValues) {
63             Assert.assertTrue(loggingEvent.getFormattedMessage().contains(message));
64         }
65     }
66 }