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.junitAndMockitoBundles;
35 import static org.opendaylight.controller.test.sal.binding.it.TestHelper.mdSalCoreBundles;
36 import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
37 import static org.ops4j.pax.exam.CoreOptions.options;
38 import static org.ops4j.pax.exam.CoreOptions.systemPackages;
39 import static org.ops4j.pax.exam.CoreOptions.systemProperty;
41 @RunWith(PaxExam.class)
42 public class ToasterTest {
45 @Filter(timeout=60*1000)
46 KitchenService kitchenService;
49 public Option[] config() {
50 return options(systemProperty("osgi.console").value("2401"), mavenBundle("org.slf4j", "slf4j-api")
51 .versionAsInProject(), //
52 mavenBundle("org.slf4j", "log4j-over-slf4j").versionAsInProject(), //
54 systemProperty("logback.configurationFile").value(
55 "file:" + PathUtils.getBaseDir()
56 + "/src/test/resources/logback.xml"),
57 mavenBundle("ch.qos.logback", "logback-core").versionAsInProject(), //
58 mavenBundle("ch.qos.logback", "logback-classic").versionAsInProject(), //
59 systemProperty("osgi.bundles.defaultStartLevel").value("4"),
60 systemPackages("sun.nio.ch"),
65 bindingAwareSalBundles(),
66 configMinumumBundles(),
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.openexi", "nagasena").versionAsInProject(),
81 mavenBundle("org.openexi", "nagasena-rta").versionAsInProject()
86 public void testToaster() throws Exception {
88 MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
89 ObjectName providerOn = new ObjectName("org.opendaylight.controller:instanceName=toaster-provider-impl,type=RuntimeBean,moduleFactoryName=toaster-provider-impl");
91 long toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
92 assertEquals(0, toastsMade);
94 boolean success = true;
96 // Make toasts using OSGi service
97 success &= kitchenService.makeBreakfast( EggsType.SCRAMBLED, HashBrown.class, 4).get().isSuccessful();
98 success &= kitchenService.makeBreakfast( EggsType.POACHED, WhiteBread.class, 8 ).get().isSuccessful();
100 Assert.assertTrue("Not all breakfasts succeeded", success);
102 // Verify toasts made count on provider via JMX/config-subsystem
103 toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
104 assertEquals(2, toastsMade);