Bug 5679 - ietf-yang-library module implemetation
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / restconf / rest / services / impl / RestconfOperationsServiceTest.java
index 6578d5114967320950f347f7f6b1f6d29b79f92e..7138f1dc0b5008fe2fd888382c8b373a4ebf6df2 100644 (file)
@@ -10,20 +10,25 @@ package org.opendaylight.restconf.rest.services.impl;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-
 import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.CheckedFuture;
 import java.net.URI;
 import java.util.Set;
 import javax.ws.rs.core.UriInfo;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.restconf.base.services.impl.RestconfOperationsServiceImpl;
 import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.handlers.TransactionChainHandler;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -49,22 +54,33 @@ public class RestconfOperationsServiceTest {
     public void init() throws Exception {
         MockitoAnnotations.initMocks(this);
         this.schemaContext = TestRestconfUtils.loadSchemaContext("/modules");
-        this.schemaContextHandler = new SchemaContextHandler();
+
+        final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
+        final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
+        Mockito.when(txHandler.get()).thenReturn(domTx);
+        final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class);
+        Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx);
+        final CheckedFuture checked = Mockito.mock(CheckedFuture.class);
+        Mockito.when(wTx.submit()).thenReturn(checked);
+        final Object valueObj = null;
+        Mockito.when(checked.checkedGet()).thenReturn(valueObj);
+        this.schemaContextHandler = new SchemaContextHandler(txHandler);
         this.schemaContextHandler.onGlobalContextUpdated(this.schemaContext);
+
         this.domMountPointServiceHandler = new DOMMountPointServiceHandler(this.domMountPointService);
 
         final QNameModule module1 = QNameModule.create(new URI("module:1"), null);
         final QNameModule module2 = QNameModule.create(new URI("module:2"), null);
 
-        listOfRpcsNames = ImmutableSet.of(
-            QName.create(module1, "dummy-rpc1-module1"), QName.create(module1, "dummy-rpc2-module1"),
-            QName.create(module2, "dummy-rpc1-module2"), QName.create(module2, "dummy-rpc2-module2"));
+        this.listOfRpcsNames = ImmutableSet.of(QName.create(module1, "dummy-rpc1-module1"),
+                QName.create(module1, "dummy-rpc2-module1"), QName.create(module2, "dummy-rpc1-module2"),
+                QName.create(module2, "dummy-rpc2-module2"));
     }
 
     @Test
     public void getOperationsTest() {
-        final RestconfOperationsServiceImpl oper = new RestconfOperationsServiceImpl(this.schemaContextHandler,
-            this.domMountPointServiceHandler);
+        final RestconfOperationsServiceImpl oper =
+                new RestconfOperationsServiceImpl(this.schemaContextHandler, this.domMountPointServiceHandler);
         final NormalizedNodeContext operations = oper.getOperations(this.uriInfo);
         final ContainerNode data = (ContainerNode) operations.getData();
         assertEquals("urn:ietf:params:xml:ns:yang:ietf-restconf", data.getNodeType().getNamespace().toString());
@@ -76,7 +92,7 @@ public class RestconfOperationsServiceTest {
             assertNull(child.getValue());
 
             final QName qname = child.getNodeType().withoutRevision();
-            assertTrue(listOfRpcsNames.contains(qname));
+            assertTrue(this.listOfRpcsNames.contains(qname));
         }
     }
 }