X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsamples%2Ftoaster-provider%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsample%2Ftoaster%2Fprovider%2FOpenDaylightToasterTest.java;h=23a51e1831127e17b78fc6ce28177116757e689a;hp=516f2149fe3abab0663b60e02c3bde6207eb5ba0;hb=390c714cdeae2efe67d55d5a401929653b534f5c;hpb=3a8636987a20a584ad25af7aba11ffcade21ebe3 diff --git a/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java b/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java index 516f2149fe..23a51e1831 100644 --- a/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java +++ b/opendaylight/md-sal/samples/toaster-provider/src/test/java/org/opendaylight/controller/sample/toaster/provider/OpenDaylightToasterTest.java @@ -1,10 +1,11 @@ /* -* Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved. -* -* This program and the accompanying materials are made available under the -* terms of the Eclipse Public License v1.0 which accompanies this distribution, -* and is available at http://www.eclipse.org/legal/epl-v10.html -*/ + * Copyright (c) 2014 Brocade Communications Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + package org.opendaylight.controller.sample.toaster.provider; import static org.junit.Assert.assertEquals; @@ -13,15 +14,16 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; +import com.google.common.base.Optional; import java.util.concurrent.Future; - +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; -import org.opendaylight.controller.md.sal.binding.test.AbstractDataBrokerTest; +import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; -import org.opendaylight.controller.sal.binding.api.NotificationProviderService; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.DisplayString; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInput; import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastInputBuilder; @@ -30,67 +32,56 @@ import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; -import com.google.common.base.Optional; +public class OpenDaylightToasterTest extends AbstractConcurrentDataBrokerTest { -public class OpenDaylightToasterTest extends AbstractDataBrokerTest{ + private static InstanceIdentifier TOASTER_IID = InstanceIdentifier.builder(Toaster.class).build(); + private OpendaylightToaster toaster; - private static InstanceIdentifier TOASTER_IID = - InstanceIdentifier.builder( Toaster.class ).build(); - OpendaylightToaster toaster; - - @Override - protected void setupWithDataBroker(DataBroker dataBroker) { + @Before + public void setupToaster() { toaster = new OpendaylightToaster(); - toaster.setDataProvider( dataBroker ); - - /** - * Doesn't look like we have support for the NotificationProviderService yet, so mock it - * for now. - */ - NotificationProviderService mockNotification = mock( NotificationProviderService.class ); - toaster.setNotificationProvider( mockNotification ); + toaster.setDataBroker(getDataBroker()); + toaster.init(); + + // We'll mock the NotificationProviderService. + NotificationPublishService mockNotification = mock(NotificationPublishService.class); + toaster.setNotificationProvider(mockNotification); } @Test public void testToasterInitOnStartUp() throws Exception { DataBroker broker = getDataBroker(); - ReadOnlyTransaction rTx = broker.newReadOnlyTransaction(); - Optional optional = rTx.read( LogicalDatastoreType.OPERATIONAL, TOASTER_IID ).get(); - assertNotNull( optional ); - assertTrue( "Operational toaster not present", optional.isPresent() ); + ReadOnlyTransaction readTx = broker.newReadOnlyTransaction(); + Optional optional = readTx.read(LogicalDatastoreType.OPERATIONAL, TOASTER_IID).get(); + assertNotNull(optional); + assertTrue("Operational toaster not present", optional.isPresent()); - Toaster toaster = optional.get(); + Toaster toasterData = optional.get(); - assertEquals( Toaster.ToasterStatus.Up, toaster.getToasterStatus() ); - assertEquals( new DisplayString("Opendaylight"), - toaster.getToasterManufacturer() ); - assertEquals( new DisplayString("Model 1 - Binding Aware"), - toaster.getToasterModelNumber() ); + assertEquals(Toaster.ToasterStatus.Up, toasterData.getToasterStatus()); + assertEquals(new DisplayString("Opendaylight"), toasterData.getToasterManufacturer()); + assertEquals(new DisplayString("Model 1 - Binding Aware"), toasterData.getToasterModelNumber()); - Optional configToaster = - rTx.read( LogicalDatastoreType.CONFIGURATION, TOASTER_IID ).get(); - assertFalse( "Didn't expect config data for toaster.", - configToaster.isPresent() ); + Optional configToaster = readTx.read(LogicalDatastoreType.CONFIGURATION, TOASTER_IID).get(); + assertFalse("Didn't expect config data for toaster.", configToaster.isPresent()); } @Test - @Ignore //ignored because it is not an e test right now. Illustrative purposes only. - public void testSomething() throws Exception{ - MakeToastInput toastInput = new MakeToastInputBuilder() - .setToasterDoneness( 1L ) - .setToasterToastType( WheatBread.class ) - .build(); + @Ignore //ignored because it is not a test right now. Illustrative purposes only. + public void testSomething() throws Exception { + MakeToastInput toastInput = new MakeToastInputBuilder().setToasterDoneness(1L) + .setToasterToastType(WheatBread.class).build(); - //NOTE: In a real test we would want to override the Thread.sleep() to prevent our junit test - //for sleeping for a second... - Future> makeToast = toaster.makeToast( toastInput ); + // NOTE: In a real test we would want to override the Thread.sleep() to + // prevent our junit test + // for sleeping for a second... + Future> makeToast = toaster.makeToast(toastInput); RpcResult rpcResult = makeToast.get(); - assertNotNull( rpcResult ); - assertTrue( rpcResult.isSuccessful() ); - //etc + assertNotNull(rpcResult); + assertTrue(rpcResult.isSuccessful()); + // etc } - }