Merge "Bug 509: Improve logging in InMemoryDataStore."
[controller.git] / opendaylight / md-sal / samples / toaster-it / src / test / java / org / opendaylight / controller / sample / toaster / it / ToasterTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.sample.toaster.it;
9
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;
22
23 import javax.inject.Inject;
24 import javax.management.MBeanServer;
25 import javax.management.ObjectName;
26 import java.lang.management.ManagementFactory;
27
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;
39
40 @RunWith(PaxExam.class)
41 public class ToasterTest {
42
43     @Inject
44     @Filter(timeout=60*1000)
45     ToastConsumer toastConsumer;
46
47     @Configuration
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(), //
52
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"),
60
61                 toasterBundles(),
62                 mdSalCoreBundles(),
63
64                 bindingAwareSalBundles(),
65                 configMinumumBundles(),
66                 // BASE Models
67                 baseModelBundles(),
68                 flowCapableModelBundles(),
69
70                 // Set fail if unresolved bundle present
71                 systemProperty("pax.exam.osgi.unresolved.fail").value("true"),
72                 junitAndMockitoBundles());
73     }
74
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()
82         );
83     }
84
85     @Test
86     public void testToaster() throws Exception {
87
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");
91
92         long toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
93         assertEquals(0, toastsMade);
94
95         boolean toasts = true;
96
97         // Make toasts using OSGi service
98         toasts &= toastConsumer.createToast(HashBrown.class, 4);
99         toasts &= toastConsumer.createToast(WhiteBread.class, 8);
100
101         // Make toast using JMX/config-subsystem
102         toasts &= (Boolean)platformMBeanServer.invoke(consumerOn, "makeHashBrownToast", new Object[]{4}, new String[]{Integer.class.getName()});
103
104         Assert.assertTrue("Not all toasts done by " + toastConsumer, toasts);
105
106         // Verify toasts made count on provider via JMX/config-subsystem
107         toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
108         assertEquals(3, toastsMade);
109     }
110
111 }