X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Ftoaster-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsample%2Ftoaster%2Fit%2FToasterTest.java;h=907b35475f80f3565e18d2965885ff505bb55d6e;hp=d8031e52f222fd9936deacec8f41922a61dee04c;hb=e159106bc148e76fc1e3e3c780bdd740d99e74ed;hpb=ee7b48483f602adb6179960baad1ba76e20770c3 diff --git a/opendaylight/md-sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java b/opendaylight/md-sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java index d8031e52f2..907b35475f 100644 --- a/opendaylight/md-sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java +++ b/opendaylight/md-sal/samples/toaster-it/src/test/java/org/opendaylight/controller/sample/toaster/it/ToasterTest.java @@ -1,80 +1,109 @@ +/* + * Copyright (c) 2014 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.controller.sample.toaster.it; -import static org.junit.Assert.*; -import static org.ops4j.pax.exam.CoreOptions.junitBundles; -import static org.ops4j.pax.exam.CoreOptions.mavenBundle; -import static org.ops4j.pax.exam.CoreOptions.options; -import static org.ops4j.pax.exam.CoreOptions.systemPackages; -import static org.ops4j.pax.exam.CoreOptions.systemProperty; -import static org.ops4j.pax.exam.CoreOptions.maven; - -import java.util.Collection; - -import javax.inject.Inject; - +import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; -import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; -import org.opendaylight.controller.sample.toaster.provider.ToasterProvider; -import org.opendaylight.controller.sample.toaster.provider.api.ToastConsumer; -import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.ToasterService; +import org.opendaylight.controller.sample.kitchen.api.EggsType; +import org.opendaylight.controller.sample.kitchen.api.KitchenService; +import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.HashBrown; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WhiteBread; import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.CoreOptions; import org.ops4j.pax.exam.Option; import org.ops4j.pax.exam.junit.PaxExam; -import org.osgi.framework.BundleContext; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; +import org.ops4j.pax.exam.options.DefaultCompositeOption; +import org.ops4j.pax.exam.util.Filter; +import org.ops4j.pax.exam.util.PathUtils; + +import javax.inject.Inject; +import javax.management.MBeanServer; +import javax.management.ObjectName; + +import java.lang.management.ManagementFactory; + +import static org.junit.Assert.assertEquals; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.junitAndMockitoBundles; +import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles; +import static org.ops4j.pax.exam.CoreOptions.mavenBundle; +import static org.ops4j.pax.exam.CoreOptions.options; +import static org.ops4j.pax.exam.CoreOptions.systemPackages; +import static org.ops4j.pax.exam.CoreOptions.systemProperty; @RunWith(PaxExam.class) public class ToasterTest { - public static final String ODL = "org.opendaylight.controller"; - public static final String YANG = "org.opendaylight.yangtools"; - public static final String SAMPLE = "org.opendaylight.controller.samples"; + @Inject + @Filter(timeout=60*1000) + KitchenService kitchenService; - @Test - public void properInitialized() throws Exception { + @Configuration + public Option[] config() { + return options(systemProperty("osgi.console").value("2401"), mavenBundle("org.slf4j", "slf4j-api") + .versionAsInProject(), // + mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(), // + + systemProperty("logback.configurationFile").value( + "file:" + PathUtils.getBaseDir() + + "/src/test/resources/logback.xml"), + mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(), // + mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(), // + systemProperty("osgi.bundles.defaultStartLevel").value("4"), + systemPackages("sun.nio.ch"), - Thread.sleep(500); // Waiting for services to get wired. + toasterBundles(), + mdSalCoreBundles(), - assertTrue(consumer.createToast(WhiteBread.class, 5)); + bindingAwareSalBundles(), + configMinumumBundles(), + // BASE Models + baseModelBundles(), + flowCapableModelBundles(), + // Set fail if unresolved bundle present + systemProperty("pax.exam.osgi.unresolved.fail").value("true"), + junitAndMockitoBundles()); } - @Inject - BindingAwareBroker broker; + private Option toasterBundles() { + return new DefaultCompositeOption( + mavenBundle("org.opendaylight.controller.samples", "sample-toaster-provider").versionAsInProject(), + mavenBundle("org.opendaylight.controller.samples", "sample-toaster-consumer").versionAsInProject(), + mavenBundle("org.opendaylight.controller.samples", "sample-toaster").versionAsInProject(), + mavenBundle("org.openexi", "nagasena").versionAsInProject(), + mavenBundle("org.openexi", "nagasena-rta").versionAsInProject() + ); + } - @Inject - ToastConsumer consumer; + @Test + public void testToaster() throws Exception { - @Inject - BundleContext ctx; + MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); + ObjectName providerOn = new ObjectName("org.opendaylight.controller:instanceName=toaster-provider-impl,type=RuntimeBean,moduleFactoryName=toaster-provider-impl"); - @Configuration - public Option[] config() { - return options(systemProperty("osgi.console").value("2401"), - mavenBundle("org.slf4j", "slf4j-api").versionAsInProject(), // - mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(), // - mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(), // - mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(), // - mavenBundle(ODL, "sal-binding-api").versionAsInProject(), // - mavenBundle(ODL, "sal-binding-broker-impl").versionAsInProject(), // - mavenBundle(ODL, "sal-common").versionAsInProject(), // - mavenBundle(ODL, "sal-common-api").versionAsInProject(), - mavenBundle(ODL, "sal-common-util").versionAsInProject(), // - mavenBundle(SAMPLE, "sample-toaster").versionAsInProject(), // - mavenBundle(SAMPLE, "sample-toaster-consumer").versionAsInProject(), // - mavenBundle(SAMPLE, "sample-toaster-provider").versionAsInProject(), // - mavenBundle(YANG, "concepts").versionAsInProject(), - mavenBundle(YANG, "yang-binding").versionAsInProject(), // - mavenBundle(YANG, "yang-common").versionAsInProject(), // - mavenBundle(YANG+".thirdparty", "xtend-lib-osgi").versionAsInProject(), - mavenBundle("com.google.guava", "guava").versionAsInProject(), // - mavenBundle("org.javassist", "javassist").versionAsInProject(), - junitBundles() - ); + long toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade"); + assertEquals(0, toastsMade); + + boolean toasts = true; + + // Make toasts using OSGi service + toasts &= kitchenService.makeBreakfast( EggsType.SCRAMBLED, HashBrown.class, 4); + toasts &= kitchenService.makeBreakfast( EggsType.POACHED, WhiteBread.class, 8 ); + + Assert.assertTrue("Not all toasts done by " + kitchenService, toasts); + + // Verify toasts made count on provider via JMX/config-subsystem + toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade"); + assertEquals(2, toastsMade); } }