Modifying the tests for Replica Catalog repositories
MODIFY
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataProductRepositoryTest.java
@@ -29,6 +29,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
@@ -38,6 +39,8 @@ public class DataProductRepositoryTest {
private static Initialize initialize;
private DataProductRepository dataProductRepository;
private String gatewayId = "testGateway";
+ private String userId = "testUser";
+ private String productName = "testProduct";
private static final Logger logger = LoggerFactory.getLogger(DataProductRepositoryTest.class);
@Before
@@ -60,14 +63,43 @@ public class DataProductRepositoryTest {
@Test
public void DataProductRepositoryTest() throws ReplicaCatalogException {
- DataProductModel dataProductModel = new DataProductModel();
- dataProductModel.setGatewayId(gatewayId);
- dataProductModel.setOwnerName("testUser");
- dataProductModel.setDataProductType(DataProductType.COLLECTION);
- dataProductModel.setProductSize(1);
- dataProductModel.setProductName("testProduct");
- String productUri = dataProductRepository.registerDataProduct(dataProductModel);
- assertTrue(productUri != null);
+ DataProductModel testDataProductModel1 = new DataProductModel();
+ testDataProductModel1.setGatewayId(gatewayId);
+ testDataProductModel1.setOwnerName(userId);
+ testDataProductModel1.setDataProductType(DataProductType.COLLECTION);
+ testDataProductModel1.setProductName(productName);
+
+ String productUri1 = dataProductRepository.registerDataProduct(testDataProductModel1);
+ assertTrue(dataProductRepository.isDataProductExists(productUri1));
+
+ DataProductModel retrievedDataProductModel = dataProductRepository.getDataProduct(productUri1);
+ assertEquals(retrievedDataProductModel.getProductUri(), productUri1);
+
+ DataProductModel testDataProductModel2 = new DataProductModel();
+ testDataProductModel2.setGatewayId(gatewayId);
+ testDataProductModel2.setOwnerName(userId);
+ testDataProductModel2.setDataProductType(DataProductType.FILE);
+ testDataProductModel2.setProductName(productName);
+
+ String productUri2 = dataProductRepository.registerDataProduct(testDataProductModel2);
+ assertTrue(dataProductRepository.isDataProductExists(productUri2));
+
+ testDataProductModel2.setParentProductUri(productUri1);
+ dataProductRepository.updateDataProduct(testDataProductModel2);
+
+ DataProductModel retrievedParentDataProductModel = dataProductRepository.getParentDataProduct(productUri2);
+ assertEquals(retrievedParentDataProductModel.getProductUri(), productUri1);
+
+ List<DataProductModel> childDataProductList = dataProductRepository.getChildDataProducts(productUri1);
+ assertTrue(childDataProductList.size() == 1);
+
+ List<DataProductModel> dataProductModelList = dataProductRepository.searchDataProductsByName(gatewayId, userId, productName, -1, 0);
+ assertTrue(dataProductModelList.size() == 2);
+
+ dataProductRepository.removeDataProduct(productUri1);
+ assertFalse(dataProductRepository.isDataProductExists(productUri1));
+
+ dataProductRepository.removeDataProduct(productUri2);
}
}

MODIFY
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/replicacatalog/DataReplicaLocationRepositoryTest.java
*/
package org.apache.airavata.registry.core.repositories.replicacatalog;
+import org.apache.airavata.model.data.replica.DataProductModel;
+import org.apache.airavata.model.data.replica.DataProductType;
+import org.apache.airavata.model.data.replica.DataReplicaLocationModel;
+import org.apache.airavata.model.data.replica.ReplicaPersistentType;
+import org.apache.airavata.registry.core.entities.replicacatalog.DataReplicaMetadataEntity;
import org.apache.airavata.registry.core.repositories.util.Initialize;
import org.apache.airavata.registry.cpi.ReplicaCatalogException;
import org.junit.After;
@@ -27,6 +32,7 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
@@ -34,6 +40,7 @@ import static org.junit.Assert.assertFalse;
public class DataReplicaLocationRepositoryTest {
private static Initialize initialize;
+ private DataProductRepository dataProductRepository;
private DataReplicaLocationRepository dataReplicaLocationRepository;
private String gatewayId = "testGateway";
private static final Logger logger = LoggerFactory.getLogger(DataReplicaLocationRepositoryTest.class);
@@ -43,6 +50,7 @@ public class DataReplicaLocationRepositoryTest {
try {
initialize = new Initialize("replicacatalog-derby.sql");
initialize.initializeDB();
+ dataProductRepository = new DataProductRepository();
dataReplicaLocationRepository = new DataReplicaLocationRepository();
} catch (Exception e) {
logger.error(e.getMessage(), e);
@@ -56,8 +64,61 @@ public class DataReplicaLocationRepositoryTest {
}
@Test
- public void DataProductRepositoryTest() throws ReplicaCatalogException {
+ public void DataReplicaLocationRepositoryTest() throws ReplicaCatalogException {
+ DataProductModel testDataProductModel = new DataProductModel();
+ testDataProductModel.setGatewayId(gatewayId);
+ testDataProductModel.setOwnerName("testUser");
+ testDataProductModel.setDataProductType(DataProductType.COLLECTION);
+ testDataProductModel.setProductName("productName");
+ String productUri = dataProductRepository.registerDataProduct(testDataProductModel);
+ assertTrue(dataProductRepository.isDataProductExists(productUri));
+ DataReplicaLocationModel testDataReplicaLocationModel1 = new DataReplicaLocationModel();
+ testDataReplicaLocationModel1.setReplicaName("replicaName1");
+ testDataReplicaLocationModel1.setProductUri(productUri);
+ String replicaId1 = dataReplicaLocationRepository.registerDataReplicaLocation(testDataReplicaLocationModel1);
+ assertTrue(dataReplicaLocationRepository.isExists(replicaId1));
+
+ DataReplicaLocationModel testDataReplicaLocationModel2 = new DataReplicaLocationModel();
+ testDataReplicaLocationModel2.setReplicaName("replicaName2");
+ testDataReplicaLocationModel2.setProductUri(productUri);
+ String replicaId2 = dataReplicaLocationRepository.registerDataReplicaLocation(testDataReplicaLocationModel2);
+ assertTrue(dataReplicaLocationRepository.isExists(replicaId2));
+
+ DataReplicaMetadataEntity dataReplicaMetadataEntity1 = new DataReplicaMetadataEntity();
+ dataReplicaMetadataEntity1.setReplicaId(replicaId1);
+ dataReplicaMetadataEntity1.setMetadataKey("dataKey1");
+ dataReplicaMetadataEntity1.setMetadataValue("dataValue1");
+
+ DataReplicaMetadataEntity dataReplicaMetadataEntity2 = new DataReplicaMetadataEntity();
+ dataReplicaMetadataEntity2.setReplicaId(replicaId1);
+ dataReplicaMetadataEntity1.setMetadataKey("dataKey2");
+ dataReplicaMetadataEntity1.setMetadataValue("dataValue2");
+
+ Map<String, String> dataReplicaMetadataEntityMap = new HashMap<>();
+ dataReplicaMetadataEntityMap.put(dataReplicaMetadataEntity1.getMetadataKey(), dataReplicaMetadataEntity1.getMetadataValue());
+ dataReplicaMetadataEntityMap.put(dataReplicaMetadataEntity2.getMetadataKey(), dataReplicaMetadataEntity2.getMetadataValue());
+ testDataReplicaLocationModel1.setReplicaMetadata(dataReplicaMetadataEntityMap);
+ testDataReplicaLocationModel1.setReplicaPersistentType(ReplicaPersistentType.TRANSIENT);
+ dataReplicaLocationRepository.updateDataReplicaLocation(testDataReplicaLocationModel1);
+
+ DataReplicaLocationModel retrievedDataReplicaLocationModel = dataReplicaLocationRepository.getDataReplicaLocation(replicaId1);
+ assertTrue(retrievedDataReplicaLocationModel.getReplicaMetadata().size() == 2);
+ assertEquals(retrievedDataReplicaLocationModel.getReplicaPersistentType(), testDataReplicaLocationModel1.getReplicaPersistentType());
+
+ testDataProductModel.setReplicaLocations(Arrays.asList(testDataReplicaLocationModel1, testDataReplicaLocationModel2));
+ dataProductRepository.updateDataProduct(testDataProductModel);
+ assertTrue(dataProductRepository.getDataProduct(productUri).getReplicaLocations().size() == 2);
+
+
+ List<DataReplicaLocationModel> dataReplicaLocationModelList = dataReplicaLocationRepository.getAllDataReplicaLocations(productUri);
+ assertTrue(dataReplicaLocationModelList.size() == 2);
+
+ dataReplicaLocationRepository.removeDataReplicaLocation(replicaId1);
+ assertFalse(dataReplicaLocationRepository.isDataReplicaLocationExists(replicaId1));
+
+ dataReplicaLocationRepository.removeDataReplicaLocation(replicaId2);
+ dataProductRepository.removeDataProduct(productUri);
}
}

Modifying the tests for Replica Catalog repositories