import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
-import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.createUri;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
-
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Application;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
import org.junit.BeforeClass;
import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
public class RestStream extends JerseyTest {
@Override
protected Application configure() {
/* enable/disable Jersey logs to console */
-// enable(TestProperties.LOG_TRAFFIC);
-// enable(TestProperties.DUMP_ENTITY);
-// enable(TestProperties.RECORD_LOG_LEVEL);
-// set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
+ // enable(TestProperties.LOG_TRAFFIC);
+ // enable(TestProperties.DUMP_ENTITY);
+ // enable(TestProperties.RECORD_LOG_LEVEL);
+ // set(TestProperties.RECORD_LOG_LEVEL, Level.ALL.intValue());
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig = resourceConfig.registerInstances(restconfImpl, StructuredDataToXmlProvider.INSTANCE,
StructuredDataToJsonProvider.INSTANCE, XmlToCompositeNodeProvider.INSTANCE,
@Test
public void testCallRpcCallGet() throws UnsupportedEncodingException, InterruptedException {
- String uri = createUri("/operations/", "sal-remote:create-data-change-event-subscription");
+ String uri = "/operations/sal-remote:create-data-change-event-subscription";
Response responseWithStreamName = post(uri, MediaType.APPLICATION_XML, getRpcInput());
- String xmlResponse = responseWithStreamName.readEntity(String.class);
+ Document xmlResponse = responseWithStreamName.readEntity(Document.class);
assertNotNull(xmlResponse);
- assertTrue(xmlResponse.contains("<stream-name>ietf-interfaces:interfaces/ietf-interfaces:interface/eth0</stream-name>"));
+ Element outputElement = xmlResponse.getDocumentElement();
+ assertEquals("output",outputElement.getLocalName());
+
+ Node streamNameElement = outputElement.getFirstChild();
+ assertEquals("stream-name",streamNameElement.getLocalName());
+ assertEquals("ietf-interfaces:interfaces/ietf-interfaces:interface/eth0/datastore=CONFIGURATION/scope=BASE",streamNameElement.getTextContent());
- uri = createUri("/streams/stream/", "ietf-interfaces:interfaces/ietf-interfaces:interface/eth0");
+ uri = "/streams/stream/ietf-interfaces:interfaces/ietf-interfaces:interface/eth0/datastore=CONFIGURATION/scope=BASE";
Response responseWithRedirectionUri = get(uri, MediaType.APPLICATION_XML);
final URI websocketServerUri = responseWithRedirectionUri.getLocation();
assertNotNull(websocketServerUri);
- assertEquals(websocketServerUri.toString(), "http://localhost:8181/ietf-interfaces:interfaces/ietf-interfaces:interface/eth0");
+ assertTrue(websocketServerUri.toString().matches(".*http://localhost:[\\d]+/ietf-interfaces:interfaces/ietf-interfaces:interface/eth0.*"));
}
private Response post(String uri, String mediaType, String data) {