2 * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.bgpcep.config.loader.impl;
10 import static org.mockito.Mockito.doAnswer;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.doThrow;
13 import static org.mockito.Mockito.timeout;
14 import static org.mockito.Mockito.verify;
16 import java.nio.file.WatchEvent;
17 import java.nio.file.WatchKey;
18 import java.nio.file.WatchService;
19 import java.util.List;
20 import org.junit.After;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.Mock;
25 import org.mockito.junit.MockitoJUnitRunner;
26 import org.opendaylight.mdsal.binding.runtime.api.BindingRuntimeContext;
27 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
29 @RunWith(MockitoJUnitRunner.StrictStubs.class)
30 public class OSGiConfigLoaderTest {
32 private FileWatcher watcher;
34 private WatchService watchService;
36 private WatchKey watchKey;
38 private WatchEvent<?> watchEvent;
40 private BindingRuntimeContext bindingContext;
42 private EffectiveModelContext domContext;
44 private OSGiConfigLoader loader;
47 public void before() throws InterruptedException {
48 doReturn(watchService).when(watcher).getWatchService();
49 doReturn("foo").when(watcher).getPathFile();
50 doReturn(watchKey).when(watchService).take();
52 doThrow(new RuntimeException("enough!")).when(watchKey).pollEvents();
53 return List.of(watchEvent);
54 }).when(watchKey).pollEvents();
55 doReturn("watchEvent").when(watchEvent).context();
56 doReturn(true).when(watchKey).reset();
57 doReturn(domContext).when(bindingContext).modelContext();
59 loader = new OSGiConfigLoader();
60 loader.watcher = watcher;
61 loader.setRuntimeContext(bindingContext);
70 public void testSimpleConfigLoader() {
72 verify(watchKey, timeout(10000)).reset();