import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+
import com.google.common.base.Optional;
import com.google.common.io.Resources;
import com.google.common.util.concurrent.Futures;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
*
* @author Thomas Pantelis
*/
+@Deprecated
public class JSONRestconfServiceImplTest {
static final String IETF_INTERFACES_NS = "urn:ietf:params:xml:ns:yang:ietf-interfaces";
static final String IETF_INTERFACES_VERSION = "2013-07-04";
public void testPut() throws Exception {
final PutResult result = mock(PutResult.class);
when(brokerFacade.commitConfigurationDataPut(notNull(SchemaContext.class),
- notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class))).thenReturn(result);
+ notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(result);
when(result.getFutureOfPutData())
.thenReturn(Futures.immediateCheckedFuture(null));
when(result.getStatus()).thenReturn(Status.OK);
final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
-
- this.service.put(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.service.put(uriPath, payload, uriInfo);
final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
verify(brokerFacade).commitConfigurationDataPut(notNull(SchemaContext.class), capturedPath.capture(),
- capturedNode.capture());
+ capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
final DOMMountPoint mockMountPoint = setupTestMountPoint();
final PutResult result = mock(PutResult.class);
when(brokerFacade.commitMountPointDataPut(notNull(DOMMountPoint.class),
- notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class))).thenReturn(result);
+ notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(result);
when(result.getFutureOfPutData()).thenReturn(Futures.immediateCheckedFuture(null));
when(result.getStatus()).thenReturn(Status.OK);
final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont/cont1";
final String payload = loadData("/full-versions/testCont1Data.json");
- this.service.put(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.service.put(uriPath, payload, uriInfo);
final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
verify(brokerFacade).commitMountPointDataPut(same(mockMountPoint), capturedPath.capture(),
- capturedNode.capture());
+ capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
@Test(expected = OperationFailedException.class)
public void testPutFailure() throws Throwable {
final PutResult result = mock(PutResult.class);
+
when(result.getFutureOfPutData())
.thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")));
when(result.getStatus()).thenReturn(Status.OK);
when(brokerFacade.commitConfigurationDataPut(notNull(SchemaContext.class),
- notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class))).thenReturn(result);
+ notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(result);
final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
- this.service.put(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.service.put(uriPath, payload, uriInfo);
}
@SuppressWarnings("rawtypes")
@Test
public void testPost() throws Exception {
doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
- any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
+ any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class),
+ Mockito.anyString(), Mockito.anyString());
final String uriPath = null;
final String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
- this.service.post(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ final UriBuilder uriBuilder = UriBuilder.fromPath("");
+ Mockito.when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
+ this.service.post(uriPath, payload, uriInfo);
final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
verify(brokerFacade).commitConfigurationDataPost(notNull(SchemaContext.class), capturedPath.capture(),
- capturedNode.capture());
+ capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
verifyPath(capturedPath.getValue(), INTERFACES_QNAME);
public void testPostBehindMountPoint() throws Exception {
final DOMMountPoint mockMountPoint = setupTestMountPoint();
doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
- notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
+ notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class),
+ Mockito.anyString(), Mockito.anyString());
final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont";
final String payload = loadData("/full-versions/testCont1Data.json");
- this.service.post(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ final UriBuilder uriBuilder = UriBuilder.fromPath("");
+ Mockito.when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
+ this.service.post(uriPath, payload, uriInfo);
final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
verify(brokerFacade).commitConfigurationDataPost(same(mockMountPoint), capturedPath.capture(),
- capturedNode.capture());
+ capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
verifyLeafNode(actualNode, TEST_LF12_QNAME, "lf12 data");
}
- @Test
+ @Test(expected = TransactionCommitFailedException.class)
public void testPostFailure() throws Throwable {
doReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock"))).when(brokerFacade)
.commitConfigurationDataPost(any(SchemaContext.class), any(YangInstanceIdentifier.class),
- any(NormalizedNode.class));
+ any(NormalizedNode.class), Mockito.anyString(), Mockito.anyString());
final String uriPath = null;
final String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
- this.service.post(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ final UriBuilder uriBuilder = UriBuilder.fromPath("");
+ Mockito.when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
+
+ try {
+ this.service.post(uriPath, payload, uriInfo);
+ } catch (final OperationFailedException e) {
+ assertNotNull(e.getCause());
+ throw e.getCause();
+ }
}
@Test
@Test
public void testGetWithNoData() throws OperationFailedException {
- doReturn(null).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class));
+ doReturn(null).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class),
+ Mockito.anyString());
final String uriPath = "ietf-interfaces:interfaces";
- this.service.get(uriPath, LogicalDatastoreType.CONFIGURATION);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.service.get(uriPath, LogicalDatastoreType.CONFIGURATION, uriInfo);
}
@Test(expected=OperationFailedException.class)
public void testGetFailure() throws Exception {
final String invalidUriPath = "/ietf-interfaces:interfaces/invalid";
-
- this.service.get(invalidUriPath, LogicalDatastoreType.CONFIGURATION);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.service.get(invalidUriPath, LogicalDatastoreType.CONFIGURATION, uriInfo);
}
@SuppressWarnings("rawtypes")
.build();
if(datastoreType == LogicalDatastoreType.CONFIGURATION) {
- doReturn(entryNode).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class));
+ doReturn(entryNode).when(brokerFacade).readConfigurationData(notNull(YangInstanceIdentifier.class),
+ Mockito.anyString());
} else {
doReturn(entryNode).when(brokerFacade).readOperationalData(notNull(YangInstanceIdentifier.class));
}
final String uriPath = "/ietf-interfaces:interfaces/interface/eth0";
-
- final Optional<String> optionalResp = this.service.get(uriPath, datastoreType);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ Mockito.when(uriInfo.getQueryParameters(false)).thenReturn(value);
+ Mockito.when(value.getFirst("depth")).thenReturn("");
+
+ final Optional<String> optionalResp = this.service.get(uriPath, datastoreType, uriInfo);
assertEquals("Response present", true, optionalResp.isPresent());
final String jsonResp = optionalResp.get();
final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
if (datastoreType == LogicalDatastoreType.CONFIGURATION) {
- verify(brokerFacade).readConfigurationData(capturedPath.capture());
+ verify(brokerFacade).readConfigurationData(capturedPath.capture(), Mockito.anyString());
} else {
verify(brokerFacade).readOperationalData(capturedPath.capture());
}