2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.controller.sample.toaster.it;
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.opendaylight.controller.sample.toaster.provider.api.ToastConsumer;
14 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.HashBrown;
15 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WhiteBread;
16 import org.ops4j.pax.exam.Configuration;
17 import org.ops4j.pax.exam.Option;
18 import org.ops4j.pax.exam.junit.PaxExam;
19 import org.ops4j.pax.exam.options.DefaultCompositeOption;
20 import org.ops4j.pax.exam.util.Filter;
21 import org.ops4j.pax.exam.util.PathUtils;
23 import javax.inject.Inject;
24 import javax.management.MBeanServer;
25 import javax.management.ObjectName;
26 import java.lang.management.ManagementFactory;
28 import static org.junit.Assert.assertEquals;
29 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles;
30 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles;
31 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles;
32 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles;
33 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.junitAndMockitoBundles;
34 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles;
35 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
36 import static org.ops4j.pax.exam.CoreOptions.options;
37 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
38 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
40 @RunWith(PaxExam.class)
41 public class ToasterTest {
44 @Filter(timeout=60*1000)
45 ToastConsumer toastConsumer;
48 public Option[] config() {
49 return options(systemProperty("osgi.console").value("2401"), mavenBundle("org.slf4j", "slf4j-api")
50 .versionAsInProject(), //
51 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(), //
53 systemProperty("logback.configurationFile").value(
54 "file:" + PathUtils.getBaseDir()
55 + "/src/test/resources/logback.xml"),
56 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(), //
57 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(), //
58 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
59 systemPackages("sun.nio.ch"),
64 bindingAwareSalBundles(),
65 configMinumumBundles(),
68 flowCapableModelBundles(),
70 // Set fail if unresolved bundle present
71 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
72 junitAndMockitoBundles());
75 private Option toasterBundles() {
76 return new DefaultCompositeOption(
77 mavenBundle("org.opendaylight.controller.samples", "sample-toaster-provider").versionAsInProject(),
78 mavenBundle("org.opendaylight.controller.samples", "sample-toaster-consumer").versionAsInProject(),
79 mavenBundle("org.opendaylight.controller.samples", "sample-toaster").versionAsInProject(),
80 mavenBundle("org.opendaylight.controller.thirdparty", "nagasena").versionAsInProject(),
81 mavenBundle("org.opendaylight.controller.thirdparty", "nagasena-rta").versionAsInProject()
86 public void testToaster() throws Exception {
88 MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
89 ObjectName consumerOn = new ObjectName("org.opendaylight.controller:instanceName=toaster-consumer-impl,type=RuntimeBean,moduleFactoryName=toaster-consumer-impl");
90 ObjectName providerOn = new ObjectName("org.opendaylight.controller:instanceName=toaster-provider-impl,type=RuntimeBean,moduleFactoryName=toaster-provider-impl");
92 long toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
93 assertEquals(0, toastsMade);
95 boolean toasts = true;
97 // Make toasts using OSGi service
98 toasts &= toastConsumer.createToast(HashBrown.class, 4);
99 toasts &= toastConsumer.createToast(WhiteBread.class, 8);
101 // Make toast using JMX/config-subsystem
102 toasts &= (Boolean)platformMBeanServer.invoke(consumerOn, "makeHashBrownToast", new Object[]{4}, new String[]{Integer.class.getName()});
104 Assert.assertTrue("Not all toasts done by " + toastConsumer, toasts);
106 // Verify toasts made count on provider via JMX/config-subsystem
107 toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
108 assertEquals(3, toastsMade);