Unit tests for neutron mapper (parent commit)
[groupbasedpolicy.git] / neutron-mapper / src / test / java / org / opendaylight / groupbasedpolicy / neutron / mapper / test / CustomDataBrokerTest.java
similarity index 60%
rename from neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/GbpDataBrokerTest.java
rename to neutron-mapper/src/test/java/org/opendaylight/groupbasedpolicy/neutron/mapper/test/CustomDataBrokerTest.java
index 0a446aea882fb73406745944af228853c2d8d998..f13748b29662c49915a838aa196c723935be129c 100644 (file)
@@ -1,31 +1,49 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
 package org.opendaylight.groupbasedpolicy.neutron.mapper.test;
 
 import static com.google.common.base.Preconditions.checkState;
 
+import javax.annotation.Nonnull;
 import java.io.IOException;
+import java.util.Collection;
 
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.ImmutableSet.Builder;
 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.Tenant;
 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
 import org.opendaylight.yangtools.yang.binding.util.BindingReflections;
 
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.ImmutableSet.Builder;
-
 /**
  * Loads only modules of GBP and it's dependencies for data broker.
- * <br>Therefore this implementation is faster than {@link AbstractDataBrokerTest}
+ * <br>
+ * Therefore this implementation is faster than {@link AbstractDataBrokerTest}
  */
-public class GbpDataBrokerTest extends AbstractDataBrokerTest {
+public abstract class CustomDataBrokerTest extends AbstractDataBrokerTest {
 
     @Override
     protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
         Builder<YangModuleInfo> moduleInfoSet = ImmutableSet.<YangModuleInfo>builder();
-        loadModuleInfos(Tenant.class, moduleInfoSet);
+        for (Class<?> clazz : getClassesFromModules()) {
+            loadModuleInfos(clazz, moduleInfoSet);
+        }
         return moduleInfoSet.build();
     }
 
-    public static void loadModuleInfos(Class<?> clazzFromModule, Builder<YangModuleInfo> moduleInfoSet) throws Exception {
+    /**
+     * @return a class from every yang module which needs to be loaded. Cannot return {@code null}
+     *         or empty collection.
+     */
+    public abstract @Nonnull Collection<Class<?>> getClassesFromModules();
+
+    public static void loadModuleInfos(Class<?> clazzFromModule, Builder<YangModuleInfo> moduleInfoSet)
+            throws Exception {
         YangModuleInfo moduleInfo = BindingReflections.getModuleInfo(clazzFromModule);
         checkState(moduleInfo != null, "Module Info for %s is not available.", clazzFromModule);
         collectYangModuleInfo(moduleInfo, moduleInfoSet);