Migrate toaster-producer to OSGi DS
[controller.git] / opendaylight / md-sal / samples / toaster-provider / src / test / java / org / opendaylight / controller / sample / toaster / provider / OpenDaylightToasterTest.java
index 23a51e1831127e17b78fc6ce28177116757e689a..7ad1e38e2c4a340cb36d6577eb132234f9bf0cb4 100644 (file)
@@ -14,46 +14,46 @@ 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.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.AbstractConcurrentDataBrokerTest;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.ReadTransaction;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
+import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 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;
+import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.MakeToastOutput;
 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.Toaster;
 import org.opendaylight.yang.gen.v1.http.netconfcentral.org.ns.toaster.rev091120.WheatBread;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.Uint32;
 
 public class OpenDaylightToasterTest extends AbstractConcurrentDataBrokerTest {
 
-    private static InstanceIdentifier<Toaster> TOASTER_IID = InstanceIdentifier.builder(Toaster.class).build();
+    private static final InstanceIdentifier<Toaster> TOASTER_IID = InstanceIdentifier.builder(Toaster.class).build();
     private OpendaylightToaster toaster;
 
     @Before
     public void setupToaster() {
-        toaster = new OpendaylightToaster();
-        toaster.setDataBroker(getDataBroker());
-        toaster.init();
-
-        // We'll mock the NotificationProviderService.
-        NotificationPublishService mockNotification = mock(NotificationPublishService.class);
-        toaster.setNotificationProvider(mockNotification);
+        toaster = new OpendaylightToaster(getDataBroker(), mock(NotificationPublishService.class),
+            mock(RpcProviderService.class));
     }
 
     @Test
     public void testToasterInitOnStartUp() throws Exception {
         DataBroker broker = getDataBroker();
 
-        ReadOnlyTransaction readTx = broker.newReadOnlyTransaction();
-        Optional<Toaster> optional = readTx.read(LogicalDatastoreType.OPERATIONAL, TOASTER_IID).get();
+        Optional<Toaster> optional;
+        try (ReadTransaction readTx = broker.newReadOnlyTransaction()) {
+            optional = readTx.read(LogicalDatastoreType.OPERATIONAL, TOASTER_IID).get();
+        }
         assertNotNull(optional);
         assertTrue("Operational toaster not present", optional.isPresent());
 
@@ -63,22 +63,24 @@ public class OpenDaylightToasterTest extends AbstractConcurrentDataBrokerTest {
         assertEquals(new DisplayString("Opendaylight"), toasterData.getToasterManufacturer());
         assertEquals(new DisplayString("Model 1 - Binding Aware"), toasterData.getToasterModelNumber());
 
-        Optional<Toaster> configToaster = readTx.read(LogicalDatastoreType.CONFIGURATION, TOASTER_IID).get();
-        assertFalse("Didn't expect config data for toaster.", configToaster.isPresent());
+        try (ReadTransaction readTx = broker.newReadOnlyTransaction()) {
+            Boolean configToaster = readTx.exists(LogicalDatastoreType.CONFIGURATION, TOASTER_IID).get();
+            assertFalse("Didn't expect config data for toaster.", configToaster);
+        }
     }
 
     @Test
     @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();
+        MakeToastInput toastInput = new MakeToastInputBuilder().setToasterDoneness(Uint32.valueOf(1))
+                .setToasterToastType(WheatBread.VALUE).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<RpcResult<Void>> makeToast = toaster.makeToast(toastInput);
+        Future<RpcResult<MakeToastOutput>> makeToast = toaster.makeToast(toastInput);
 
-        RpcResult<Void> rpcResult = makeToast.get();
+        RpcResult<MakeToastOutput> rpcResult = makeToast.get();
 
         assertNotNull(rpcResult);
         assertTrue(rpcResult.isSuccessful());