1 package org.opendaylight.groupbasedpolicy.neutron.mapper.test;
3 import static com.google.common.base.Preconditions.checkState;
5 import java.io.IOException;
7 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
9 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
10 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
12 import com.google.common.collect.ImmutableSet;
13 import com.google.common.collect.ImmutableSet.Builder;
16 * Loads only modules of GBP and it's dependencies for data broker.
17 * <br>Therefore this implementation is faster than {@link AbstractDataBrokerTest}
19 public class GbpDataBrokerTest extends AbstractDataBrokerTest {
22 protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
23 Builder<YangModuleInfo> moduleInfoSet = ImmutableSet.<YangModuleInfo>builder();
24 loadModuleInfos(Tenant.class, moduleInfoSet);
25 return moduleInfoSet.build();
28 public static void loadModuleInfos(Class<?> clazzFromModule, Builder<YangModuleInfo> moduleInfoSet) throws Exception {
29 YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(clazzFromModule);
30 checkState(moduleInfo != null, "Module Info for %s is not available.", clazzFromModule);
31 collectYangModuleInfo(moduleInfo, moduleInfoSet);
34 private static void collectYangModuleInfo(final YangModuleInfo moduleInfo,
35 final Builder<YangModuleInfo> moduleInfoSet) throws IOException {
36 moduleInfoSet.add(moduleInfo);
37 for (YangModuleInfo dependency : moduleInfo.getImportedModules()) {
38 collectYangModuleInfo(dependency, moduleInfoSet);