/* * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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.ovsdb.hwvtepsouthbound.it; import static org.ops4j.pax.exam.CoreOptions.composite; import static org.ops4j.pax.exam.CoreOptions.maven; import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.concurrent.atomic.AtomicBoolean; import javax.inject.Inject; import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase; import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundConstants; import org.opendaylight.ovsdb.hwvtepsouthbound.HwvtepSouthboundProvider; import org.opendaylight.ovsdb.utils.mdsal.utils.MdsalUtils; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology; import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; import org.ops4j.pax.exam.karaf.options.LogLevelOption.LogLevel; import org.ops4j.pax.exam.options.MavenUrlReference; import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; import org.ops4j.pax.exam.spi.reactors.PerClass; import org.osgi.framework.BundleContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @RunWith(PaxExam.class) @ExamReactorStrategy(PerClass.class) public class HwvtepSouthboundIT extends AbstractMdsalTestBase { private static final Logger LOG = LoggerFactory.getLogger(HwvtepSouthboundIT.class); private static MdsalUtils mdsalUtils = null; private static boolean setup = false; private static int testMethodsRemaining; @Inject private BundleContext bundleContext; @Override public String getModuleName() { return "hwvtepsouthbound"; } @Override public String getInstanceName() { return "hwvtepsouthbound-default"; } @Override public MavenUrlReference getFeatureRepo() { return maven() .groupId("org.opendaylight.ovsdb") .artifactId("hwvtepsouthbound-features") .classifier("features") .type("xml") .versionAsInProject(); } @Override public String getFeatureName() { return "odl-ovsdb-hwvtepsouthbound-test"; } @Override public Option getLoggingOption() { Option option = editConfigurationFilePut(ORG_OPS4J_PAX_LOGGING_CFG, logConfiguration(HwvtepSouthboundIT.class), LogLevel.INFO.name()); option = composite(option, super.getLoggingOption()); return option; } @Override public String getKarafDistro() { return maven() .groupId("org.opendaylight.ovsdb") .artifactId("hwvtepsouthbound-karaf") .versionAsInProject() .type("zip") .getURL(); } @Before @Override public void setup() throws InterruptedException { if (setup) { LOG.info("Skipping setup, already initialized"); return; } try { super.setup(); } catch (Exception e) { e.printStackTrace(); } //dataBroker = getSession().getSALService(DataBroker.class); Thread.sleep(3000); DataBroker dataBroker = HwvtepSouthboundProvider.getDb(); Assert.assertNotNull("db should not be null", dataBroker); mdsalUtils = new MdsalUtils(dataBroker); // Let's count the test methods (we need to use this instead of @AfterClass on teardown() since the latter is // useless with pax-exam) for (Method method : getClass().getMethods()) { boolean testMethod = false; boolean ignoreMethod = false; for (Annotation annotation : method.getAnnotations()) { if (Test.class.equals(annotation.annotationType())) { testMethod = true; } if (Ignore.class.equals(annotation.annotationType())) { ignoreMethod = true; } } if (testMethod && !ignoreMethod) { testMethodsRemaining++; } } LOG.info("{} test methods to run", testMethodsRemaining); setup = true; } @After public void teardown() { testMethodsRemaining--; LOG.info("{} test methods remaining", testMethodsRemaining); } @Test public void testhwvtepsouthboundFeatureLoad() { Assert.assertTrue(true); } @Test public void testNetworkTopology() throws InterruptedException { NetworkTopology networkTopology = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(NetworkTopology.class)); Assert.assertNotNull("NetworkTopology could not be found in " + LogicalDatastoreType.CONFIGURATION, networkTopology); networkTopology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(NetworkTopology.class)); Assert.assertNotNull("NetworkTopology could not be found in " + LogicalDatastoreType.OPERATIONAL, networkTopology); } @Test public void testHwvtepTopology() throws InterruptedException { InstanceIdentifier path = InstanceIdentifier .create(NetworkTopology.class) .child(Topology.class, new TopologyKey(HwvtepSouthboundConstants.HWVTEP_TOPOLOGY_ID)); Topology topology = mdsalUtils.read(LogicalDatastoreType.CONFIGURATION, path); Assert.assertNotNull("Topology could not be found in " + LogicalDatastoreType.CONFIGURATION, topology); topology = mdsalUtils.read(LogicalDatastoreType.OPERATIONAL, path); Assert.assertNotNull("Topology could not be found in " + LogicalDatastoreType.OPERATIONAL, topology); } }