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
50d9062a
Commit
50d9062a
authored
Sep 04, 2020
by
Komal Makkar
Browse files
Added Tests.
parent
172a2d2c
Pipeline
#7336
failed with stage
in 4 minutes and 16 seconds
Changes
10
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
provider/notification-azure/pom.xml
View file @
50d9062a
...
...
@@ -110,13 +110,6 @@
<version>
2.1.6.RELEASE
</version>
</dependency>
<!--<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.0.0</version>
<scope>test</scope>
</dependency>-->
<dependency>
<groupId>
org.junit.jupiter
</groupId>
<artifactId>
junit-jupiter
</artifactId>
...
...
@@ -130,9 +123,26 @@
<version>
2.23.0
</version>
<scope>
test
</scope>
</dependency>
</dependencies>
<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>
<build>
<plugins>
<plugin>
...
...
@@ -165,7 +175,7 @@
<configuration>
<classifier>
spring-boot
</classifier>
<mainClass>
org.opengroup.osdu.notification.provider.
azure.Application
azure.Application
</mainClass>
</configuration>
</execution>
...
...
provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java
View file @
50d9062a
...
...
@@ -103,7 +103,7 @@ public class AppProperties implements IAppProperties {
return
maxCacheSize
;
}
p
rivate
String
getKeyVaultSecret
(
SecretClient
kv
,
String
secretName
)
{
p
ublic
String
getKeyVaultSecret
(
SecretClient
kv
,
String
secretName
)
{
KeyVaultSecret
secret
=
kv
.
getSecret
(
secretName
);
if
(
secret
==
null
)
{
logger
.
error
(
String
.
format
(
"Secret unexpectedly missing from KeyVault response for secret with name %s"
,
secretName
));
...
...
provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureCosmosProperties.java
View file @
50d9062a
...
...
@@ -6,11 +6,12 @@ import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.stereotype.Component
;
import
javax.inject.Named
;
@Co
mponent
@Co
nfiguration
public
class
AzureCosmosProperties
{
@Value
(
"${tenantinfo.container.name}"
)
...
...
provider/notification-azure/src/test/java/org/opengroup/osdu/notifica
t
ion/pubsub/EventGridHandshakeHandlerTest.java
→
provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/pubsub/EventGridHandshakeHandlerTest.java
View file @
50d9062a
...
...
@@ -13,7 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.notifica
t
ion.pubsub
;
package
org.opengroup.osdu.notificaion.pubsub
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
@@ -46,7 +46,7 @@ public class EventGridHandshakeHandlerTest {
private
EventGridHandshakeHandler
sut
;
@Test
public
void
should_returnValidResponse_getHandshakeResponse
()
throws
IOException
{
public
void
should_returnValidResponse_getHandshakeResponse
()
{
// Set up
when
(
sut
.
getHandshakeResponse
()).
thenReturn
(
"testValidationCode"
);
String
expectedResponse
=
"{\"ValidationResponse\":\"testValidationCode\"}"
;
...
...
@@ -59,7 +59,7 @@ public class EventGridHandshakeHandlerTest {
}
@Test
public
void
should_throw_getHandshakeResponse
()
throws
IOException
{
public
void
should_throw_getHandshakeResponse
()
{
// Set up
when
(
sut
.
getHandshakeResponse
())
.
thenThrow
(
new
AppException
(
HttpStatus
.
BAD_REQUEST
.
value
(),
"Request payload parsing error"
,
""
));
...
...
provider/notification-azure/src/test/java/org/opengroup/osdu/notifica
t
ion/pubsub/EventGridRequestBodyExtractorTest.java
→
provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/pubsub/EventGridRequestBodyExtractorTest.java
View file @
50d9062a
...
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.notifica
t
ion.pubsub
;
package
org.opengroup.osdu.notificaion.pubsub
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AppPropertiesTests.java
0 → 100644
View file @
50d9062a
// 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.notificaion.util
;
import
com.azure.security.keyvault.secrets.SecretClient
;
import
com.azure.security.keyvault.secrets.models.KeyVaultSecret
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.opengroup.osdu.core.common.logging.JaxRsDpsLog
;
import
org.opengroup.osdu.notification.provider.azure.util.AppProperties
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
public
class
AppPropertiesTests
{
@Mock
private
SecretClient
kv
;
@Mock
private
KeyVaultSecret
secret
;
@Mock
private
JaxRsDpsLog
logger
;
@InjectMocks
private
AppProperties
sut
;
@Before
public
void
init
()
{
initMocks
(
this
);
}
@Test
public
void
should_throwWhenSecretNameIsNull_getKeyVaultSecret
()
{
// Set-Up
doReturn
(
null
).
when
(
kv
).
getSecret
(
"secret-name"
);
// Act
IllegalStateException
exception
=
assertThrows
(
IllegalStateException
.
class
,
()
->{
sut
.
getKeyVaultSecret
(
kv
,
"secret-name"
);
});
// Assert
assertEquals
(
"No secret found with name secret-name"
,
exception
.
getMessage
());
}
@Test
public
void
should_throwWhenSecretIsMissing_getKeyVaultSecret
()
{
// Set-Up
doReturn
(
null
).
when
(
secret
).
getValue
();
doReturn
(
secret
).
when
(
kv
).
getSecret
(
"secret-name"
);
// Act
IllegalStateException
exception
=
assertThrows
(
IllegalStateException
.
class
,
()
->{
sut
.
getKeyVaultSecret
(
kv
,
"secret-name"
);
});
// Assert
assertEquals
(
"Secret unexpectedly missing from KeyVault response for secret with name secret-name"
,
exception
.
getMessage
());
}
@Test
public
void
should_returnRightClientAuth_getCosmosKey
()
{
// Set-Up
doReturn
(
"client-auth-secret"
).
when
(
secret
).
getValue
();
doReturn
(
secret
).
when
(
kv
).
getSecret
(
"app-dev-sp-password"
);
// Act
String
secretValue
=
sut
.
getAuthClientSecret
();
// Assert
assertEquals
(
"client-auth-secret"
,
secretValue
);
}
@Test
public
void
should_returnRightCosmosSecret_getCosmosKey
()
{
// Set-Up
doReturn
(
"cosmos-endpoint-secret"
).
when
(
secret
).
getValue
();
doReturn
(
secret
).
when
(
kv
).
getSecret
(
"app-dev-sp-username"
);
// Act
String
secretValue
=
sut
.
getAuthClientID
();
// Assert
assertEquals
(
"cosmos-endpoint-secret"
,
secretValue
);
}
@Test
public
void
should_returnRightAuthURL_getCosmosKey
()
{
// Set-Up
doReturn
(
"cosmos-endpoint-secret"
).
when
(
secret
).
getValue
();
doReturn
(
secret
).
when
(
kv
).
getSecret
(
"app-dev-sp-tenant-id"
);
// Act
String
secretValue
=
sut
.
getAuthURL
();
// Assert
assertEquals
(
"cosmos-endpoint-secret"
,
secretValue
);
}
}
provider/notification-azure/src/test/java/org/opengroup/osdu/notifica
t
ion/util/AzureCosmosPropertiesTest.java
→
provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AzureCosmosPropertiesTest.java
View file @
50d9062a
...
...
@@ -12,22 +12,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.notifica
t
ion.util
;
package
org.opengroup.osdu.notificaion.util
;
import
com.azure.security.keyvault.secrets.SecretClient
;
import
com.azure.security.keyvault.secrets.models.KeyVaultSecret
;
import
org.junit.
jupiter.api.Test
;
import
org.junit.
jupiter.api.extension.ExtendWith
;
import
org.junit.
Before
;
import
org.junit.
Test
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.
mockito.junit.jupiter.MockitoExtension
;
import
org.
opengroup.osdu.core.common.logging.JaxRsDpsLog
;
import
org.opengroup.osdu.notification.provider.azure.util.AzureCosmosProperties
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
import
static
org
.
mockito
.
MockitoAnnotations
.
initMocks
;
@ExtendWith
(
MockitoExtension
.
class
)
public
class
AzureCosmosPropertiesTest
{
@InjectMocks
...
...
@@ -39,8 +39,16 @@ public class AzureCosmosPropertiesTest {
@Mock
private
KeyVaultSecret
secret
;
@Mock
private
JaxRsDpsLog
logger
;
@Before
public
void
init
()
{
initMocks
(
this
);
}
@Test
public
void
kvSecretChecksForNullResponse
()
{
public
void
should_throwWhenSecretNameIsNull_getKeyVaultSecret
()
{
// Set-Up
doReturn
(
null
).
when
(
kv
).
getSecret
(
"secret-name"
);
...
...
@@ -52,8 +60,9 @@ public class AzureCosmosPropertiesTest {
// Assert
assertEquals
(
"No secret found with name secret-name"
,
exception
.
getMessage
());
}
@Test
public
void
kvSecretChecksForNullValueWithinResponse
()
{
public
void
should_throwWhenSecretIsMissing_getKeyVaultSecret
()
{
// Set-Up
doReturn
(
null
).
when
(
secret
).
getValue
();
doReturn
(
secret
).
when
(
kv
).
getSecret
(
"secret-name"
);
...
...
@@ -68,7 +77,7 @@ public class AzureCosmosPropertiesTest {
}
@Test
public
void
configReturnsCorrectSecr
etCosmosKey
()
{
public
void
should_returnRightCosmosKey_g
etCosmosKey
()
{
// Set-Up
doReturn
(
"cosmos-key-secret"
).
when
(
secret
).
getValue
();
doReturn
(
secret
).
when
(
kv
).
getSecret
(
"cosmos-primary-key"
);
...
...
@@ -81,7 +90,7 @@ public class AzureCosmosPropertiesTest {
}
@Test
public
void
configReturnsCorrect
SecretCosmos
Endpoint
()
{
public
void
should_returnRightCosmos
Secret
_get
Cosmos
Key
()
{
// Set-Up
doReturn
(
"cosmos-endpoint-secret"
).
when
(
secret
).
getValue
();
doReturn
(
secret
).
when
(
kv
).
getSecret
(
"cosmos-endpoint"
);
...
...
provider/notification-azure/src/test/java/org/opengroup/osdu/notifica
t
ion/util/AzureServiceAccountValidatorImplTest.java
→
provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AzureServiceAccountValidatorImplTest.java
View file @
50d9062a
...
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.notifica
t
ion.util
;
package
org.opengroup.osdu.notificaion.util
;
import
org.junit.Assert
;
import
org.junit.Before
;
...
...
@@ -41,7 +41,7 @@ public class AzureServiceAccountValidatorImplTest {
@Before
public
void
setup
()
{
when
(
this
.
appProperties
.
getAadClientID
()).
thenReturn
(
this
.
invalidAADClientID
);
when
(
this
.
appProperties
.
getAadClientID
()).
thenReturn
(
invalidAADClientID
);
}
@Test
...
...
provider/notification-azure/src/test/java/org/opengroup/osdu/notifica
t
ion/util/ServiceAccountClientImplTest.java
→
provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/ServiceAccountClientImplTest.java
View file @
50d9062a
...
...
@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package
org.opengroup.osdu.notifica
t
ion.util
;
package
org.opengroup.osdu.notificaion.util
;
import
org.apache.http.HttpStatus
;
import
org.junit.Assert
;
...
...
provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AppPropertiesTests.java
deleted
100644 → 0
View file @
172a2d2c
// 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.azure.security.keyvault.secrets.SecretClient
;
import
com.azure.security.keyvault.secrets.models.KeyVaultSecret
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.Mock
;
import
org.mockito.junit.jupiter.MockitoExtension
;
import
org.opengroup.osdu.notification.provider.azure.util.AzureCosmosProperties
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertThrows
;
import
static
org
.
mockito
.
Mockito
.
doReturn
;
@ExtendWith
(
MockitoExtension
.
class
)
public
class
AppPropertiesTests
{
}
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