Skip to content
Snippets Groups Projects
Commit a5a4d87a authored by Hema Vishnu Pola [Microsoft]'s avatar Hema Vishnu Pola [Microsoft]
Browse files

Merge branch 'integration_tests' into 'master'

Integration tests Refactored

See merge request !15
parents 72a6dc6b f92f8d2a
No related branches found
No related tags found
1 merge request!15Integration tests Refactored
Pipeline #7486 failed
Showing
with 252 additions and 47 deletions
......@@ -162,7 +162,7 @@ public class PubsubEndpoint {
throw new AppException(HttpStatus.SC_NOT_FOUND, "Not found subscription for notificationId:" + notificationId, "Subscription not found");
}
Subscription subscription = service.query(notificationId).get(0);
Subscription subscription = subscriptionList.get(0);
String jsonSubscription = gson.toJson(subscription);
this.subscriptionCacheFactory.put(subscription.getNotificationId(), jsonSubscription);
......
......@@ -35,7 +35,7 @@ public class EventGridHandshakeHandler implements IPubsubHandshakeHandler {
*/
@Override
public String getHandshakeResponse() {
String response;
String response;
try {
String validationCode = this.eventGridRequestBodyExtractor.getValidationCodeForHandshake();
......@@ -50,4 +50,4 @@ public class EventGridHandshakeHandler implements IPubsubHandshakeHandler {
return response;
}
}
}
\ No newline at end of file
......@@ -58,7 +58,7 @@ public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClien
IdToken cachedToken = (IdToken) tenantJwtCache.get(tenant.getName());
if ((cachedToken != null) && !IdToken.refreshToken(cachedToken)) {
return cachedToken.getTokenValue();
return "Bearer " + cachedToken.getTokenValue();
}
// TODO : Control the thread count via config and pool should be created once.
......@@ -76,7 +76,7 @@ public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClien
service.shutdown();
}
}
return ACCESS_TOKEN;
return "Bearer " + ACCESS_TOKEN;
}
// TODO : Refactor for making it test-able.
......
......@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.notification.pubsub;
package org.opengroup.osdu.notification.provider.azure;
import org.junit.Assert;
import org.junit.Test;
......@@ -72,5 +72,4 @@ public class EventGridHandshakeHandlerTest {
fail("Should Throw AppException");
}
}
}
}
\ No newline at end of file
......@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package org.opengroup.osdu.notification.pubsub;
package org.opengroup.osdu.notification.provider.azure;
import org.junit.Assert;
import org.junit.Test;
......
......@@ -97,24 +97,26 @@ public class ServiceAccountClientImplTest {
public void should_getTokenFromCache_getIdTokenTest() {
// SetUp
when(tenantJwtCacheMock.get(any())).thenReturn(idToken);
String expectedToken = "Bearer " +idToken.getTokenValue();
// Act
String returnedIdToken = sut.getIdToken(tenantName);
// Assert
Assert.assertEquals(idToken.getTokenValue(), returnedIdToken);
Assert.assertEquals(expectedToken, returnedIdToken);
}
@Test
public void should_updateCache_getIdTokenTest() {
// Set up
when(tenantJwtCacheMock.get(any())).thenReturn(idToken);
String expectedToken = "Bearer " +idToken.getTokenValue();
// Act
String returnedToken = this.sut.getIdToken(tenantName);
// Assert
Assert.assertEquals(validToken, returnedToken);
Assert.assertEquals(expectedToken, returnedToken);
}
@Test
......
......@@ -42,11 +42,11 @@
<distributionManagement>
<repository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/143/packages/maven</url>
<url>https://community.opengroup.org/api/v4/projects/157/packages/maven</url>
</repository>
<snapshotRepository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/143/packages/maven</url>
<url>https://community.opengroup.org/api/v4/projects/157/packages/maven</url>
</snapshotRepository>
</distributionManagement>
......@@ -56,20 +56,37 @@
<artifactId>notification-test-core</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.0.20</version>
<artifactId>core-lib-azure</artifactId>
<version>0.0.22</version>
<exclusions>
<exclusion>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
</exclusion>
<exclusion>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>0.0.17</version>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.3.5.RELEASE</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>0.9.7.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
......
// Copyright © Microsoft Corporation
//
// 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.api;
import org.opengroup.osdu.notification.util.Config;
import org.opengroup.osdu.notification.util.RestDescriptor;
import org.opengroup.osdu.notification.util.TestUtils;
import java.util.HashMap;
import java.util.Map;
public class PubsubEndpointHMACDescriptor extends RestDescriptor {
@Override
public String getPath() {
return "push-handlers/records-changed";
}
@Override
public String getHttpMethod() {
return "POST";
}
@Override
public String getValidBody() {
return "[{\n" +
" \"id\": \"2425\",\n" +
" \"eventType\": \"recordInserted\",\n" +
" \"subject\": \"myapp/vehicles/motorcycles\",\n" +
" \"data\": {\n" +
" \"attributes\": {\n" +
" \"correlation-id\": \"39137f49-67d6-4001-a6aa-15521ef4f49e\",\n" +
" \"data-partition-id\": \"" + TestUtils.getOsduTenant() + "\"\n" +
" },\n" +
" \"data\": \"W3sia2luZCI6InRlc3RraW5kIiwiaWQiOiJ0ZXN0aWQiLCJvcGVyYXRpb250eXBlIjoiY3JlYXRlIn0seyJraW5kIjoidGVzdGtpbmQyIiwiaWQiOiJ0ZXN0aWQyIiwib3BlcmF0aW9udHlwZSI6InVwZGF0ZSJ9XQ\",\n" +
" \"messageId\": \"136969346945\"\n" +
" },\n" +
" \"dataVersion\": \"1.0\",\n" +
" \"metadataVersion\": \"1\",\n" +
" \"eventTime\": \"2020-08-14T18:04:12+00:00\",\n" +
" \"topic\": \"/subscriptions/c99e2bf3-1777-412b-baba-d823676589c2/resourceGroups/komakkar-OSDU-RG/providers/Microsoft.EventGrid/topics/recordChanged\"\n" +
" }]";
}
@Override
public Map<String,String> getOsduTenantHeaders() {
Map<String, String> headers = new HashMap<>();
headers.put("Aeg-Subscription-Name", arg());
headers.put("data-partition-id", Config.Instance().OsduTenant);
return headers;
}
@Override
public Map<String,String> getCustomerTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("Aeg-Subscription-Name", arg());
headers.put("data-partition-id", Config.Instance().ClientTenant);
return headers;
}
}
// Copyright © Microsoft Corporation
//
// 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.api;
import org.junit.After;
......
// Copyright © Microsoft Corporation
//
// 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.util;
import com.google.common.base.Strings;
......
......@@ -69,7 +69,17 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.3.6</version>
<version>0.3.4</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.json</groupId>
......
......@@ -20,6 +20,9 @@ import org.opengroup.osdu.notification.util.Config;
import org.opengroup.osdu.notification.util.RestDescriptor;
import org.opengroup.osdu.notification.util.TestUtils;
import java.util.HashMap;
import java.util.Map;
public class PubsubEndpointGSADescriptor extends RestDescriptor {
@Override
......@@ -44,4 +47,18 @@ public class PubsubEndpointGSADescriptor extends RestDescriptor {
"\t\"subscription\":\"" + Config.Instance().NotificationId + "\"\n" +
"}";
}
@Override
public Map<String,String> getOsduTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", Config.Instance().OsduTenant);
return headers;
}
@Override
public Map<String,String> getCustomerTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", Config.Instance().ClientTenant);
return headers;
}
}
......@@ -16,9 +16,13 @@
package org.opengroup.osdu.notification.api;
import org.opengroup.osdu.notification.util.Config;
import org.opengroup.osdu.notification.util.RestDescriptor;
import org.opengroup.osdu.notification.util.TestUtils;
import java.util.HashMap;
import java.util.Map;
public class PubsubEndpointHMACDescriptor extends RestDescriptor {
@Override
......@@ -45,4 +49,18 @@ public class PubsubEndpointHMACDescriptor extends RestDescriptor {
"\t\"subscription\": \""+ arg() +"\"\n" +
"}\n";
}
@Override
public Map<String,String> getOsduTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", Config.Instance().OsduTenant);
return headers;
}
@Override
public Map<String,String> getCustomerTenantHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", Config.Instance().ClientTenant);
return headers;
}
}
......@@ -92,6 +92,8 @@ public abstract class PubsubEndpointHMACTests extends BaseTestTemplate {
Subscription subscriptionCreated = subscriptionService.create(subscription);
notificationId = subscriptionCreated.getNotificationId();
subscriptionId = subscriptionCreated.getId();
Config.Instance().NotificationId = notificationId;
}
@Override
......
......@@ -33,17 +33,15 @@ public class Config {
public static Config Instance() {
String env = getEnvironment();
config.ClientTenant = "nonexistenttenant";
config.IntegrationAudience = "245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com";
config.OsduTenant = "opendes";
config.Topic = "records-changed";
config.hmacSecretValue = System.getProperty("HMAC_SECRET", System.getenv("HMAC_SECRET"));
if (env.equalsIgnoreCase("LOCAL")) {
//make sure to run register service on a different port. You can also choose to point to Register service that is running in cloud
String registerUrl = "http://localhost:8081/";
String registerUrl = "http://localhost:8081/api/register/v1";
//must have notification and register services running on different ports
config.HostUrl = "http://localhost:8080/";
......
......@@ -18,6 +18,8 @@ package org.opengroup.osdu.notification.util;
import com.sun.jersey.api.client.ClientResponse;
import java.util.Map;
public abstract class RestDescriptor {
public RestDescriptor() {
......@@ -30,22 +32,24 @@ public abstract class RestDescriptor {
public abstract String getPath();
public abstract String getHttpMethod();
public abstract String getValidBody();
public abstract Map<String,String> getOsduTenantHeaders();
public abstract Map<String,String> getCustomerTenantHeaders();
public String getQuery() { return ""; }
public ClientResponse runHttp(String arg, String token) throws Exception{
this.arg = arg;
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), true);
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), getOsduTenantHeaders(),true);
}
public ClientResponse run(String arg, String token) throws Exception{
this.arg = arg;
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), false);
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), getOsduTenantHeaders(),false);
}
public ClientResponse runOnCustomerTenant(String arg, String token) throws Exception{
this.arg = arg;
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), TestUtils.getCustomerTenantHeaders(), false);
return TestUtils.send(getPath(), getHttpMethod(), token, getValidBody(), getQuery(), getCustomerTenantHeaders(), false);
}
public ClientResponse runOptions(String arg, String token) throws Exception{
this.arg = arg;
return TestUtils.send(getPath(), "OPTIONS", token, "", "", false);
return TestUtils.send(getPath(), "OPTIONS", token, "", "", getOsduTenantHeaders(),false);
}
}
\ No newline at end of file
......@@ -62,27 +62,6 @@ public abstract class TestUtils {
public abstract String getEditorToken() throws Exception;
public abstract String getNoAccessToken() throws Exception;
public static ClientResponse send(String path, String httpMethod, String token, String requestBody, String query, boolean enforceHttp)
throws Exception {
Map<String, String> headers = getOsduTenantHeaders();
return send(path, httpMethod, token, requestBody, query, headers, enforceHttp);
}
public static Map<String, String> getOsduTenantHeaders() {
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", getOsduTenant());
return headers;
}
public static Map<String, String> getCustomerTenantHeaders() {
Map<String, String> headers = new HashMap<>();
headers.put("data-partition-id", getCustomerTenant());
return headers;
}
public static ClientResponse send(String path, String httpMethod, String token, String requestBody, String query,
Map<String,String> headers, boolean enforceHttp)
throws Exception {
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2017-2019, 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-notification-testing</artifactId>
<version>0.0.5-SNAPSHOT</version>
<description>Root Notification Service project</description>
<packaging>pom</packaging>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<modules>
<module>notification-test-core</module>
<module>notification-test-azure</module>
<module>notification-test-gcp</module>
</modules>
<repositories>
<repository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/groups/17/-/packages/maven</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/44/packages/maven</url>
</repository>
<snapshotRepository>
<id>${gitlab-server}</id>
<url>https://community.opengroup.org/api/v4/projects/44/packages/maven</url>
</snapshotRepository>
</distributionManagement>
</project>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment