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 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.Toaster;
31 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.opendaylight.yangtools.yang.common.RpcResult;
35 public class OpenDaylightToasterTest extends AbstractConcurrentDataBrokerTest {
37 private static InstanceIdentifier<Toaster> TOASTER_IID = InstanceIdentifier.builder(Toaster.class).build();
38 private OpendaylightToaster toaster;
41 public void setupToaster() {
42 toaster = new OpendaylightToaster();
43 toaster.setDataBroker(getDataBroker());
46 // We'll mock the NotificationProviderService.
47 NotificationPublishService mockNotification = mock(NotificationPublishService.class);
48 toaster.setNotificationProvider(mockNotification);
52 public void testToasterInitOnStartUp() throws Exception {
53 DataBroker broker = getDataBroker();
55 ReadOnlyTransaction readTx = broker.newReadOnlyTransaction();
56 Optional<Toaster> optional = readTx.read(LogicalDatastoreType.OPERATIONAL, TOASTER_IID).get();
57 assertNotNull(optional);
58 assertTrue("Operational toaster not present", optional.isPresent());
60 Toaster toasterData = optional.get();
62 assertEquals(Toaster.ToasterStatus.Up, toasterData.getToasterStatus());
63 assertEquals(new DisplayString("Opendaylight"), toasterData.getToasterManufacturer());
64 assertEquals(new DisplayString("Model 1 - Binding Aware"), toasterData.getToasterModelNumber());
66 Optional<Toaster> configToaster = readTx.read(LogicalDatastoreType.CONFIGURATION, TOASTER_IID).get();
67 assertFalse("Didn't expect config data for toaster.", configToaster.isPresent());
71 @Ignore //ignored because it is not a test right now. Illustrative purposes only.
72 public void testSomething() throws Exception {
73 MakeToastInput toastInput = new MakeToastInputBuilder().setToasterDoneness(1L)
74 .setToasterToastType(WheatBread.class).build();
76 // NOTE: In a real test we would want to override the Thread.sleep() to
77 // prevent our junit test
78 // for sleeping for a second...
79 Future<RpcResult<Void>> makeToast = toaster.makeToast(toastInput);
81 RpcResult<Void> rpcResult = makeToast.get();
83 assertNotNull(rpcResult);
84 assertTrue(rpcResult.isSuccessful());