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;
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());
assertNull(child.getValue());
final QName qname = child.getNodeType().withoutRevision();
- assertTrue(listOfRpcsNames.contains(qname));
+ assertTrue(this.listOfRpcsNames.contains(qname));
}
}
}