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
187df94e
Commit
187df94e
authored
Sep 15, 2020
by
Komal Makkar
Browse files
Added tests
parent
0d22c6c6
Changes
3
Show whitespace changes
Inline
Side-by-side
provider/notification-azure/src/test/java/org/opengroup/osdu/notification/di/ServiceAccountJwtClientFactoryTest.java
View file @
187df94e
...
...
@@ -20,6 +20,7 @@ import org.junit.Test;
import
org.mockito.InjectMocks
;
import
org.opengroup.osdu.core.common.util.IServiceAccountJwtClient
;
import
org.opengroup.osdu.notification.provider.azure.di.ServiceAccountJwtClientFactory
;
import
org.opengroup.osdu.notification.provider.azure.util.ServiceAccountJwtAzureClientImpl
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
...
...
@@ -35,11 +36,18 @@ public class ServiceAccountJwtClientFactoryTest {
}
@Test
public
void
test
g
ettingInstance
()
{
public
void
test
G
ettingInstance
()
{
try
{
IServiceAccountJwtClient
serviceAccountJwtClient
=
sut
.
createInstance
();
// Act
Class
<?>
objectType
=
sut
.
getObjectType
();
// Assert
Assert
.
assertEquals
(
IServiceAccountJwtClient
.
class
,
objectType
);
// Act
IServiceAccountJwtClient
serviceAccountJwtClient
=
sut
.
createInstance
();
// Assert
Assert
.
assertNotNull
(
"Should not be null"
,
serviceAccountJwtClient
);
Assert
.
assertEquals
(
serviceAccountJwtClient
.
getClass
(),
ServiceAccountJwtAzureClientImpl
.
class
);
}
catch
(
Exception
exception
)
{
fail
(
"Should not throw this exception"
+
exception
.
getMessage
());
}
...
...
provider/notification-azure/src/test/java/org/opengroup/osdu/notification/provider/azure/EventGridRequestBodyExtractorTest.java
View file @
187df94e
...
...
@@ -301,4 +301,63 @@ public class EventGridRequestBodyExtractorTest {
// Assert
Assert
.
assertEquals
(
observedResponse
,
expectedResponse
);
}
@Test
public
void
should_throwWhenNotHandshakeRequest_getHandshakeResponse
()
throws
IOException
{
// Set up
String
validHandshakeRequestRoot
=
"[{\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\": \"opendes\"\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"
+
" }]"
;
String
expectedResponse
=
null
;
BufferedReader
reader
=
new
BufferedReader
(
new
StringReader
(
validHandshakeRequestRoot
));
when
(
this
.
httpServletRequest
.
getReader
()).
thenReturn
(
reader
);
sut
=
new
EventGridRequestBodyExtractor
(
httpServletRequest
,
log
);
// Act
String
observedResponse
=
this
.
sut
.
getValidationCodeForHandshake
();
// Assert
Assert
.
assertNull
(
observedResponse
);
}
@Test
public
void
should_throwWhenHandshakeRequest_extractDataFromRequestBody
()
throws
IOException
{
String
vaidRequestRoot
=
" [{\n"
+
" \"id\": \"testId\",\n"
+
" \"topic\": \"testTopic\",\n"
+
" \"subject\": \"\",\n"
+
" \"data\": {\n"
+
" \"validationCode\": \"testValidationCode\",\n"
+
" \"validationUrl\": \"testURL\"\n"
+
" },\n"
+
" \"eventType\": \"Microsoft.EventGrid.SubscriptionValidationEvent\",\n"
+
" \"eventTime\": \"2020-08-14T11:18:55.9278057Z\",\n"
+
" \"metadataVersion\": \"1\",\n"
+
" \"dataVersion\": \"2\"\n"
+
" }]"
;
BufferedReader
reader
=
new
BufferedReader
(
new
StringReader
(
vaidRequestRoot
));
when
(
this
.
httpServletRequest
.
getReader
()).
thenReturn
(
reader
);
sut
=
new
EventGridRequestBodyExtractor
(
httpServletRequest
,
log
);
// Act
Map
<
String
,
String
>
observedAttributes
=
this
.
sut
.
extractAttributesFromRequestBody
();
Assert
.
assertNull
(
observedAttributes
);
}
}
provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureCosmosPropertiesTest.java
View file @
187df94e
...
...
@@ -53,9 +53,7 @@ public class AzureCosmosPropertiesTest {
doReturn
(
null
).
when
(
kv
).
getSecret
(
"secret-name"
);
// Act
IllegalStateException
exception
=
assertThrows
(
IllegalStateException
.
class
,
()
->{
sut
.
cosmosKey
(
kv
);
});
IllegalStateException
exception
=
assertThrows
(
IllegalStateException
.
class
,
()
->
sut
.
cosmosKey
(
kv
));
// Assert
assertEquals
(
"No secret found with name cosmos-primary-key"
,
exception
.
getMessage
());
...
...
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