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.kitchen.api.EggsType;
14 import org.opendaylight.controller.sample.kitchen.api.KitchenService;
15 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.HashBrown;
16 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WhiteBread;
17 import org.ops4j.pax.exam.Configuration;
18 import org.ops4j.pax.exam.Option;
19 import org.ops4j.pax.exam.junit.PaxExam;
20 import org.ops4j.pax.exam.options.DefaultCompositeOption;
21 import org.ops4j.pax.exam.util.Filter;
22 import org.ops4j.pax.exam.util.PathUtils;
24 import javax.inject.Inject;
25 import javax.management.MBeanServer;
26 import javax.management.ObjectName;
28 import java.lang.management.ManagementFactory;
30 import static org.junit.Assert.assertEquals;
31 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.baseModelBundles;
32 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.bindingAwareSalBundles;
33 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.configMinumumBundles;
34 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.flowCapableModelBundles;
35 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.junitAndMockitoBundles;
36 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles;
37 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
38 import static org.ops4j.pax.exam.CoreOptions.options;
39 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
40 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
42 @RunWith(PaxExam.class)
43 public class ToasterTest {
46 @Filter(timeout=60*1000)
47 KitchenService kitchenService;
50 public Option[] config() {
51 return options(systemProperty("osgi.console").value("2401"), mavenBundle("org.slf4j", "slf4j-api")
52 .versionAsInProject(), //
53 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(), //
55 systemProperty("logback.configurationFile").value(
56 "file:" + PathUtils.getBaseDir()
57 + "/src/test/resources/logback.xml"),
58 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(), //
59 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(), //
60 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
61 systemPackages("sun.nio.ch"),
66 bindingAwareSalBundles(),
67 configMinumumBundles(),
70 flowCapableModelBundles(),
72 // Set fail if unresolved bundle present
73 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
74 junitAndMockitoBundles());
77 private Option toasterBundles() {
78 return new DefaultCompositeOption(
79 mavenBundle("org.opendaylight.controller.samples", "sample-toaster-provider").versionAsInProject(),
80 mavenBundle("org.opendaylight.controller.samples", "sample-toaster-consumer").versionAsInProject(),
81 mavenBundle("org.opendaylight.controller.samples", "sample-toaster").versionAsInProject(),
82 mavenBundle("org.openexi", "nagasena").versionAsInProject(),
83 mavenBundle("org.openexi", "nagasena-rta").versionAsInProject()
88 public void testToaster() throws Exception {
90 MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
91 ObjectName providerOn = new ObjectName("org.opendaylight.controller:instanceName=toaster-provider-impl,type=RuntimeBean,moduleFactoryName=toaster-provider-impl");
93 long toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
94 assertEquals(0, toastsMade);
96 boolean success = true;
98 // Make toasts using OSGi service
99 success &= kitchenService.makeBreakfast( EggsType.SCRAMBLED, HashBrown.class, 4).get().isSuccessful();
100 success &= kitchenService.makeBreakfast( EggsType.POACHED, WhiteBread.class, 8 ).get().isSuccessful();
102 Assert.assertTrue("Not all breakfasts succeeded", success);
104 // Verify toasts made count on provider via JMX/config-subsystem
105 toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
106 assertEquals(2, toastsMade);