2 * Copyright (C) 2018 Bell Canada.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.ccsdk.sli.adaptors.netbox.property;
18 import static org.mockito.Mockito.times;
19 import static org.mockito.Mockito.verify;
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;
34 @RunWith(MockitoJUnitRunner.class)
35 public class NetboxPropertiesTest {
37 private NetboxProperties props;
40 private Appender<ILoggingEvent> appender;
42 private ArgumentCaptor<ILoggingEvent> captor;
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);
52 public void testMissingFile() {
53 props = new NetboxProperties();
56 "Missing configuration properties resource for Netbox: netbox.properties");
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));