Adding test for
ExperimentSummaryRepository
MODIFY
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepositoryTest.java
modules/registry-refactoring/src/test/java/org/apache/airavata/registry/core/repositories/expcatalog/ExperimentSummaryRepositoryTest.java
package org.apache.airavata.registry.core.repositories.expcatalog;
+import org.apache.airavata.model.experiment.ExperimentModel;
+import org.apache.airavata.model.experiment.ExperimentSummaryModel;
+import org.apache.airavata.model.experiment.ExperimentType;
+import org.apache.airavata.model.workspace.Gateway;
+import org.apache.airavata.model.workspace.Project;
import org.apache.airavata.registry.core.repositories.expcatalog.util.Initialize;
import org.apache.airavata.registry.core.utils.DBConstants;
import org.apache.airavata.registry.cpi.RegistryException;
@@ -9,6 +14,11 @@ import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
@@ -16,6 +26,9 @@ import static org.junit.Assert.assertFalse;
public class ExperimentSummaryRepositoryTest {
private static Initialize initialize;
+ GatewayRepository gatewayRepository;
+ ProjectRepository projectRepository;
+ ExperimentRepository experimentRepository;
ExperimentSummaryRepository experimentSummaryRepository;
private static final Logger logger = LoggerFactory.getLogger(ExperimentSummaryRepositoryTest.class);
@@ -24,6 +37,9 @@ public class ExperimentSummaryRepositoryTest {
try {
initialize = new Initialize("expcatalog-derby.sql");
initialize.initializeDB();
+ gatewayRepository = new GatewayRepository();
+ projectRepository = new ProjectRepository();
+ experimentRepository = new ExperimentRepository();
experimentSummaryRepository = new ExperimentSummaryRepository();
} catch (Exception e) {
logger.error(e.getMessage(), e);
@@ -38,7 +54,70 @@ public class ExperimentSummaryRepositoryTest {
@Test
public void ExperimentSummaryRepositoryTest() throws RegistryException {
+ Gateway gateway = new Gateway();
+ gateway.setGatewayId("gateway");
+ gateway.setDomain("SEAGRID");
+ gateway.setEmailAddress("abc@d.com");
+ String gatewayId = gatewayRepository.addGateway(gateway);
+
+ Project project = new Project();
+ project.setName("projectName");
+ project.setOwner("user");
+ project.setGatewayId(gatewayId);
+
+ String projectId = projectRepository.addProject(project, gatewayId);
+
+ ExperimentModel experimentModelOne = new ExperimentModel();
+ experimentModelOne.setProjectId(projectId);
+ experimentModelOne.setGatewayId(gatewayId);
+ experimentModelOne.setExperimentType(ExperimentType.SINGLE_APPLICATION);
+ experimentModelOne.setUserName("userOne");
+ experimentModelOne.setExperimentName("nameOne");
+ experimentModelOne.setDescription("descriptionOne");
+ experimentModelOne.setExecutionId("executionIdOne");
+
+ ExperimentModel experimentModelTwo = new ExperimentModel();
+ experimentModelTwo.setProjectId(projectId);
+ experimentModelTwo.setGatewayId(gatewayId);
+ experimentModelTwo.setExperimentType(ExperimentType.WORKFLOW);
+ experimentModelTwo.setUserName("userTwo");
+ experimentModelTwo.setExperimentName("nameTwo");
+ experimentModelTwo.setDescription("descriptionTwo");
+ experimentModelTwo.setExecutionId("executionIdTwo");
+
+ String experimentIdOne = experimentRepository.addExperiment(experimentModelOne);
+ assertTrue(experimentIdOne != null);
+
+ String expertimentIdTwo = experimentRepository.addExperiment(experimentModelTwo);
+ assertTrue(expertimentIdTwo != null);
+
+ Map<String, String> filters = new HashMap<>();
+ filters.put(DBConstants.Experiment.GATEWAY_ID, gatewayId);
+ filters.put(DBConstants.Experiment.PROJECT_ID, projectId);
+
+ List<ExperimentSummaryModel> experimentSummaryModelList = experimentSummaryRepository.
+ searchExperiments(filters, -1, 0, null, null);
+ assertTrue(experimentSummaryModelList.size() == 2);
+
+ filters.put(DBConstants.Experiment.EXECUTION_ID, "executionIdTwo");
+
+ experimentSummaryModelList = experimentSummaryRepository.
+ searchExperiments(filters, -1, 0, null, null);
+ assertTrue(experimentSummaryModelList.size() == 1);
+ assertEquals(expertimentIdTwo, experimentSummaryModelList.get(0).getExperimentId());
+
+ List<String> accessibleExperimentIds = new ArrayList<>();
+ accessibleExperimentIds.add(experimentIdOne);
+ filters.put(DBConstants.Experiment.EXECUTION_ID, "executionIdOne");
+
+ experimentSummaryModelList = experimentSummaryRepository.
+ searchAllAccessibleExperiments(accessibleExperimentIds, filters, -1, 0, null, null);
+ assertTrue(experimentSummaryModelList.size() == 1);
+ assertEquals(experimentIdOne, experimentSummaryModelList.get(0).getExperimentId());
+
+ //TODO: Use fromDate and toDate filters
+ //TODO: Write test for the getExperimentStatistics() method
}
}

Adding test for
ExperimentSummaryRepository