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;
17 import java.util.concurrent.Future;
19 import org.junit.Ignore;
20 import org.junit.Test;
21 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
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.controller.sal.binding.api.NotificationProviderService;
26 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.DisplayString;
27 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput;
28 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInputBuilder;
29 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.Toaster;
30 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32 import org.opendaylight.yangtools.yang.common.RpcResult;
34 import com.google.common.base.Optional;
36 public class OpenDaylightToasterTest extends AbstractDataBrokerTest{
38 private static InstanceIdentifier<Toaster> TOASTER_IID =
39 InstanceIdentifier.builder( Toaster.class ).build();
40 OpendaylightToaster toaster;
43 protected void setupWithDataBroker(DataBroker dataBroker) {
44 toaster = new OpendaylightToaster();
45 toaster.setDataProvider( dataBroker );
48 * Doesn't look like we have support for the NotificationProviderService yet, so mock it
51 NotificationProviderService mockNotification = mock( NotificationProviderService.class );
52 toaster.setNotificationProvider( mockNotification );
56 public void testToasterInitOnStartUp() throws Exception {
57 DataBroker broker = getDataBroker();
59 ReadOnlyTransaction rTx = broker.newReadOnlyTransaction();
60 Optional<Toaster> optional = rTx.read( LogicalDatastoreType.OPERATIONAL, TOASTER_IID ).get();
61 assertNotNull( optional );
62 assertTrue( "Operational toaster not present", optional.isPresent() );
64 Toaster toaster = optional.get();
66 assertEquals( Toaster.ToasterStatus.Up, toaster.getToasterStatus() );
67 assertEquals( new DisplayString("Opendaylight"),
68 toaster.getToasterManufacturer() );
69 assertEquals( new DisplayString("Model 1 - Binding Aware"),
70 toaster.getToasterModelNumber() );
72 Optional<Toaster> configToaster =
73 rTx.read( LogicalDatastoreType.CONFIGURATION, TOASTER_IID ).get();
74 assertFalse( "Didn't expect config data for toaster.",
75 configToaster.isPresent() );
79 @Ignore //ignored because it is not an e test right now. Illustrative purposes only.
80 public void testSomething() throws Exception{
81 MakeToastInput toastInput = new MakeToastInputBuilder()
82 .setToasterDoneness( 1L )
83 .setToasterToastType( WheatBread.class )
86 //NOTE: In a real test we would want to override the Thread.sleep() to prevent our junit test
87 //for sleeping for a second...
88 Future<RpcResult<Void>> makeToast = toaster.makeToast( toastInput );
90 RpcResult<Void> rpcResult = makeToast.get();
92 assertNotNull( rpcResult );
93 assertTrue( rpcResult.isSuccessful() );