Fix license header violations in toaster-provider
[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 java.util.concurrent.Future;
18
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;
33
34 import com.google.common.base.Optional;
35
36 public class OpenDaylightToasterTest extends AbstractDataBrokerTest{
37
38     private static InstanceIdentifier<Toaster> TOASTER_IID =
39                         InstanceIdentifier.builder( Toaster.class ).build();
40     OpendaylightToaster toaster;
41
42     @Override
43     protected void setupWithDataBroker(DataBroker dataBroker) {
44         toaster = new OpendaylightToaster();
45         toaster.setDataProvider( dataBroker );
46
47         /**
48          * Doesn't look like we have support for the NotificationProviderService yet, so mock it
49          * for now.
50          */
51         NotificationProviderService mockNotification = mock( NotificationProviderService.class );
52         toaster.setNotificationProvider( mockNotification );
53     }
54
55     @Test
56     public void testToasterInitOnStartUp() throws Exception {
57         DataBroker broker = getDataBroker();
58
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() );
63
64         Toaster toaster = optional.get();
65
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() );
71
72         Optional<Toaster> configToaster =
73                             rTx.read( LogicalDatastoreType.CONFIGURATION, TOASTER_IID ).get();
74         assertFalse( "Didn't expect config data for toaster.",
75                      configToaster.isPresent() );
76     }
77
78     @Test
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 )
84                                         .build();
85
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 );
89
90         RpcResult<Void> rpcResult = makeToast.get();
91
92         assertNotNull( rpcResult );
93         assertTrue( rpcResult.isSuccessful() );
94          //etc
95     }
96
97 }