Commit e91e8d66 authored by Nikhil Singh[MicroSoft]'s avatar Nikhil Singh[MicroSoft]
Browse files

Commit 3 contents:

1-Revert azure specific changes
2-Formatting and license addition
3-Removal of interface dependency for notification and subscription handler
parent 77d83e61
Pipeline #46791 failed with stages
in 34 seconds
......@@ -19,7 +19,7 @@ package org.opengroup.osdu.notification.api;
import org.opengroup.osdu.core.common.http.HttpResponse;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.notification.provider.interfaces.IPubsubRequestBodyExtractor;
import org.opengroup.osdu.notification.service.interfaces.INotificationHandler;
import org.opengroup.osdu.notification.service.NotificationHandler;
import org.opengroup.osdu.notification.utils.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
......@@ -37,7 +37,7 @@ public class PubsubEndpoint {
@Autowired
private IPubsubRequestBodyExtractor pubsubRequestBodyExtractor;
@Autowired
private INotificationHandler notificationHandler;
private NotificationHandler notificationHandler;
@Autowired
private JaxRsDpsLog log;
......@@ -51,7 +51,7 @@ public class PubsubEndpoint {
String pubsubMessage = this.pubsubRequestBodyExtractor.extractDataFromRequestBody();
Map<String, String> headerAttributes = this.pubsubRequestBodyExtractor.extractAttributesFromRequestBody();
try {
HttpResponse response = notificationHandler.NotifySubscriber(notificationId, pubsubMessage, headerAttributes);
HttpResponse response = notificationHandler.notifySubscriber(notificationId, pubsubMessage, headerAttributes);
if (!response.isSuccessCode()) {
this.log.error(NOT_ACKNOWLEDGE);
return ResponseEntity.badRequest().body(NOT_ACKNOWLEDGE);
......
......@@ -24,26 +24,24 @@ import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.notification.*;
import org.opengroup.osdu.notification.auth.factory.AuthFactory;
import org.opengroup.osdu.notification.auth.interfaces.SecretAuth;
import org.opengroup.osdu.notification.service.interfaces.INotificationHandler;
import org.opengroup.osdu.notification.service.interfaces.ISubscriptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class NotificationHandler implements INotificationHandler {
public class NotificationHandler {
@Autowired
private JaxRsDpsLog log;
@Autowired
private HttpClient httpClient;
@Autowired
private ISubscriptionHandler subscriptionHandler;
private SubscriptionHandler subscriptionHandler;
@Autowired
private AuthFactory authFactory;
private final int WAITING_TIME = 30000;
public HttpResponse NotifySubscriber (String notificationId, String pubsubMessage, Map<String, String> headerAttributes) throws Exception{
public HttpResponse notifySubscriber(String notificationId, String pubsubMessage, Map<String, String> headerAttributes) throws Exception{
Subscription subscription = subscriptionHandler.getSubscriptionFromCache(notificationId);
Secret secret = subscription.getSecret();
String endpoint = subscription.getPushEndpoint();
......
......@@ -28,14 +28,13 @@ import org.opengroup.osdu.core.common.notification.ISubscriptionFactory;
import org.opengroup.osdu.core.common.notification.ISubscriptionService;
import org.opengroup.osdu.core.common.notification.SubscriptionException;
import org.opengroup.osdu.notification.di.SubscriptionCacheFactory;
import org.opengroup.osdu.notification.service.interfaces.ISubscriptionHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.List;
@Component
public class SubscriptionHandler implements ISubscriptionHandler {
public class SubscriptionHandler {
@Autowired
private ISubscriptionFactory subscriptionFactory;
@Autowired
......
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.notification.service.interfaces;
import org.opengroup.osdu.core.common.http.HttpResponse;
import java.util.Map;
public interface INotificationHandler {
HttpResponse NotifySubscriber(String id, String notificationId, Map<String, String> headerAttributes) throws Exception;
}
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.notification.service.interfaces;
import org.opengroup.osdu.core.common.model.notification.Subscription;
import org.opengroup.osdu.core.common.notification.SubscriptionException;
import java.io.IOException;
public interface ISubscriptionHandler {
Subscription getSubscriptionFromCache(String notificationId) throws IOException, SubscriptionException;
}
......@@ -56,7 +56,7 @@ public class PubsubEndpointTests {
@Test
public void should_return200_whenPubsubMessageValidAndSuccessCodeReturnedFromNotificationHandler() throws Exception {
response.setResponseCode(200);
when(this.notificationHandler.NotifySubscriber(anyString(), anyString(), any())).thenReturn(response);
when(this.notificationHandler.notifySubscriber(anyString(), anyString(), any())).thenReturn(response);
ResponseEntity responseEntity = this.sut.recordChanged();
Assert.assertEquals(200, responseEntity.getStatusCode().value());
Assert.assertEquals("message acknowledged by client", responseEntity.getBody().toString());
......@@ -65,7 +65,7 @@ public class PubsubEndpointTests {
@Test
public void should_return400_whenPubsubMessageValidAndFailureCodeReturnedFromNotificationHandler() throws Exception {
response.setResponseCode(400);
when(this.notificationHandler.NotifySubscriber(anyString(), anyString(), any())).thenReturn(response);
when(this.notificationHandler.notifySubscriber(anyString(), anyString(), any())).thenReturn(response);
ResponseEntity responseEntity = this.sut.recordChanged();
Assert.assertEquals(400, responseEntity.getStatusCode().value());
Assert.assertEquals("message not acknowledged by client", responseEntity.getBody().toString());
......@@ -74,7 +74,7 @@ public class PubsubEndpointTests {
@Test
public void should_return400_whenPubsubMessageValidAndNotificationHandlerThrowsException() throws Exception {
response.setResponseCode(400);
when(this.notificationHandler.NotifySubscriber(anyString(), anyString(), any())).thenThrow(new Exception("error"));
when(this.notificationHandler.notifySubscriber(anyString(), anyString(), any())).thenThrow(new Exception("error"));
ResponseEntity responseEntity = this.sut.recordChanged();
Assert.assertEquals(400, responseEntity.getStatusCode().value());
Assert.assertEquals("message not acknowledged by client", responseEntity.getBody().toString());
......
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.notification.service;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
......@@ -11,12 +26,10 @@ import org.mockito.Mockito;
import org.opengroup.osdu.core.common.http.HttpClient;
import org.opengroup.osdu.core.common.http.HttpResponse;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.core.common.model.notification.*;
import org.opengroup.osdu.core.common.notification.SubscriptionException;
import org.opengroup.osdu.notification.auth.factory.AuthFactory;
import org.opengroup.osdu.notification.auth.interfaces.SecretAuth;
import org.opengroup.osdu.notification.di.CredentialHeadersProvider;
import org.powermock.modules.junit4.PowerMockRunner;
import java.util.HashMap;
import java.util.Map;
......@@ -59,7 +72,7 @@ public class NotificationHandlerTests {
when(this.httpClient.send(any())).thenReturn(response);
when(this.secretAuth.getPushUrl(gsa_subscription.getPushEndpoint())).thenReturn(gsa_subscription.getPushEndpoint());
Mockito.doNothing().when(secretAuth).getRequestHeaders(headers);
HttpResponse response = this.sut.NotifySubscriber(this.NOTIFICATION_ID,this.PUBSUB_MESSAGE,headers);
HttpResponse response = this.sut.notifySubscriber(this.NOTIFICATION_ID,this.PUBSUB_MESSAGE,headers);
Assert.assertEquals(200, response.getResponseCode());
}
......@@ -72,7 +85,7 @@ public class NotificationHandlerTests {
when(this.httpClient.send(any())).thenReturn(response);
when(this.secretAuth.getPushUrl(hmac_subscription.getPushEndpoint())).thenReturn(hmac_subscription.getPushEndpoint());
Mockito.doNothing().when(secretAuth).getRequestHeaders(headers);
HttpResponse response = this.sut.NotifySubscriber(this.NOTIFICATION_ID,this.PUBSUB_MESSAGE,headers);
HttpResponse response = this.sut.notifySubscriber(this.NOTIFICATION_ID,this.PUBSUB_MESSAGE,headers);
Assert.assertEquals(200, response.getResponseCode());
}
......@@ -84,7 +97,7 @@ public class NotificationHandlerTests {
when(this.secretAuth.getPushUrl(gsa_subscription.getPushEndpoint())).thenReturn(gsa_subscription.getPushEndpoint());
Mockito.doNothing().when(secretAuth).getRequestHeaders(headers);
when(subscriptionHandler.getSubscriptionFromCache(this.NOTIFICATION_ID)).thenThrow(new SubscriptionException("error", response));
this.sut.NotifySubscriber(this.NOTIFICATION_ID,this.PUBSUB_MESSAGE,headers);
this.sut.notifySubscriber(this.NOTIFICATION_ID,this.PUBSUB_MESSAGE,headers);
fail("should throw SubscriptionException");
}
......
/*
* Copyright 2017-2020, Schlumberger
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.opengroup.osdu.notification.service;
import com.fasterxml.jackson.databind.ObjectMapper;
......
......@@ -28,6 +28,8 @@ import org.opengroup.osdu.notification.provider.azure.pubsub.EventGridHandshakeH
import org.opengroup.osdu.notification.provider.azure.pubsub.EventGridRequestBodyExtractor;
import org.springframework.http.HttpStatus;
import java.io.IOException;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment