Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SubscriptionChangeHandler from unregisterForNotifications #178

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,15 @@ public CompletionStage<NotificationsResponse> registerForNotifications(UUri topi
* Unregister for subscription change notifications.
*
* @param topic The topic to unregister for notifications.
* @param handler The {@link SubscriptionChangeHandler} to handle the subscription changes.
* @param options The {@link CallOptions} to be used for the unregister request.
* @return {@link CompletionStage} completed successfully with {@link NotificationResponse} with
* the status of the API call to uSubscription service, or completed unsuccessfully with
* {@link UStatus} with the reason for the failure. {@link UCode.PERMISSION_DENIED} is
* returned if the topic ue_id does not equal the callers ue_id.
*/
@Override
public CompletionStage<NotificationsResponse> unregisterForNotifications(UUri topic,
SubscriptionChangeHandler handler, CallOptions options) {
public CompletionStage<NotificationsResponse> unregisterForNotifications(UUri topic, CallOptions options) {
Objects.requireNonNull(topic, "Topic missing");
Objects.requireNonNull(handler, "Handler missing");
Objects.requireNonNull(options, "CallOptions missing");

NotificationsRequest request = NotificationsRequest.newBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,29 +177,25 @@ CompletionStage<NotificationsResponse> registerForNotifications(UUri topic,
* Unregister for subscription change notifications.
*
* @param topic The topic to unregister for notifications.
* @param handler The {@link SubscriptionChangeHandler} to be unregistered.
* @return {@link CompletionStage} completed successfully with {@link NotificationResponse} with
* the status of the API call to uSubscription service, or completed unsuccessfully with
* {@link UStatus} with the reason for the failure.
*/
default CompletionStage<NotificationsResponse> unregisterForNotifications(UUri topic,
SubscriptionChangeHandler handler) {
return unregisterForNotifications(topic, handler, CallOptions.DEFAULT);
default CompletionStage<NotificationsResponse> unregisterForNotifications(UUri topic) {
return unregisterForNotifications(topic, CallOptions.DEFAULT);
}


/**
* Unregister for subscription change notifications.
*
* @param topic The topic to unregister for notifications.
* @param handler The {@link SubscriptionChangeHandler} to be unregistered.
* @param options The {@link CallOptions} to be used for the request.
* @return {@link CompletionStage} completed successfully with {@link NotificationResponse} with
* the status of the API call to uSubscription service, or completed unsuccessfully with
* {@link UStatus} with the reason for the failure.
*/
CompletionStage<NotificationsResponse> unregisterForNotifications(UUri topic, SubscriptionChangeHandler handler,
CallOptions options);
CompletionStage<NotificationsResponse> unregisterForNotifications(UUri topic, CallOptions options);


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void test_creation_of_InMemoryUSubscriptionClient_passing_only_the_transp
.thenReturn(CompletableFuture.completedFuture(UStatus.newBuilder().setCode(UCode.OK).build()));

assertDoesNotThrow(() -> {
InMemoryUSubscriptionClient subscriber = new InMemoryUSubscriptionClient(transport);
new InMemoryUSubscriptionClient(transport);
});

verify(transport, times(2)).getSource();
Expand All @@ -112,7 +112,7 @@ public void test_creation_of_InMemoryUSubscriptionClient_passing_only_the_transp
@DisplayName("Testing creation of InMemoryUSubscriptionClient passing null for the transport")
public void test_creation_of_InMemoryUSubscriptionClient_passing_null_for_the_transport() {
assertThrows(NullPointerException.class, () -> {
InMemoryUSubscriptionClient subscriber = new InMemoryUSubscriptionClient(null);
new InMemoryUSubscriptionClient(null);
});
}

Expand Down Expand Up @@ -902,15 +902,6 @@ void test_unregisterListener_api_for_the_happy_path() {

InMemoryUSubscriptionClient subscriber = new InMemoryUSubscriptionClient(transport, rpcClient, notifier);
assertNotNull(subscriber);

SubscriptionChangeHandler handler = new SubscriptionChangeHandler() {
@Override
public void handleSubscriptionChange(UUri topic, SubscriptionStatus status) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'handleSubscriptionChange'");
}
};

UListener listener = new UListener() {
@Override
public void onReceive(UMessage message) {
Expand Down Expand Up @@ -1113,7 +1104,7 @@ public void handleSubscriptionChange(UUri topic, SubscriptionStatus status) {

assertDoesNotThrow(() -> {
subscriber.registerForNotifications(topic, handler).toCompletableFuture().get();
subscriber.unregisterForNotifications(topic, handler).toCompletableFuture().get();
subscriber.unregisterForNotifications(topic).toCompletableFuture().get();
});

verify(notifier, times(1)).registerNotificationListener(any(), any());
Expand All @@ -1129,16 +1120,8 @@ void test_unregisterNotification_api_when_passed_a_null_topic() {
InMemoryUSubscriptionClient subscriber = new InMemoryUSubscriptionClient(transport, rpcClient, notifier);
assertNotNull(subscriber);

SubscriptionChangeHandler handler = new SubscriptionChangeHandler() {
@Override
public void handleSubscriptionChange(UUri topic, SubscriptionStatus status) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'handleSubscriptionChange'");
}
};

assertThrows(NullPointerException.class, () -> {
subscriber.unregisterForNotifications(null, handler);
assertThrows(NullPointerException.class, () -> {
subscriber.unregisterForNotifications(null);
});

verify(notifier, times(1)).registerNotificationListener(any(), any());
Expand Down Expand Up @@ -1176,17 +1159,10 @@ void test_calling_unregisterNotification_api_when_we_never_registered_the_notifi
InMemoryUSubscriptionClient subscriber = new InMemoryUSubscriptionClient(transport, rpcClient, notifier);
assertNotNull(subscriber);

SubscriptionChangeHandler handler = new SubscriptionChangeHandler() {
@Override
public void handleSubscriptionChange(UUri topic, SubscriptionStatus status) {
// TODO Auto-generated method stub
throw new UnsupportedOperationException("Unimplemented method 'handleSubscriptionChange'");
}
};
UUri topic = UUri.newBuilder(transport.getSource()).setResourceId(0x8000).build();

assertDoesNotThrow(() -> {
CompletionStage<NotificationsResponse> response = subscriber.unregisterForNotifications(topic, handler);
CompletionStage<NotificationsResponse> response = subscriber.unregisterForNotifications(topic);
assertTrue(response.toCompletableFuture().isCompletedExceptionally());

response.handle((r, e) -> {
Expand Down
Loading