2 * Copyright (c) 2014 Brocade Communications 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
9 package org.opendaylight.controller.sample.toaster.provider;
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 import com.google.common.base.Optional;
17 import java.util.concurrent.Future;
18 import org.junit.Ignore;
19 import org.junit.Test;
20 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
21 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
22 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
23 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.DisplayString;
26 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput;
27 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInputBuilder;
28 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.Toaster;
29 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
33 public class OpenDaylightToasterTest extends AbstractDataBrokerTest {
35 private static InstanceIdentifier<Toaster> TOASTER_IID =
36 InstanceIdentifier.builder( Toaster.class ).build();
37 OpendaylightToaster toaster;
40 protected void setupWithDataBroker(DataBroker dataBroker) {
41 toaster = new OpendaylightToaster();
42 toaster.setDataProvider( dataBroker );
45 * Doesn't look like we have support for the NotificationProviderService yet, so mock it
48 NotificationPublishService mockNotification = mock( NotificationPublishService.class );
49 toaster.setNotificationProvider( mockNotification );
53 public void testToasterInitOnStartUp() throws Exception {
54 DataBroker broker = getDataBroker();
56 ReadOnlyTransaction rTx = broker.newReadOnlyTransaction();
57 Optional<Toaster> optional = rTx.read( LogicalDatastoreType.OPERATIONAL, TOASTER_IID ).get();
58 assertNotNull( optional );
59 assertTrue( "Operational toaster not present", optional.isPresent() );
61 Toaster toaster = optional.get();
63 assertEquals( Toaster.ToasterStatus.Up, toaster.getToasterStatus() );
64 assertEquals( new DisplayString("Opendaylight"),
65 toaster.getToasterManufacturer() );
66 assertEquals( new DisplayString("Model 1 - Binding Aware"),
67 toaster.getToasterModelNumber() );
69 Optional<Toaster> configToaster =
70 rTx.read( LogicalDatastoreType.CONFIGURATION, TOASTER_IID ).get();
71 assertFalse( "Didn't expect config data for toaster.",
72 configToaster.isPresent() );
76 @Ignore //ignored because it is not an e test right now. Illustrative purposes only.
77 public void testSomething() throws Exception{
78 MakeToastInput toastInput = new MakeToastInputBuilder()
79 .setToasterDoneness( 1L )
80 .setToasterToastType( WheatBread.class )
83 //NOTE: In a real test we would want to override the Thread.sleep() to prevent our junit test
84 //for sleeping for a second...
85 Future<RpcResult<Void>> makeToast = toaster.makeToast( toastInput );
87 RpcResult<Void> rpcResult = makeToast.get();
89 assertNotNull( rpcResult );
90 assertTrue( rpcResult.isSuccessful() );