From 19f579d5bac365a080ddcd734cd1ec02285cbe65 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 12 Feb 2016 14:54:24 +0000 Subject: [PATCH] Fixing tests git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@124134 82a268e6-3cf1-43bd-a215-b396298e98cf --- ...AccountingPersistenceQueryFactoryTest.java | 2 +- .../JobUsageRecordScopedTest.java | 2 +- .../ServiceUsageRecordScopedTest.java | 2 +- .../StorageUsageRecordScopedTest.java | 2 +- .../TaskUsageRecordScopedTest.java | 2 +- .../PersistenceBackendMonitorTest.java | 2 +- .../persistence/PersistenceBackendTest.java | 2 +- .../persistence/PersistenceCouchBaseTest.java | 2 +- .../persistence/PersistenceCouchDBTest.java | 2 +- .../aggregation/AggregationSchedulerTest.java | 2 +- .../java/org/gcube/utils/TestUsageRecord.java | 208 ++++++++++++++++++ .../java/org/gcube/utils/TestUtility.java | 2 +- .../executor/GCoreEndPointCreationTest.java | 12 +- 13 files changed, 224 insertions(+), 18 deletions(-) create mode 100644 src/test/java/org/gcube/utils/TestUsageRecord.java diff --git a/src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryFactoryTest.java b/src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryFactoryTest.java index 0733d11..aae011a 100644 --- a/src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryFactoryTest.java +++ b/src/test/java/org/gcube/accounting/analytics/persistence/AccountingPersistenceQueryFactoryTest.java @@ -21,10 +21,10 @@ import org.gcube.accounting.analytics.exception.NoUsableAccountingPersistenceQue import org.gcube.accounting.datamodel.UsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedStorageUsageRecord; -import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; +import org.gcube.utils.TestUsageRecord; import org.gcube.utils.TestUtility; import org.junit.After; import org.junit.Assert; diff --git a/src/test/java/org/gcube/accounting/datamodel/usagerecords/JobUsageRecordScopedTest.java b/src/test/java/org/gcube/accounting/datamodel/usagerecords/JobUsageRecordScopedTest.java index 6b1a18c..ccd30bf 100644 --- a/src/test/java/org/gcube/accounting/datamodel/usagerecords/JobUsageRecordScopedTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/usagerecords/JobUsageRecordScopedTest.java @@ -5,9 +5,9 @@ package org.gcube.accounting.datamodel.usagerecords; import java.util.Set; -import org.gcube.accounting.testutility.TestUsageRecord; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.documentstore.exception.InvalidValueException; +import org.gcube.utils.TestUsageRecord; import org.gcube.utils.TestUtility; import org.junit.After; import org.junit.Assert; diff --git a/src/test/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecordScopedTest.java b/src/test/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecordScopedTest.java index d405ad7..4e6a612 100644 --- a/src/test/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecordScopedTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/usagerecords/ServiceUsageRecordScopedTest.java @@ -5,9 +5,9 @@ package org.gcube.accounting.datamodel.usagerecords; import java.util.Set; -import org.gcube.accounting.testutility.TestUsageRecord; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.documentstore.exception.InvalidValueException; +import org.gcube.utils.TestUsageRecord; import org.gcube.utils.TestUtility; import org.junit.After; import org.junit.Assert; diff --git a/src/test/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecordScopedTest.java b/src/test/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecordScopedTest.java index 263b1f4..b642c76 100644 --- a/src/test/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecordScopedTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/usagerecords/StorageUsageRecordScopedTest.java @@ -5,9 +5,9 @@ package org.gcube.accounting.datamodel.usagerecords; import java.util.Set; -import org.gcube.accounting.testutility.TestUsageRecord; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.documentstore.exception.InvalidValueException; +import org.gcube.utils.TestUsageRecord; import org.gcube.utils.TestUtility; import org.junit.After; import org.junit.Assert; diff --git a/src/test/java/org/gcube/accounting/datamodel/usagerecords/TaskUsageRecordScopedTest.java b/src/test/java/org/gcube/accounting/datamodel/usagerecords/TaskUsageRecordScopedTest.java index 1cce179..562af7e 100644 --- a/src/test/java/org/gcube/accounting/datamodel/usagerecords/TaskUsageRecordScopedTest.java +++ b/src/test/java/org/gcube/accounting/datamodel/usagerecords/TaskUsageRecordScopedTest.java @@ -8,10 +8,10 @@ import java.util.Set; import org.gcube.accounting.datamodel.UsageRecord; import org.gcube.accounting.datamodel.basetypes.AbstractTaskUsageRecord; -import org.gcube.accounting.testutility.TestUsageRecord; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.records.Record; +import org.gcube.utils.TestUsageRecord; import org.gcube.utils.TestUtility; import org.junit.After; import org.junit.Assert; diff --git a/src/test/java/org/gcube/documentstore/persistence/PersistenceBackendMonitorTest.java b/src/test/java/org/gcube/documentstore/persistence/PersistenceBackendMonitorTest.java index 4ebbaaa..9fc95b8 100644 --- a/src/test/java/org/gcube/documentstore/persistence/PersistenceBackendMonitorTest.java +++ b/src/test/java/org/gcube/documentstore/persistence/PersistenceBackendMonitorTest.java @@ -7,11 +7,11 @@ import java.util.concurrent.TimeUnit; import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.accounting.datamodel.UsageRecord; -import org.gcube.accounting.testutility.TestUsageRecord; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.utils.StressTestUtility; import org.gcube.utils.TestOperation; +import org.gcube.utils.TestUsageRecord; import org.gcube.utils.TestUtility; import org.junit.After; import org.junit.Before; diff --git a/src/test/java/org/gcube/documentstore/persistence/PersistenceBackendTest.java b/src/test/java/org/gcube/documentstore/persistence/PersistenceBackendTest.java index 9521499..a8cb57e 100644 --- a/src/test/java/org/gcube/documentstore/persistence/PersistenceBackendTest.java +++ b/src/test/java/org/gcube/documentstore/persistence/PersistenceBackendTest.java @@ -8,10 +8,10 @@ import java.util.concurrent.TimeUnit; import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.accounting.datamodel.UsageRecord; -import org.gcube.accounting.testutility.TestUsageRecord; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.utils.StressTestUtility; import org.gcube.utils.TestOperation; +import org.gcube.utils.TestUsageRecord; import org.gcube.utils.TestUtility; import org.junit.After; import org.junit.Assert; diff --git a/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchBaseTest.java b/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchBaseTest.java index 5faeacb..9803cdd 100644 --- a/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchBaseTest.java +++ b/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchBaseTest.java @@ -5,9 +5,9 @@ package org.gcube.documentstore.persistence; import java.net.URL; -import org.gcube.accounting.testutility.TestUsageRecord; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.documentstore.records.Record; +import org.gcube.utils.TestUsageRecord; import org.gcube.utils.TestUtility; import org.junit.After; import org.junit.Assert; diff --git a/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchDBTest.java b/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchDBTest.java index f3cab86..6331bf9 100644 --- a/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchDBTest.java +++ b/src/test/java/org/gcube/documentstore/persistence/PersistenceCouchDBTest.java @@ -6,9 +6,9 @@ package org.gcube.documentstore.persistence; import java.net.URL; import org.codehaus.jackson.JsonNode; -import org.gcube.accounting.testutility.TestUsageRecord; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.documentstore.records.Record; +import org.gcube.utils.TestUsageRecord; import org.gcube.utils.TestUtility; import org.junit.After; import org.junit.Assert; diff --git a/src/test/java/org/gcube/documentstore/records/aggregation/AggregationSchedulerTest.java b/src/test/java/org/gcube/documentstore/records/aggregation/AggregationSchedulerTest.java index a1623cb..4cc4232 100644 --- a/src/test/java/org/gcube/documentstore/records/aggregation/AggregationSchedulerTest.java +++ b/src/test/java/org/gcube/documentstore/records/aggregation/AggregationSchedulerTest.java @@ -8,7 +8,6 @@ import java.util.List; import java.util.Map; import org.gcube.accounting.datamodel.UsageRecord; -import org.gcube.accounting.datamodel.basetypes.TestUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.documentstore.persistence.PersistenceExecutor; @@ -16,6 +15,7 @@ import org.gcube.documentstore.records.AggregatedRecord; import org.gcube.documentstore.records.Record; import org.gcube.utils.StressTestUtility; import org.gcube.utils.TestOperation; +import org.gcube.utils.TestUsageRecord; import org.gcube.utils.TestUtility; import org.junit.After; import org.junit.Assert; diff --git a/src/test/java/org/gcube/utils/TestUsageRecord.java b/src/test/java/org/gcube/utils/TestUsageRecord.java new file mode 100644 index 0000000..0b4f64f --- /dev/null +++ b/src/test/java/org/gcube/utils/TestUsageRecord.java @@ -0,0 +1,208 @@ +/** + * + */ +package org.gcube.utils; + +import java.io.Serializable; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.Calendar; +import java.util.HashMap; +import java.util.UUID; + +import org.gcube.accounting.datamodel.UsageRecord.OperationResult; +import org.gcube.accounting.datamodel.basetypes.AbstractStorageUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.JobUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord; +import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord; +import org.gcube.documentstore.exception.InvalidValueException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/ + * + */ +public class TestUsageRecord { + + private static final Logger logger = LoggerFactory.getLogger(TestUsageRecord.class); + + public final static String TEST_CONSUMER_ID = "name.surname"; + public final static String TEST_SCOPE = "/infrastructure/vo"; + + public final static String TEST_SERVICE_CLASS = "TestServiceClass"; + public final static String TEST_SERVICE_NAME = "TestServiceName"; + public final static String TEST_CALLED_METHOD = "TestCalledMethod"; + + public final static String TEST_CALLER_HOST = "remotehost"; + public final static String TEST_HOST = "localhost"; + + public final static String TEST_PROPERTY_NAME = "TestPropertyName"; + public final static String TEST_PROPERTY_VALUE = "TestPropertyValue"; + + public final static String TEST_JOB_ID = UUID.randomUUID().toString(); + public final static String TEST_JOB_NAME = "TestJobName"; + public final static int TEST_VMS_USED = 2; + public final static String TEST_JOB_QUALIFIER = "TestJobQualifier"; + public final static long HALF_DURATION = 10 * 60 * 1000; // 10 min + public final static OperationResult TEST_JOB_OPERATION_RESULT = OperationResult.SUCCESS; + + public final static String TEST_TASK_ID = UUID.randomUUID().toString(); + + public final static String TEST_NESTED_MAP = "TestNestedMap"; + + private final static long MIN_DURATION = 60; // millisec + private final static long MAX_DURATION = 1000; // millisec + + /** + * Generate A Random long in a range between min and max. + * This function is internally used to set random duration. + * @return the generated random long + */ + public static long generateRandomLong(long min, long max){ + return min + (int)(Math.random() * ((max - min) + 1)); + } + + /** + * Create a valid #ServiceUsageRecord with scope set automatically. + * @return the created #ServiceUsageRecord + */ + public static ServiceUsageRecord createTestServiceUsageRecord() { + ServiceUsageRecord usageRecord = new ServiceUsageRecord(); + try { + usageRecord.setConsumerId(TEST_CONSUMER_ID); + usageRecord.setOperationResult(OperationResult.SUCCESS); + + usageRecord.setCallerHost(TEST_CALLER_HOST); + usageRecord.setHost(TEST_HOST); + + usageRecord.setServiceClass(TEST_SERVICE_CLASS); + usageRecord.setServiceName(TEST_SERVICE_NAME); + usageRecord.setCalledMethod(TEST_CALLED_METHOD); + + usageRecord.setDuration(generateRandomLong(MIN_DURATION, MAX_DURATION)); + + } catch (InvalidValueException e) { + logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e); + throw new RuntimeException(e); + } + return usageRecord; + + } + public final static String TEST_RESOUCE_OWNER = "resource.owner"; + public final static String TEST_RESOUCE_SCOPE = TEST_SCOPE; + + public final static String TEST_RESOURCE_URI = "testprotocol://objectURI"; + public final static String TEST_PROVIDER_URI = "testprotocol://providerURI"; + + private final static long MIN_DATA_VOLUME = 1024; + private final static long MAX_DATA_VOLUME = 10240; + + /** + * Create a valid #StorageUsageRecord with scope set automatically. + * @return the created #StorageUsageRecord + */ + public static StorageUsageRecord createTestStorageUsageRecord() { + StorageUsageRecord usageRecord = new StorageUsageRecord(); + try { + usageRecord.setConsumerId(TEST_CONSUMER_ID); + usageRecord.setOperationResult(OperationResult.SUCCESS); + + usageRecord.setResourceOwner(TEST_RESOUCE_OWNER); + usageRecord.setResourceScope(TEST_RESOUCE_SCOPE); + + usageRecord.setResourceURI(new URI(TEST_RESOURCE_URI)); + usageRecord.setProviderURI(new URI(TEST_PROVIDER_URI)); + + usageRecord.setOperationType(AbstractStorageUsageRecord.OperationType.READ); + usageRecord.setDataType(AbstractStorageUsageRecord.DataType.STORAGE); + + usageRecord.setDataVolume(generateRandomLong(MIN_DATA_VOLUME, MAX_DATA_VOLUME)); + + usageRecord.setQualifier("image/png"); + + + } catch (InvalidValueException | URISyntaxException e) { + logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e); + throw new RuntimeException(e); + } + return usageRecord; + + } + + /** + * @return + */ + public static JobUsageRecord createTestJobUsageRecord() { + + JobUsageRecord usageRecord = new JobUsageRecord(); + try { + usageRecord.setConsumerId(TEST_CONSUMER_ID); + usageRecord.setOperationResult(TEST_JOB_OPERATION_RESULT); + + usageRecord.setJobId(TEST_JOB_ID); + + usageRecord.setJobName(TEST_JOB_NAME); + usageRecord.setJobQualifier(TEST_JOB_QUALIFIER); + + + Calendar startTime = Calendar.getInstance(); + Calendar endTime = Calendar.getInstance(); + endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION); + startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION); + + usageRecord.setJobStartTime(startTime); + usageRecord.setJobEndTime(endTime); + + + } catch (InvalidValueException e) { + logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e); + } + + return usageRecord; + } + + /** + * @return + */ + public static TaskUsageRecord createTestTaskUsageRecord() { + + TaskUsageRecord usageRecord = new TaskUsageRecord(); + try { + usageRecord.setConsumerId(TEST_CONSUMER_ID); + usageRecord.setOperationResult(TEST_JOB_OPERATION_RESULT); + + usageRecord.setTaskId(TEST_TASK_ID); + usageRecord.setTaskId(TEST_JOB_ID); + usageRecord.setHost(TEST_HOST); + + usageRecord.setRefHostingNodeId(UUID.randomUUID().toString()); + + Calendar startTime = Calendar.getInstance(); + Calendar endTime = Calendar.getInstance(); + endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION); + startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION); + + usageRecord.setTaskStartTime(startTime); + usageRecord.setTaskEndTime(endTime); + + HashMap inputParameters = new HashMap<>(); + inputParameters.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE); + inputParameters.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME); + + HashMap parameter = new HashMap<>(); + parameter.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE); + parameter.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME); + + inputParameters.put(TEST_NESTED_MAP, parameter); + + usageRecord.setInputParameters(inputParameters); + + } catch (InvalidValueException e) { + logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e); + } + + return usageRecord; + } +} diff --git a/src/test/java/org/gcube/utils/TestUtility.java b/src/test/java/org/gcube/utils/TestUtility.java index 3c0877d..be21cf9 100644 --- a/src/test/java/org/gcube/utils/TestUtility.java +++ b/src/test/java/org/gcube/utils/TestUtility.java @@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory; */ public class TestUtility { - public static final String TOKEN = ""; + public static final String TOKEN = "82a84741-debe-4c90-a907-c429c8272071"; public static final String PARENT_TOKEN = ""; /** diff --git a/src/test/java/org/gcube/vremanagement/executor/GCoreEndPointCreationTest.java b/src/test/java/org/gcube/vremanagement/executor/GCoreEndPointCreationTest.java index 1df6dec..a194275 100644 --- a/src/test/java/org/gcube/vremanagement/executor/GCoreEndPointCreationTest.java +++ b/src/test/java/org/gcube/vremanagement/executor/GCoreEndPointCreationTest.java @@ -16,7 +16,6 @@ import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Function.Parameter import org.gcube.common.resources.gcore.Resources; import org.gcube.utils.TestUtility; import org.gcube.vremanagement.executor.plugin.PluginDeclaration; -import org.gcube.vremanagement.executor.pluginmanager.PluginManager; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -29,8 +28,7 @@ import org.slf4j.LoggerFactory; */ public class GCoreEndPointCreationTest { - private static Logger logger = LoggerFactory - .getLogger(GCoreEndPointCreationTest.class); + private static Logger logger = LoggerFactory.getLogger(GCoreEndPointCreationTest.class); @Before public void before() throws Exception { @@ -42,7 +40,7 @@ public class GCoreEndPointCreationTest { SecurityTokenProvider.instance.reset(); } - protected static GCoreEndpoint createGCoreEndpoint(){ +/* protected static GCoreEndpoint createGCoreEndpoint(){ logger.debug("Getting Available Plugins and their own supported capabilities"); PluginManager pluginManager = PluginManager.getInstance(); @@ -58,12 +56,12 @@ public class GCoreEndPointCreationTest { profile.description("description"); profile.endpoints().add().nameAndAddress("name",URI.create("http://acme.org")); - /* + profile.serviceClass(ContextProvider.get().configuration().serviceClass()); profile.serviceName(ContextProvider.get().configuration().name()); profile.version(ContextProvider.get().configuration().version()); profile.description(ContextProvider.get().configuration().description()); - */ + DeploymentData deploymentData = profile.newDeploymentData(); deploymentData.activationTime(Calendar.getInstance()); @@ -101,6 +99,6 @@ public class GCoreEndPointCreationTest { logger.debug("Created {} for scope {}:\n{}", GCoreEndpoint.class.getSimpleName(), TestUtility.getScopeFromToken(), stringWriter); - } + }*/ }