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.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataChangeListener;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataTreeChangeService;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.mdsal.dom.api.DOMSchemaService;
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 UriInfo uriInfo;
@Mock
private NotificationServiceHandler notificationServiceHandler;
- @Mock
- private TransactionChainHandler transactionHandler;
+ private TransactionChainHandler transactionHandler;
private SchemaContextHandler schemaHandler;
+ @SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- final TransactionChainHandler txHandler = Mockito.mock(TransactionChainHandler.class);
- final DOMTransactionChain domTx = Mockito.mock(DOMTransactionChain.class);
- Mockito.when(this.transactionHandler.get()).thenReturn(domTx);
- Mockito.when(txHandler.get()).thenReturn(domTx);
+ final DOMTransactionChain domTx = mock(DOMTransactionChain.class);
final DOMDataWriteTransaction wTx = Mockito.mock(DOMDataWriteTransaction.class);
Mockito.when(domTx.newWriteOnlyTransaction()).thenReturn(wTx);
final DOMDataReadWriteTransaction rwTx = Mockito.mock(DOMDataReadWriteTransaction.class);
Futures.immediateCheckedFuture(null);
Mockito.when(rwTx.submit()).thenReturn(checkedFutureEmpty);
Mockito.when(domTx.newReadWriteTransaction()).thenReturn(rwTx);
- final CheckedFuture<Void, TransactionCommitFailedException> checked = Mockito.mock(CheckedFuture.class);
+ final CheckedFuture<Void, TransactionCommitFailedException> checked = mock(CheckedFuture.class);
Mockito.when(wTx.submit()).thenReturn(checked);
Mockito.when(checked.checkedGet()).thenReturn(null);
- this.schemaHandler = new SchemaContextHandler(txHandler);
final DOMDataBroker dataBroker = mock(DOMDataBroker.class);
- final ListenerRegistration<DOMDataChangeListener> listener = mock(ListenerRegistration.class);
+ doReturn(domTx).when(dataBroker).createTransactionChain(any());
+
+ transactionHandler = new TransactionChainHandler(dataBroker);
+ schemaHandler = SchemaContextHandler.newInstance(transactionHandler, Mockito.mock(DOMSchemaService.class));
+
+ DOMDataTreeChangeService dataTreeChangeService = mock(DOMDataTreeChangeService.class);
+ doReturn(mock(ListenerRegistration.class)).when(dataTreeChangeService)
+ .registerDataTreeChangeListener(any(), any());
+
+ doReturn(Collections.singletonMap(DOMDataTreeChangeService.class, dataTreeChangeService))
+ .when(dataBroker).getSupportedExtensions();
+
doReturn(dataBroker).when(this.dataBrokerHandler).get();
- doReturn(listener).when(dataBroker).registerDataChangeListener(any(), any(), any(), any());
- final MultivaluedMap<String, String> map = Mockito.mock(MultivaluedMap.class);
+
+ final MultivaluedMap<String, String> map = mock(MultivaluedMap.class);
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")));
+ YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications")));
+ }
+
+ private static class LocalUriInfo extends SimpleUriInfo {
+
+ LocalUriInfo() {
+ super("/");
+ }
+
+ @Override
+ public URI getBaseUri() {
+ return UriBuilder.fromUri("http://localhost:8181").build();
+ }
}
@BeforeClass
@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());
}