Add INFO.yaml for GBP
[groupbasedpolicy.git] / renderers / vpp / src / test / java / org / opendaylight / groupbasedpolicy / renderer / vpp / CustomDataBrokerTest.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.groupbasedpolicy.renderer.vpp;
10
11 import static com.google.common.base.Preconditions.checkState;
12
13 import java.io.IOException;
14 import java.util.Collection;
15
16 import javax.annotation.Nonnull;
17
18 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
19 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
20 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
21
22 import com.google.common.collect.ImmutableSet;
23 import com.google.common.collect.ImmutableSet.Builder;
24
25 /**
26  * Loads only modules of GBP and it's dependencies for data broker.
27  * <br>
28  * Therefore this implementation is faster than {@link AbstractDataBrokerTest}
29  */
30 public abstract class CustomDataBrokerTest extends AbstractDataBrokerTest {
31
32     public static void loadModuleInfos(Class<?> clazzFromModule, Builder<YangModuleInfo> moduleInfoSet)
33             throws Exception {
34         YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(clazzFromModule);
35         checkState(moduleInfo != null, "Module Info for %s is not available.", clazzFromModule);
36         collectYangModuleInfo(moduleInfo, moduleInfoSet);
37     }
38
39     private static void collectYangModuleInfo(final YangModuleInfo moduleInfo,
40             final Builder<YangModuleInfo> moduleInfoSet) throws IOException {
41         moduleInfoSet.add(moduleInfo);
42         for (YangModuleInfo dependency : moduleInfo.getImportedModules()) {
43             collectYangModuleInfo(dependency, moduleInfoSet);
44         }
45     }
46
47     @Override
48     protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
49         Builder<YangModuleInfo> moduleInfoSet = ImmutableSet.<YangModuleInfo>builder();
50         for (Class<?> clazz : getClassesFromModules()) {
51             loadModuleInfos(clazz, moduleInfoSet);
52         }
53         return moduleInfoSet.build();
54     }
55
56     /**
57      * @return a class from every yang module which needs to be loaded. Cannot return {@code null}
58      *         or empty collection.
59      */
60     public abstract @Nonnull Collection<Class<?>> getClassesFromModules();
61 }