BGPCEP-710: Create Network Topology Loader
[bgpcep.git] / config-loader / config-loader-impl / src / test / java / org / opendaylight / bgpcep / config / loader / impl / ConfigLoaderImplTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.bgpcep.config.loader.impl;
10
11 import static org.junit.Assert.assertNotNull;
12 import static org.mockito.Matchers.any;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.timeout;
15 import static org.mockito.Mockito.verify;
16
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.mdsal.binding.generator.impl.ModuleInfoBackedContext;
20 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.NetworkInstances;
21 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.NetworkInstance;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.network.instance.rev151018.network.instance.top.network.instances.network.instance.Protocols;
23 import org.opendaylight.yangtools.concepts.AbstractRegistration;
24 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
25 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
26
27 public class ConfigLoaderImplTest extends AbstractConfigLoader {
28     @Override
29     @Before
30     public void setUp() throws Exception {
31         super.setUp();
32         final SchemaPath schemaPath = SchemaPath.create(true,
33                 NetworkInstances.QNAME, NetworkInstance.QNAME, Protocols.QNAME);
34         doReturn(schemaPath).when(this.processor).getSchemaPath();
35         doReturn("processor").when(this.processor).toString();
36     }
37
38     @Override
39     protected String getResourceFolder() {
40         return ClassLoader.getSystemClassLoader().getResource("etc/opendaylight/bgpcep").getPath();
41     }
42
43     @Override
44     protected void registerModules(final ModuleInfoBackedContext moduleInfoBackedContext) throws Exception {
45         moduleInfoBackedContext.registerModuleInfo(BindingReflections.getModuleInfo(NetworkInstances.class));
46     }
47
48     @Test
49     public void configLoaderImplTest() throws Exception {
50         assertNotNull(ClassLoader.getSystemClassLoader().getResource("etc/opendaylight/bgpcep/protocols-config.xml"));
51         final AbstractRegistration ticket = this.configLoader.registerConfigFile(this.processor);
52         verify(this.processor).loadConfiguration(any());
53
54         triggerEvent("protocols-config.xml");
55         verify(this.processor, timeout(20000).times(2)).loadConfiguration(any());
56
57         ticket.close();
58         triggerEvent("protocols-config.xml");
59         verify(this.processor, timeout(20000).times(2)).loadConfiguration(any());
60     }
61 }