Merge "Bug 1593 - Flow Statistics manager is updating store with incorrect key Statis...
[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 package org.opendaylight.controller.sample.toaster.provider;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14 import static org.mockito.Mockito.mock;
15
16 import java.util.concurrent.Future;
17
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.ReadOnlyTransaction;
22 import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest;
23 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
24 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
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;
32
33 import com.google.common.base.Optional;
34
35 public class OpenDaylightToasterTest extends AbstractDataBrokerTest{
36
37     private static InstanceIdentifier<Toaster> TOASTER_IID =
38                         InstanceIdentifier.builder( Toaster.class ).build();
39     OpendaylightToaster toaster;
40
41     @Override
42     protected void setupWithDataBroker(DataBroker dataBroker) {
43         toaster = new OpendaylightToaster();
44         toaster.setDataProvider( dataBroker );
45
46         /**
47          * Doesn't look like we have support for the NotificationProviderService yet, so mock it
48          * for now.
49          */
50         NotificationProviderService mockNotification = mock( NotificationProviderService.class );
51         toaster.setNotificationProvider( mockNotification );
52     }
53
54     @Test
55     public void testToasterInitOnStartUp() throws Exception {
56         DataBroker broker = getDataBroker();
57
58         ReadOnlyTransaction rTx = broker.newReadOnlyTransaction();
59         Optional<Toaster> optional = rTx.read( LogicalDatastoreType.OPERATIONAL, TOASTER_IID ).get();
60         assertNotNull( optional );
61         assertTrue( "Operational toaster not present", optional.isPresent() );
62
63         Toaster toaster = optional.get();
64
65         assertEquals( Toaster.ToasterStatus.Up, toaster.getToasterStatus() );
66         assertEquals( new DisplayString("Opendaylight"),
67                       toaster.getToasterManufacturer() );
68         assertEquals( new DisplayString("Model 1 - Binding Aware"),
69                       toaster.getToasterModelNumber() );
70
71         Optional<Toaster> configToaster =
72                             rTx.read( LogicalDatastoreType.CONFIGURATION, TOASTER_IID ).get();
73         assertFalse( "Didn't expect config data for toaster.",
74                      configToaster.isPresent() );
75     }
76
77     @Test
78     @Ignore //ignored because it is not an e test right now. Illustrative purposes only.
79     public void testSomething() throws Exception{
80         MakeToastInput toastInput = new MakeToastInputBuilder()
81                                         .setToasterDoneness( 1L )
82                                         .setToasterToastType( WheatBread.class )
83                                         .build();
84
85         //NOTE: In a real test we would want to override the Thread.sleep() to prevent our junit test
86         //for sleeping for a second...
87         Future<RpcResult<Void>> makeToast = toaster.makeToast( toastInput );
88
89         RpcResult<Void> rpcResult = makeToast.get();
90
91         assertNotNull( rpcResult );
92         assertTrue( rpcResult.isSuccessful() );
93          //etc
94     }
95
96 }