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 static org.junit.Assert.assertEquals;
11 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.*;
12 import static org.ops4j.pax.exam.CoreOptions.*;
14 import javax.inject.Inject;
15 import javax.management.JMX;
16 import javax.management.MBeanServer;
17 import javax.management.ObjectName;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.junit.runner.RunWith;
22 import org.opendaylight.controller.config.yang.config.toaster_consumer.impl.ToasterConsumerRuntimeMXBean;
23 import org.opendaylight.controller.config.yang.config.toaster_provider.impl.ToasterProviderRuntimeMXBean;
24 import org.opendaylight.controller.sample.toaster.provider.api.ToastConsumer;
25 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.HashBrown;
26 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WhiteBread;
27 import org.ops4j.pax.exam.Configuration;
28 import org.ops4j.pax.exam.Option;
29 import org.ops4j.pax.exam.junit.PaxExam;
30 import org.ops4j.pax.exam.options.DefaultCompositeOption;
31 import org.ops4j.pax.exam.util.Filter;
32 import org.ops4j.pax.exam.util.PathUtils;
34 import java.lang.management.ManagementFactory;
36 @RunWith(PaxExam.class)
37 public class ToasterTest {
40 @Filter(timeout=60*1000)
41 ToastConsumer toastConsumer;
44 public Option[] config() {
45 return options(systemProperty("osgi.console").value("2401"), mavenBundle("org.slf4j", "slf4j-api")
46 .versionAsInProject(), //
47 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(), //
49 systemProperty("logback.configurationFile").value(
50 "file:" + PathUtils.getBaseDir()
51 + "/src/test/resources/logback.xml"),
52 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(), //
53 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(), //
54 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
55 systemPackages("sun.nio.ch"),
60 bindingAwareSalBundles(),
61 configMinumumBundles(),
64 flowCapableModelBundles(),
66 // Set fail if unresolved bundle present
67 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
68 junitAndMockitoBundles());
71 private Option toasterBundles() {
72 return new DefaultCompositeOption(
73 mavenBundle("org.opendaylight.controller.samples", "sample-toaster-provider").versionAsInProject(),
74 mavenBundle("org.opendaylight.controller.samples", "sample-toaster-consumer").versionAsInProject(),
75 mavenBundle("org.opendaylight.controller.samples", "sample-toaster").versionAsInProject()
80 public void testToaster() throws Exception {
82 MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
83 ObjectName consumerOn = new ObjectName("org.opendaylight.controller:instanceName=toaster-consumer-impl,type=RuntimeBean,moduleFactoryName=toaster-consumer-impl");
84 ObjectName providerOn = new ObjectName("org.opendaylight.controller:instanceName=toaster-provider-impl,type=RuntimeBean,moduleFactoryName=toaster-provider-impl");
86 long toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
87 assertEquals(0, toastsMade);
89 boolean toasts = true;
91 // Make toasts using OSGi service
92 toasts &= toastConsumer.createToast(HashBrown.class, 4);
93 toasts &= toastConsumer.createToast(WhiteBread.class, 8);
95 // Make toast using JMX/config-subsystem
96 toasts &= (Boolean)platformMBeanServer.invoke(consumerOn, "makeHashBrownToast", new Object[]{4}, new String[]{Integer.class.getName()});
98 Assert.assertTrue("Not all toasts done by " + toastConsumer, toasts);
100 // Verify toasts made count on provider via JMX/config-subsystem
101 toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
102 assertEquals(3, toastsMade);