Fixing tests
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/infrastructure-tests@124134 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
08b9c4fd1c
commit
19f579d5ba
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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<String, Serializable> inputParameters = new HashMap<>();
|
||||
inputParameters.put(TEST_PROPERTY_NAME, TEST_PROPERTY_VALUE);
|
||||
inputParameters.put(TEST_PROPERTY_VALUE, TEST_PROPERTY_NAME);
|
||||
|
||||
HashMap<String, Serializable> 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;
|
||||
}
|
||||
}
|
|
@ -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 = "";
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue