}
static URI prepareUriByStreamName(final UriInfo uriInfo, final String streamName) {
- final int port = SubscribeToStreamUtil.prepareNotificationPort();
+ final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();
- final UriBuilder uriBuilder = uriInfo.getAbsolutePathBuilder();
- final UriBuilder uriToWebSocketServer =
- uriBuilder.port(port).scheme(RestconfStreamsConstants.SCHEMA_SUBSCIBRE_URI);
- final URI uri = uriToWebSocketServer.replacePath(streamName).build();
- return uri;
+ prepareNotificationPort(uriInfo.getBaseUri().getPort());
+ uriBuilder.scheme(RestconfStreamsConstants.SCHEMA_SUBSCIBRE_URI);
+ return uriBuilder.replacePath(streamName).build();
}
/**
/**
* Get port from web socket server. If doesn't exit, create it.
*
- * @return port
+ * @param port
+ * - port
*/
- private static int prepareNotificationPort() {
- int port = RestconfStreamsConstants.NOTIFICATION_PORT;
+ private static void prepareNotificationPort(final int port) {
try {
- final WebSocketServer webSocketServer = WebSocketServer.getInstance();
- port = webSocketServer.getPort();
+ WebSocketServer.getInstance();
} catch (final NullPointerException e) {
- WebSocketServer.createInstance(RestconfStreamsConstants.NOTIFICATION_PORT);
+ WebSocketServer.createInstance(port);
}
- return port;
}
static boolean checkExist(final SchemaContext schemaContext,
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.lang.reflect.Field;
+import java.net.URI;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.restconf.common.context.NormalizedNodeContext;
import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.util.SimpleUriInfo;
import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.restconf.nb.rfc8040.handlers.DOMDataBrokerHandler;
import org.opendaylight.restconf.nb.rfc8040.handlers.NotificationServiceHandler;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+@SuppressWarnings("deprecation")
public class RestconfStreamsSubscriptionServiceImplTest {
private static final String URI = "/restconf/18/data/ietf-restconf-monitoring:restconf-state/streams/stream/"
private SchemaContextHandler schemaHandler;
+ @SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
final Set<Entry<String, List<String>>> set = new HashSet<>();
Mockito.when(map.entrySet()).thenReturn(set);
Mockito.when(this.uriInfo.getQueryParameters()).thenReturn(map);
+ final UriBuilder baseUriBuilder = new LocalUriInfo().getBaseUriBuilder();
+ Mockito.when(uriInfo.getBaseUri()).thenReturn(baseUriBuilder.build());
+ Mockito.when(uriInfo.getBaseUriBuilder()).thenReturn(baseUriBuilder);
this.schemaHandler.onGlobalContextUpdated(
YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/notifications")));
}
+ private static class LocalUriInfo extends SimpleUriInfo {
+
+ LocalUriInfo() {
+ super("/");
+ }
+
+ @Override
+ public URI getBaseUri() {
+ return UriBuilder.fromUri("http://localhost:8181").build();
+ }
+ }
+
@BeforeClass
public static void setUpBeforeTest() throws Exception {
final Map<String, ListenerAdapter> listenersByStreamNameSetter = new HashMap<>();
@Test
public void testSubscribeToStream() throws Exception {
final UriBuilder uriBuilder = UriBuilder.fromUri(URI);
- final ListenerAdapter createListener = Notificator.createListener(
+ Notificator.createListener(
IdentifierCodec.deserialize("toaster:toaster/toasterStatus", this.schemaHandler.get()),
"data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
NotificationOutputType.XML);
"data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
this.uriInfo);
assertEquals(
- "ws://:8181/data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
+ "ws://localhost:8181/data-change-event-subscription"
+ + "/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
response.getNewHeaders().get("Location").toString());
}