Adjust for Binding RPC codegen changes
[controller.git] / opendaylight / md-sal / samples / toaster-provider / src / test / java / org / opendaylight / controller / sample / toaster / provider / OpenDaylightToasterTest.java
1 /*
2  * Copyright (c) 2014 Brocade Communications 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
9 package org.opendaylight.controller.sample.toaster.provider;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15 import static org.mockito.Mockito.mock;
16
17 import com.google.common.base.Optional;
18 import java.util.concurrent.Future;
19 import org.junit.Before;
20 import org.junit.Ignore;
21 import org.junit.Test;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
24 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
25 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
26 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
27 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.DisplayString;
28 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput;
29 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInputBuilder;
30 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastOutput;
31 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.Toaster;
32 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34 import org.opendaylight.yangtools.yang.common.RpcResult;
35
36 public class OpenDaylightToasterTest extends AbstractConcurrentDataBrokerTest {
37
38     private static InstanceIdentifier<Toaster> TOASTER_IID = InstanceIdentifier.builder(Toaster.class).build();
39     private OpendaylightToaster toaster;
40
41     @Before
42     public void setupToaster() {
43         toaster = new OpendaylightToaster();
44         toaster.setDataBroker(getDataBroker());
45         toaster.init();
46
47         // We'll mock the NotificationProviderService.
48         NotificationPublishService mockNotification = mock(NotificationPublishService.class);
49         toaster.setNotificationProvider(mockNotification);
50     }
51
52     @Test
53     public void testToasterInitOnStartUp() throws Exception {
54         DataBroker broker = getDataBroker();
55
56         ReadOnlyTransaction readTx = broker.newReadOnlyTransaction();
57         Optional<Toaster> optional = readTx.read(LogicalDatastoreType.OPERATIONAL, TOASTER_IID).get();
58         assertNotNull(optional);
59         assertTrue("Operational toaster not present", optional.isPresent());
60
61         Toaster toasterData = optional.get();
62
63         assertEquals(Toaster.ToasterStatus.Up, toasterData.getToasterStatus());
64         assertEquals(new DisplayString("Opendaylight"), toasterData.getToasterManufacturer());
65         assertEquals(new DisplayString("Model 1 - Binding Aware"), toasterData.getToasterModelNumber());
66
67         Optional<Toaster> configToaster = readTx.read(LogicalDatastoreType.CONFIGURATION, TOASTER_IID).get();
68         assertFalse("Didn't expect config data for toaster.", configToaster.isPresent());
69     }
70
71     @Test
72     @Ignore //ignored because it is not a test right now. Illustrative purposes only.
73     public void testSomething() throws Exception {
74         MakeToastInput toastInput = new MakeToastInputBuilder().setToasterDoneness(1L)
75                 .setToasterToastType(WheatBread.class).build();
76
77         // NOTE: In a real test we would want to override the Thread.sleep() to
78         // prevent our junit test
79         // for sleeping for a second...
80         Future<RpcResult<MakeToastOutput>> makeToast = toaster.makeToast(toastInput);
81
82         RpcResult<MakeToastOutput> rpcResult = makeToast.get();
83
84         assertNotNull(rpcResult);
85         assertTrue(rpcResult.isSuccessful());
86         // etc
87     }
88 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.