Improved tests

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@124255 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-02-17 14:09:32 +00:00
parent c5790461b4
commit 1ef3cedd3d
1 changed files with 38 additions and 7 deletions

View File

@ -13,6 +13,7 @@ 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.PortletUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.TaskUsageRecord;
@ -30,7 +31,8 @@ public class TestUsageRecord {
public final static String TEST_CONSUMER_ID = "name.surname";
public final static String TEST_SCOPE = "/infrastructure/vo";
public final static OperationResult TEST_OPERATION_RESULT = OperationResult.SUCCESS;
public final static String TEST_SERVICE_CLASS = "TestServiceClass";
public final static String TEST_SERVICE_NAME = "TestServiceName";
public final static String TEST_CALLED_METHOD = "TestCalledMethod";
@ -46,12 +48,14 @@ public class TestUsageRecord {
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";
public final static String TEST_PORTLET_ID = "TestPortlet";
public final static String TEST_PORTLET_OPERATION_ID = "TestPortletOperationID";
public final static String TEST_PORTLET_MESSAGE = "TestPortletMessage";
private final static long MIN_DURATION = 60; // millisec
private final static long MAX_DURATION = 1000; // millisec
@ -72,7 +76,7 @@ public class TestUsageRecord {
ServiceUsageRecord usageRecord = new ServiceUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(OperationResult.SUCCESS);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
usageRecord.setCallerHost(TEST_CALLER_HOST);
usageRecord.setHost(TEST_HOST);
@ -107,7 +111,7 @@ public class TestUsageRecord {
StorageUsageRecord usageRecord = new StorageUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(OperationResult.SUCCESS);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
usageRecord.setResourceOwner(TEST_RESOUCE_OWNER);
usageRecord.setResourceScope(TEST_RESOUCE_SCOPE);
@ -139,7 +143,7 @@ public class TestUsageRecord {
JobUsageRecord usageRecord = new JobUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(TEST_JOB_OPERATION_RESULT);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
usageRecord.setJobId(TEST_JOB_ID);
@ -171,7 +175,7 @@ public class TestUsageRecord {
TaskUsageRecord usageRecord = new TaskUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(TEST_JOB_OPERATION_RESULT);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
usageRecord.setTaskId(TEST_TASK_ID);
usageRecord.setTaskId(TEST_JOB_ID);
@ -205,4 +209,31 @@ public class TestUsageRecord {
return usageRecord;
}
/**
* @return
*/
public static PortletUsageRecord createTestPortletUsageRecord() {
PortletUsageRecord usageRecord = new PortletUsageRecord();
try {
usageRecord.setConsumerId(TEST_CONSUMER_ID);
usageRecord.setOperationResult(TEST_OPERATION_RESULT);
Calendar startTime = Calendar.getInstance();
Calendar endTime = Calendar.getInstance();
endTime.setTimeInMillis(startTime.getTimeInMillis() + HALF_DURATION);
startTime.setTimeInMillis(startTime.getTimeInMillis() - HALF_DURATION);
usageRecord.setPortletId(TEST_PORTLET_ID);
usageRecord.setOperationId(TEST_PORTLET_OPERATION_ID);
usageRecord.setMessage(TEST_PORTLET_MESSAGE);
} catch (InvalidValueException e) {
logger.error(" ------ You SHOULD NOT SEE THIS MESSAGE. Error Creating a test Usage Record", e);
}
return usageRecord;
}
}