Fixup checkstyle
[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 static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.ops4j.pax.exam.CoreOptions.maven;
13
14 import java.lang.management.ManagementFactory;
15 import javax.inject.Inject;
16 import javax.management.MBeanServer;
17 import javax.management.ObjectName;
18 import org.junit.Test;
19 import org.junit.runner.RunWith;
20 import org.opendaylight.controller.mdsal.it.base.AbstractMdsalTestBase;
21 import org.opendaylight.controller.sample.kitchen.api.EggsType;
22 import org.opendaylight.controller.sample.kitchen.api.KitchenService;
23 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.HashBrown;
24 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToast;
25 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WhiteBread;
26 import org.ops4j.pax.exam.junit.PaxExam;
27 import org.ops4j.pax.exam.options.MavenUrlReference;
28 import org.ops4j.pax.exam.util.Filter;
29
30 @RunWith(PaxExam.class)
31 public class ToasterTest extends AbstractMdsalTestBase {
32     @Inject
33     @Filter(timeout = 60 * 1000)
34     KitchenService kitchenService;
35     @Inject
36     @Filter(timeout = 60 * 1000)
37     // proxy for the entire toaster, nothing else
38     MakeToast makeToast;
39
40     @Override
41     public MavenUrlReference getFeatureRepo() {
42         return maven().groupId("org.opendaylight.controller").artifactId("features-controller-experimental")
43                 .classifier("features").type("xml").versionAsInProject();
44     }
45
46     @Override
47     public String getFeatureName() {
48         return "odl-toaster";
49     }
50
51     @Test
52     public void testToaster() throws Exception {
53         MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer();
54         ObjectName providerOn = new ObjectName(
55                 "org.opendaylight.controller:name=OpendaylightToaster,type=toaster-provider");
56
57         long toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
58         assertEquals(0, toastsMade);
59
60         boolean success = true;
61
62         // Make toasts using OSGi service
63         success &= kitchenService.makeBreakfast(EggsType.SCRAMBLED, HashBrown.VALUE, 4).get().isSuccessful();
64         success &= kitchenService.makeBreakfast(EggsType.POACHED, WhiteBread.VALUE, 8).get().isSuccessful();
65
66         assertTrue("Not all breakfasts succeeded", success);
67
68         // Verify toasts made count on provider via JMX/config-subsystem
69         toastsMade = (long) platformMBeanServer.getAttribute(providerOn, "ToastsMade");
70         assertEquals(2, toastsMade);
71     }
72 }