Commit 50d9062a authored by Komal Makkar's avatar Komal Makkar
Browse files

Added Tests.

parent 172a2d2c
Pipeline #7336 failed with stage
in 4 minutes and 16 seconds
......@@ -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>
......
......@@ -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));
......
......@@ -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}")
......
......@@ -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", "" ));
......
......@@ -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;
......
// 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);
}
}
......@@ -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");
......
......@@ -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
......
......@@ -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;
......
// 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 {
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment