Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Open Subsurface Data Universe Software
Platform
System
Notification
Commits
89018c02
Commit
89018c02
authored
Sep 07, 2020
by
Komal Makkar
Browse files
master merge
parents
e0ca8e25
a5a4d87a
Changes
17
Hide whitespace changes
Inline
Side-by-side
notification-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpoint.java
View file @
89018c02
...
...
@@ -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
=
s
ervice
.
query
(
notificationId
)
.
get
(
0
);
Subscription
subscription
=
s
ubscriptionList
.
get
(
0
);
String
jsonSubscription
=
gson
.
toJson
(
subscription
);
this
.
subscriptionCacheFactory
.
put
(
subscription
.
getNotificationId
(),
jsonSubscription
);
...
...
provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/ServiceAccountJwtAzureClientImpl.java
View file @
89018c02
...
...
@@ -57,7 +57,7 @@ public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClien
IdToken
cachedToken
=
(
IdToken
)
this
.
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.
...
...
@@ -71,7 +71,7 @@ public class ServiceAccountJwtAzureClientImpl implements IServiceAccountJwtClien
service
.
shutdown
();
}
}
return
ACCESS_TOKEN
;
return
"Bearer "
+
ACCESS_TOKEN
;
}
// TODO : Refactor for making it test-able.
...
...
provider/notification-azure/src/test/java/org/opengroup/osdu/notification/p
ubsub
/EventGridHandshakeHandlerTest.java
→
provider/notification-azure/src/test/java/org/opengroup/osdu/notification/p
rovider/azure
/EventGridHandshakeHandlerTest.java
View file @
89018c02
...
...
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.notification.p
ubsub
;
package
org.opengroup.osdu.notification.p
rovider.azure
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
@@ -75,5 +75,4 @@ public class EventGridHandshakeHandlerTest {
fail
(
"Should Throw AppException"
);
}
}
}
}
\ No newline at end of file
provider/notification-azure/src/test/java/org/opengroup/osdu/notification/p
ubsub
/EventGridRequestBodyExtractorTest.java
→
provider/notification-azure/src/test/java/org/opengroup/osdu/notification/p
rovider/azure
/EventGridRequestBodyExtractorTest.java
View file @
89018c02
...
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.notification.p
ubsub
;
package
org.opengroup.osdu.notification.p
rovider.azure
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java
View file @
89018c02
...
...
@@ -101,24 +101,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
(
vali
dToken
,
returnedToken
);
Assert
.
assertEquals
(
expecte
dToken
,
returnedToken
);
}
@Test
...
...
testing/notification-test-azure/pom.xml
View file @
89018c02
...
...
@@ -42,11 +42,11 @@
<distributionManagement>
<repository>
<id>
${gitlab-server}
</id>
<url>
https://community.opengroup.org/api/v4/projects/1
43
/packages/maven
</url>
<url>
https://community.opengroup.org/api/v4/projects/1
57
/packages/maven
</url>
</repository>
<snapshotRepository>
<id>
${gitlab-server}
</id>
<url>
https://community.opengroup.org/api/v4/projects/1
43
/packages/maven
</url>
<url>
https://community.opengroup.org/api/v4/projects/1
57
/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>
...
...
testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/PubsubEndpointHMACDescriptor.java
0 → 100644
View file @
89018c02
// 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
;
}
}
testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/api/TestPubsubEndpointHMAC.java
View file @
89018c02
// 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
;
...
...
testing/notification-test-azure/src/test/java/org/opengroup/osdu/notification/util/AzureTestUtils.java
View file @
89018c02
// 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
;
...
...
testing/notification-test-core/pom.xml
View file @
89018c02
...
...
@@ -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>
...
...
testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpointGSADescriptor.java
View file @
89018c02
...
...
@@ -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
;
}
}
testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpointHMACDescriptor.java
View file @
89018c02
...
...
@@ -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
;
}
}
testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/api/PubsubEndpointHMACTests.java
View file @
89018c02
...
...
@@ -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
...
...
testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/Config.java
View file @
89018c02
...
...
@@ -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/"
;
...
...
testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/RestDescriptor.java
View file @
89018c02
...
...
@@ -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
testing/notification-test-core/src/main/java/org/opengroup/osdu/notification/util/TestUtils.java
View file @
89018c02
...
...
@@ -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
{
...
...
testing/pom.xml
0 → 100644
View file @
89018c02
<?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>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment