diff --git a/provider/notification-azure/pom.xml b/provider/notification-azure/pom.xml index 0e44f42fc6579414dd62e2032c13e62c769af88f..95a5b1e2236ac325d1f4819eec7cba50656a3f0d 100644 --- a/provider/notification-azure/pom.xml +++ b/provider/notification-azure/pom.xml @@ -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> diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java index 32f048a4696abb2945f66091a1505a5e259eda2a..8cbc9bb09044623e734a35f96b0d2f5d55926836 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AppProperties.java @@ -103,7 +103,7 @@ public class AppProperties implements IAppProperties { return maxCacheSize; } - private String getKeyVaultSecret(SecretClient kv, String secretName) { + public 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)); diff --git a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureCosmosProperties.java b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureCosmosProperties.java index 81bca28a60c26c81462321b06697a0602cf1cfbc..258c92293119454685997ba7ba2f230f48585a12 100644 --- a/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureCosmosProperties.java +++ b/provider/notification-azure/src/main/java/org/opengroup/osdu/notification/provider/azure/util/AzureCosmosProperties.java @@ -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; -@Component +@Configuration public class AzureCosmosProperties { @Value("${tenantinfo.container.name}") diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/pubsub/EventGridHandshakeHandlerTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/pubsub/EventGridHandshakeHandlerTest.java similarity index 94% rename from provider/notification-azure/src/test/java/org/opengroup/osdu/notification/pubsub/EventGridHandshakeHandlerTest.java rename to provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/pubsub/EventGridHandshakeHandlerTest.java index 68f87776f7e095c043653394e672aae62a79dfe8..dd3fafc8f08c4c6047541a71a2a2a699e0961146 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/pubsub/EventGridHandshakeHandlerTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/pubsub/EventGridHandshakeHandlerTest.java @@ -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.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", "" )); diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/pubsub/EventGridRequestBodyExtractorTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/pubsub/EventGridRequestBodyExtractorTest.java similarity index 99% rename from provider/notification-azure/src/test/java/org/opengroup/osdu/notification/pubsub/EventGridRequestBodyExtractorTest.java rename to provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/pubsub/EventGridRequestBodyExtractorTest.java index ad875413152efab0d5431ee334aa940bc926f36b..c00bd0fc3c5b77cdbba2ee01b4b36651c014521f 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/pubsub/EventGridRequestBodyExtractorTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/pubsub/EventGridRequestBodyExtractorTest.java @@ -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.notificaion.pubsub; import org.junit.Assert; import org.junit.Test; diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AppPropertiesTests.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AppPropertiesTests.java new file mode 100644 index 0000000000000000000000000000000000000000..0d612026b6525ef51857802c8488c4971b42a5e4 --- /dev/null +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AppPropertiesTests.java @@ -0,0 +1,118 @@ +// 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); + } + +} diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureCosmosPropertiesTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AzureCosmosPropertiesTest.java similarity index 82% rename from provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureCosmosPropertiesTest.java rename to provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AzureCosmosPropertiesTest.java index 5c424e74c93966c417758c1db227f51b2a8c29e7..a58cfabb5861ea6e2a3dc2302cea91381f93c9c6 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureCosmosPropertiesTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AzureCosmosPropertiesTest.java @@ -12,22 +12,22 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.opengroup.osdu.notification.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 configReturnsCorrectSecretCosmosKey() { + public void should_returnRightCosmosKey_getCosmosKey() { // 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 configReturnsCorrectSecretCosmosEndpoint() { + public void should_returnRightCosmosSecret_getCosmosKey() { // Set-Up doReturn("cosmos-endpoint-secret").when(secret).getValue(); doReturn(secret).when(kv).getSecret("cosmos-endpoint"); diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AzureServiceAccountValidatorImplTest.java similarity index 94% rename from provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java rename to provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AzureServiceAccountValidatorImplTest.java index 0899d9a4c6275dc152c9bdce952a91449260d066..6589e257e74768e0a660ab381fb7fed359b5859d 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AzureServiceAccountValidatorImplTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/AzureServiceAccountValidatorImplTest.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.opengroup.osdu.notification.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 diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/ServiceAccountClientImplTest.java similarity index 99% rename from provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java rename to provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/ServiceAccountClientImplTest.java index d7099cb5a6bdfdb4237ff72a6151bf454a5ee7dd..4e991a7db9f355a2c7b1257f05b35eaefc02c521 100644 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/ServiceAccountClientImplTest.java +++ b/provider/notification-azure/src/test/java/org/opengroup/osdu/notificaion/util/ServiceAccountClientImplTest.java @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.opengroup.osdu.notification.util; +package org.opengroup.osdu.notificaion.util; import org.apache.http.HttpStatus; import org.junit.Assert; diff --git a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AppPropertiesTests.java b/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AppPropertiesTests.java deleted file mode 100644 index 72b605e1a7d415bfdaa971feae9029963dcff393..0000000000000000000000000000000000000000 --- a/provider/notification-azure/src/test/java/org/opengroup/osdu/notification/util/AppPropertiesTests.java +++ /dev/null @@ -1,34 +0,0 @@ -// 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 { - - -}