Commit 976b9e13 authored by Hema Vishnu Pola [Microsoft]'s avatar Hema Vishnu Pola [Microsoft]
Browse files

Merge branch 'abpatil/dpndncy_mngmnt_az_sdk_upgrd' into 'master'

Dependency Management & Azure SDK Upgrade

See merge request !48
parents c219e75f dde9f6b9
Pipeline #21058 failed with stages
in 24 minutes and 33 seconds
......@@ -29,32 +29,45 @@
<packaging>jar</packaging>
<version>1.0.0-SNAPSHOT</version>
<properties>
<azure.version>2.1.7</azure.version>
<azure.appservice.resourcegroup></azure.appservice.resourcegroup>
<azure.appservice.plan></azure.appservice.plan>
<azure.appservice.appname></azure.appservice.appname>
<azure.appservice.subscription></azure.appservice.subscription>
<azure.keyvault.keys.version>4.2.3</azure.keyvault.keys.version>
<azure.evengrid.version>1.0.0-beta-3</azure.evengrid.version>
<osdu.corelibazure.version>0.0.48</osdu.corelibazure.version>
<osdu.oscorecommon.version>0.3.16</osdu.oscorecommon.version>
<osdu.register-core.version>1.0.0</osdu.register-core.version>
<junit-jupiter.version>5.6.0</junit-jupiter.version>
</properties>
<dependencyManagement>
<dependencies>
<!-- Inherit managed dependencies from core-lib-azure. -->
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>${osdu.corelibazure.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-active-directory-spring-boot-starter</artifactId>
<version>${azure.version}</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-security-keyvault-keys</artifactId>
<version>4.1.4</version>
<version>${azure.keyvault.keys.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure.eventgrid.v2020_04_01_preview</groupId>
<artifactId>azure-mgmt-eventgrid</artifactId>
<version>1.0.0-beta-3</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.21.0</version>
<version>${azure.evengrid.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
......@@ -91,17 +104,17 @@
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>0.0.28</version>
<version>${osdu.corelibazure.version}</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>os-core-common</artifactId>
<version>0.3.6</version>
<version>${osdu.oscorecommon.version}</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>register-core</artifactId>
<version>1.0.0</version>
<version>${osdu.register-core.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
......@@ -112,31 +125,15 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--
Override the spring-boot version of these dependencies to the ones
required by the azure-core library. This needs to be done for each
app that depends on this library
-->
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>0.9.0.RELEASE</version>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>3.3.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.0</version>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.0</version>
<scope>test</scope>
</dependency>
</dependencies>
......
......@@ -14,17 +14,16 @@
package org.opengroup.osdu.register.provider.azure.action;
import com.azure.cosmos.FeedOptions;
import com.azure.cosmos.SqlParameter;
import com.azure.cosmos.SqlParameterList;
import com.azure.cosmos.SqlQuerySpec;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.SqlParameter;
import com.azure.cosmos.models.SqlQuerySpec;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.register.action.model.Action;
import org.opengroup.osdu.register.provider.azure.di.AzureBootstrapConfig;
import org.opengroup.osdu.register.provider.azure.di.CosmosContainerConfig;
import org.opengroup.osdu.register.provider.interfaces.action.IActionRepo;
import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.azure.cosmosdb.CosmosStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.google.cloud.Timestamp;
......@@ -63,7 +62,7 @@ public class ActionRepository implements IActionRepo {
ActionDoc doc = new ActionDoc(action, dpsHeaders.getPartitionId());
try {
cosmosStore.createItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getActionContainerName(), doc);
cosmosStore.createItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getActionContainerName(), dpsHeaders.getPartitionId(), doc);
}
catch (AppException e) {
if(e.getError().getCode() == 409) {
......@@ -113,10 +112,9 @@ public class ActionRepository implements IActionRepo {
public List<Action> getAllActions() {
SqlQuerySpec query = new SqlQuerySpec("SELECT * FROM c where c.dataPartitionId = @partitionId");
SqlParameterList pars = query.getParameters();
pars.add(new SqlParameter("@partitionId", dpsHeaders.getPartitionId()));
query.getParameters().add(new SqlParameter("@partitionId", dpsHeaders.getPartitionId()));
FeedOptions options = new FeedOptions();
CosmosQueryRequestOptions options = new CosmosQueryRequestOptions();
return cosmosStore.queryItems(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getActionContainerName(), query, options, ActionDoc.class)
.stream().map(this::convertToActionClass).collect(Collectors.toList());
}
......
......@@ -14,12 +14,11 @@
package org.opengroup.osdu.register.provider.azure.ddms;
import com.azure.cosmos.FeedOptions;
import com.azure.cosmos.SqlParameter;
import com.azure.cosmos.SqlParameterList;
import com.azure.cosmos.SqlQuerySpec;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.SqlParameter;
import com.azure.cosmos.models.SqlQuerySpec;
import com.google.cloud.Timestamp;
import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.azure.cosmosdb.CosmosStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.opengroup.osdu.register.ddms.model.Ddms;
......@@ -58,7 +57,7 @@ public class DdmsRepository implements IDdmsRepository {
DdmsDoc doc = new DdmsDoc(ddms, dpsHeaders.getPartitionId());
try {
cosmosStore.createItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getDdmsContainerName(), doc);
cosmosStore.createItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getDdmsContainerName(), dpsHeaders.getPartitionId(), doc);
}
catch (AppException e) {
if(e.getError().getCode() == 409) {
......@@ -93,11 +92,11 @@ public class DdmsRepository implements IDdmsRepository {
SqlQuerySpec query = new SqlQuerySpec("SELECT f.id, f.name, f.description, f.contactEmail, f.createdDateTimeEpoch, " +
"f.interfaces FROM f JOIN c IN f.interfaces where c.entityType = @type and f.dataPartitionId = @partitionId");
SqlParameterList pars = query.getParameters();
List<SqlParameter> pars = query.getParameters();
pars.add(new SqlParameter("@type", type));
pars.add(new SqlParameter("@partitionId", dpsHeaders.getPartitionId()));
FeedOptions options = new FeedOptions();
CosmosQueryRequestOptions options = new CosmosQueryRequestOptions();
return cosmosStore.queryItems(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getDdmsContainerName(), query, options, DdmsDoc.class)
.stream().map(this::ConvertToDdmsClass).collect(Collectors.toList());
}
......
......@@ -15,6 +15,8 @@
package org.opengroup.osdu.register.provider.azure.di;
import com.azure.core.credential.TokenCredential;
import com.azure.cosmos.CosmosClient;
import com.azure.cosmos.CosmosClientBuilder;
import com.azure.identity.DefaultAzureCredentialBuilder;
import com.azure.security.keyvault.keys.cryptography.CryptographyClient;
import com.azure.security.keyvault.keys.cryptography.CryptographyClientBuilder;
......@@ -26,6 +28,8 @@ import com.microsoft.azure.credentials.AzureTokenCredentials;
import com.microsoft.azure.management.eventgrid.v2020_04_01_preview.implementation.EventGridManager;
import com.microsoft.rest.LogLevel;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
......@@ -152,4 +156,17 @@ public class AzureBootstrapConfig {
return secretValue;
}
@Autowired
@Named("COSMOS_ENDPOINT")
String cosmosEndpoint;
@Autowired
@Named("COSMOS_KEY")
String cosmosPrimaryKey;
@Bean
public CosmosClient buildCosmosClient(SecretClient kv) {
return new CosmosClientBuilder().endpoint(cosmosEndpoint).key(cosmosPrimaryKey).buildClient();
}
}
\ No newline at end of file
package org.opengroup.osdu.register.provider.azure.di;
import com.azure.cosmos.CosmosClient;
import org.opengroup.osdu.azure.cosmosdb.ICosmosClientFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
@Component
@Primary
public class SinglePartitionCosmosClientFactory implements ICosmosClientFactory {
@Autowired
CosmosClient cosmosClient;
@Override
public CosmosClient getClient(final String s) {
return cosmosClient;
}
}
......@@ -14,12 +14,11 @@
package org.opengroup.osdu.register.provider.azure.subscriber;
import com.azure.cosmos.FeedOptions;
import com.azure.cosmos.SqlParameter;
import com.azure.cosmos.SqlParameterList;
import com.azure.cosmos.SqlQuerySpec;
import com.azure.cosmos.models.CosmosQueryRequestOptions;
import com.azure.cosmos.models.SqlParameter;
import com.azure.cosmos.models.SqlQuerySpec;
import com.google.cloud.Timestamp;
import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.azure.cosmosdb.CosmosStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
......@@ -101,7 +100,7 @@ public class SubscriptionRepository implements ISubscriptionRepository {
doc.setKeyVersion(cryptographyUtil.getKeyVersion());
try {
cosmosStore.createItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getSubscriptionContainerName(), doc);
cosmosStore.createItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getSubscriptionContainerName(), dpsHeaders.getPartitionId(), doc);
logger.info(String.format("Record successfully created for Subscription with id %s", input.getId()));
}
catch (AppException e) {
......@@ -158,11 +157,11 @@ public class SubscriptionRepository implements ISubscriptionRepository {
SqlQuerySpec query = new SqlQuerySpec("SELECT * from c where c.notificationId = @notificationId and c.dataPartitionId = @partitionId");
SqlParameterList pars = query.getParameters();
List<SqlParameter> pars = query.getParameters();
pars.add(new SqlParameter("@notificationId", notificationId));
pars.add(new SqlParameter("@partitionId", dpsHeaders.getPartitionId()));
FeedOptions options = new FeedOptions();
CosmosQueryRequestOptions options = new CosmosQueryRequestOptions();
return cosmosStore.queryItems(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getSubscriptionContainerName(), query, options, SubscriptionDoc.class).stream()
.map(this::convertToSubscriptionClass)
......@@ -226,10 +225,10 @@ public class SubscriptionRepository implements ISubscriptionRepository {
SqlQuerySpec query = new SqlQuerySpec("SELECT * from c where c.dataPartitionId = @partitionId");
SqlParameterList pars = query.getParameters();
List<SqlParameter> pars = query.getParameters();
pars.add(new SqlParameter("@partitionId", dpsHeaders.getPartitionId()));
FeedOptions options = new FeedOptions();
CosmosQueryRequestOptions options = new CosmosQueryRequestOptions();
return cosmosStore.queryItems(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getSubscriptionContainerName(), query, options, SubscriptionDoc.class).stream()
.map(this::convertToSubscriptionClass)
......@@ -258,7 +257,7 @@ public class SubscriptionRepository implements ISubscriptionRepository {
try {
// If Push Subscription is not yet created we should create it, also we might
// need to update the cosmos db record since some other fields might be different
cosmosStore.upsertItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getSubscriptionContainerName(), input);
cosmosStore.upsertItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getSubscriptionContainerName(), dpsHeaders.getPartitionId(), input);
logger.info("Updating Record for subscription with ID: ", input.getId());
// Now creating the Push Subscription, if it fails again we should throw server error
// otherwise we can return Success code as response
......@@ -289,7 +288,7 @@ public class SubscriptionRepository implements ISubscriptionRepository {
doc.setSecretType(secret.getSecretType());
doc.setSecretValue(cryptographyUtil.encryptData(secret.toString()));
cosmosStore.upsertItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getSubscriptionContainerName(), doc);
cosmosStore.upsertItem(dpsHeaders.getPartitionId(), azureBootstrapConfig.getCosmosDBName(), cosmosContainerConfig.getSubscriptionContainerName(), dpsHeaders.getPartitionId(), doc);
return true;
}
......
......@@ -52,4 +52,7 @@ SUBSCRIBER_PRIVATE_KEY_ID=
ENVIRONMENT=LOCAL
SUBSCRIBER_SECRET=395f1b05e95171d7c0dde0b19fd6cf
management.health.defaults.enabled=false
\ No newline at end of file
management.health.defaults.enabled=false
management.health.azure-key-vault.enabled=false
azure.activedirectory.app-resource-id=${aad_client_id}
\ No newline at end of file
......@@ -20,7 +20,7 @@ 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.azure.CosmosStore;
import org.opengroup.osdu.azure.cosmosdb.CosmosStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
......@@ -98,7 +98,7 @@ public class ActionRepositoryTest {
@Test
public void createActionThrows409WhenIdExists() {
Action action = createAction();
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(actionContainer), any());
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(actionContainer), eq(dataPartitionId), any());
AppException exception = assertThrows(AppException.class, () -> {
repo.createAction(action);
......@@ -107,21 +107,21 @@ public class ActionRepositoryTest {
assertEquals(409, exception.getError().getCode());
assertEquals("Conflict", exception.getError().getReason());
assertEquals(String.format("An action already exists with the id: %s", action.getId()), exception.getError().getMessage());
verify(dpsHeaders, times(2)).getPartitionId();
verify(dpsHeaders, times(3)).getPartitionId();
verify(logger, times(1)).error(String.format("An action already exists with the id: %s", action.getId()));
}
@Test
public void createActionDocumentInsertedSuccessfully() {
Action action = createAction();
doNothing().when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(actionContainer), any());
doNothing().when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(actionContainer), eq(dataPartitionId), any());
Action output = repo.createAction(action);
assertEquals(action, output);
verify(azureBootstrapConfig, times(1)).getCosmosDBName();
verify(cosmosContainerConfig, times(1)).getActionContainerName();
verify(dpsHeaders, times(2)).getPartitionId();
verify(dpsHeaders, times(3)).getPartitionId();
}
@Test
......
......@@ -20,7 +20,7 @@ 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.azure.CosmosStore;
import org.opengroup.osdu.azure.cosmosdb.CosmosStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
......@@ -85,7 +85,7 @@ public class DdmsRepositoryTest {
@Test
public void createDdmsThrows409WhenIdExists() {
Ddms ddms = createDdms();
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(ddmsContainer), any());
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(ddmsContainer), eq(dataPartitionId), any());
AppException exception = assertThrows(AppException.class, () -> {
repo.create(ddms);
......@@ -95,21 +95,21 @@ public class DdmsRepositoryTest {
assertEquals("Conflict", exception.getError().getReason());
assertEquals(String.format("A DDMS already exists with the same id: %s", ddms.getId()), exception.getError().getMessage());
verify(cosmosContainerConfig, times(1)).getDdmsContainerName();
verify(dpsHeaders, times(2)).getPartitionId();
verify(dpsHeaders, times(3)).getPartitionId();
verify(logger, times(1)).error(String.format("A DDMS already exists with the same id: %s", ddms.getId()));
}
@Test
public void createDdmsDocumentInsertedSuccessfully() {
Ddms ddms = createDdms();
doNothing().when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(ddmsContainer), any());
doNothing().when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(ddmsContainer), eq(dataPartitionId), any());
Ddms output = repo.create(ddms);
assertEquals(ddms, output);
verify(azureBootstrapConfig, times(1)).getCosmosDBName();
verify(cosmosContainerConfig, times(1)).getDdmsContainerName();
verify(dpsHeaders, times(2)).getPartitionId();
verify(dpsHeaders, times(3)).getPartitionId();
}
@Test
......
......@@ -21,7 +21,7 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.opengroup.osdu.azure.CosmosStore;
import org.opengroup.osdu.azure.cosmosdb.CosmosStore;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.DpsHeaders;
......@@ -115,7 +115,7 @@ public class SubscriptionRepositoryTest {
@Test
public void createSubscriptionThrows409WhenIdExists() {
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), any());
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(dataPartitionId), any());
doReturn(Optional.of(subscriptionDoc)).when(cosmosStore).findItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(subscriptionId), eq(dataPartitionId), any());
doNothing().when(pushSubscription).checkIfPushSubscriptionExists(subscriptionId, topicName);
AppException exception = assertThrows(AppException.class, () -> {
......@@ -130,14 +130,14 @@ public class SubscriptionRepositoryTest {
verify(cosmosContainerConfig, times(2)).getSubscriptionContainerName();
verify(azureBootstrapConfig, times(2)).getCosmosDBName();
verify(subscription, times(2)).getId();
verify(dpsHeaders, times(4)).getPartitionId();
verify(dpsHeaders, times(5)).getPartitionId();
verify(logger, times(1)).error("A subscriber already exists with the same topic and endpoint combination");
}
@Test
public void createSubscriptionDocumentInsertedSuccessfullyAndPushSubscriptionCreated() {
doNothing().when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), any());
doNothing().when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(dataPartitionId), any());
when(cryptographyUtil.encryptData(secretValue)).thenReturn("some-string");
Subscription output = repo.create(subscription);
......@@ -145,7 +145,7 @@ public class SubscriptionRepositoryTest {
assertEquals(subscription, output);
verify(azureBootstrapConfig, times(1)).getCosmosDBName();
verify(cosmosContainerConfig, times(1)).getSubscriptionContainerName();
verify(dpsHeaders, times(2)).getPartitionId();
verify(dpsHeaders, times(3)).getPartitionId();
verify(cryptographyUtil, times(1)).encryptData(secretValue);
verify(cryptographyUtil, times(1)).getKeyName();
verify(cryptographyUtil, times(1)).getKeyVersion();
......@@ -157,7 +157,7 @@ public class SubscriptionRepositoryTest {
@Test
public void createSubscriptionDocumentInsertedSuccessfullyButPushSubscriptionCreationFailed() throws Exception {
doNothing().when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), any());
doNothing().when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(dataPartitionId), any());
doNothing().when(cosmosStore).deleteItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(subscriptionId), eq(dataPartitionId));
doThrow(new AppException(500, "Server Error", "Unexpected error creating Push subscription")).when(pushSubscription).createPushSubscription(subscriptionId, topicName);
when(cryptographyUtil.encryptData(secretValue)).thenReturn("some-string");
......@@ -176,7 +176,7 @@ public class SubscriptionRepositoryTest {
verify(cosmosContainerConfig, times(2)).getSubscriptionContainerName();
verify(subscription, times(4)).getId();
verify(subscription, times(3)).getSecret();
verify(dpsHeaders, times(4)).getPartitionId();
verify(dpsHeaders, times(5)).getPartitionId();
verify(cryptographyUtil, times(1)).encryptData(secretValue);
verify(cryptographyUtil, times(1)).getKeyName();
verify(cryptographyUtil, times(1)).getKeyVersion();
......@@ -188,10 +188,10 @@ public class SubscriptionRepositoryTest {
@Test
public void subscriptionCreatedSuccessfullyIfRecordExistsInCosmosDbButPushSubscriptionIsNotPresent() throws Exception {
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), any());
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(dataPartitionId), any());
doThrow(new AppException(404, "Reason", "Message")).when(pushSubscription).checkIfPushSubscriptionExists(subscriptionId, topicName);
doReturn(Optional.of(subscriptionDoc)).when(cosmosStore).findItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(subscriptionId), eq(dataPartitionId), any());
doNothing().when(cosmosStore).upsertItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), any());
doNothing().when(cosmosStore).upsertItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(dataPartitionId), any());
when(cryptographyUtil.encryptData(secretValue)).thenReturn("some-string");
Subscription output = repo.create(subscription);
......@@ -202,7 +202,7 @@ public class SubscriptionRepositoryTest {
verify(cosmosContainerConfig, times(3)).getSubscriptionContainerName();
verify(subscription, times(2)).getId();
verify(subscription, times(3)).getSecret();
verify(dpsHeaders, times(5)).getPartitionId();
verify(dpsHeaders, times(7)).getPartitionId();
verify(cryptographyUtil, times(1)).encryptData(secretValue);
verify(cryptographyUtil, times(1)).getKeyName();
verify(cryptographyUtil, times(1)).getKeyVersion();
......@@ -214,11 +214,11 @@ public class SubscriptionRepositoryTest {
@Test
public void createSubscriptionShouldThrow500ExceptionIfRecordExistsInCosmosDbButFailedToCreatePushSubscription() {
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), any());
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(dataPartitionId), any());
doThrow(new AppException(404, "Reason", "Message")).when(pushSubscription).checkIfPushSubscriptionExists(subscriptionId, topicName);
doReturn(Optional.of(subscriptionDoc)).when(cosmosStore).findItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(subscriptionId), eq(dataPartitionId), any());
doThrow(new AppException(500, "Server Error", "Unexpected error creating Push subscription")).when(pushSubscription).createPushSubscription(subscriptionId, topicName);
doNothing().when(cosmosStore).upsertItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), any());
doNothing().when(cosmosStore).upsertItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(dataPartitionId), any());
when(cryptographyUtil.encryptData(secretValue)).thenReturn("some-string");
AppException exception = assertThrows(AppException.class, () -> {
......@@ -234,7 +234,7 @@ public class SubscriptionRepositoryTest {
verify(cosmosContainerConfig, times(3)).getSubscriptionContainerName();
verify(subscription, times(2)).getId();
verify(subscription, times(3)).getSecret();
verify(dpsHeaders, times(5)).getPartitionId();
verify(dpsHeaders, times(7)).getPartitionId();
verify(cryptographyUtil, times(1)).encryptData(secretValue);
verify(cryptographyUtil, times(1)).getKeyName();
verify(cryptographyUtil, times(1)).getKeyVersion();
......@@ -247,9 +247,9 @@ public class SubscriptionRepositoryTest {
@Test
public void createSubscriptionShouldThrow500ExceptionIfRecordExistsInCosmosDbButUpsertOperationFailed() {
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), any());
doThrow(new AppException(409, "Reason", "Message")).when(cosmosStore).createItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(dataPartitionId), any());
doThrow(new AppException(404, "Reason", "Message")).when(pushSubscription).checkIfPushSubscriptionExists(subscriptionId, topicName);
doThrow(new AppException(500, "Reason", "Message")).when(cosmosStore).upsertItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), any());
doThrow(new AppException(500, "Reason", "Message")).when(cosmosStore).upsertItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(dataPartitionId), any());
doReturn(Optional.of(subscriptionDoc)).when(cosmosStore).findItem(eq(dataPartitionId), eq(cosmosDatabase), eq(subscriptionContainer), eq(subscriptionId), eq(dataPartitionId), any());
when(cryptographyUtil.encryptData(secretValue)).thenReturn("some-string");
......@@ -266,7 +266,7 @@ public class SubscriptionRepositoryTest {
verify(cosmosContainerConfig, times(3)).getSubscriptionContainerName();
verify(subscription, times(2)).getId();
verify(subscription, times(3)).getSecret();
verify(dpsHeaders, times(5)).getPartitionId();
verify(dpsHeaders, times(7)).getPartitionId();
verify(cryptographyUtil, times(1)).encryptData(secretValue);
verify(cryptographyUtil, times(1)).getKeyName();
verify(cryptographyUtil, times(1)).getKeyVersion();
......@@ -278,7 +278,7 @@ public class SubscriptionRepositoryTest {
@Test