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 SimpleConfigLoaderTest {
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 SimpleConfigLoader loader;
47 public void before() throws InterruptedException {
48 doReturn(domContext).when(bindingContext).getEffectiveModelContext();
49 doReturn(watchService).when(watcher).getWatchService();
50 doReturn("foo").when(watcher).getPathFile();
51 doReturn(watchKey).when(watchService).take();
53 doThrow(new RuntimeException("enough!")).when(watchKey).pollEvents();
54 return List.of(watchEvent);
55 }).when(watchKey).pollEvents();
56 doReturn("watchEvent").when(watchEvent).context();
57 doReturn(true).when(watchKey).reset();
59 loader = new SimpleConfigLoader(watcher, bindingContext);
68 public void testSimpleConfigLoader() {
70 verify(watchKey, timeout(10000)).reset();