refs #2437: Some records accounted on fallback are not recovered in the proper way in a special case

https://support.d4science.org/issues/2437
Added Tests

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@124673 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-02-29 14:30:48 +00:00
parent 9ba2a2e788
commit 34df63030e
4 changed files with 53 additions and 3 deletions

View File

@ -29,8 +29,7 @@ public class AggregatedServiceUsageRecord extends AbstractServiceUsageRecord imp
*/
private static final long serialVersionUID = 6387584974618335623L;
// Redefining DURATION to Set @AggregatedField
@RequiredField @ValidLong @AggregatedField
@AggregatedField
public static final String DURATION = AbstractServiceUsageRecord.DURATION;
@RequiredField @ValidLong @AggregatedField

View File

@ -33,10 +33,12 @@ public class AggregatedServiceUsageRecordTest extends ScopedTest {
AggregatedServiceUsageRecord aggregatedServiceUsageRecord = new AggregatedServiceUsageRecord(serviceUsageRecord);
Set<String> expectedRequiredFields = ServiceUsageRecordTest.getExpectedRequiredFields();
expectedRequiredFields.add(AggregatedServiceUsageRecord.DURATION);
expectedRequiredFields.add(AggregatedServiceUsageRecord.MAX_INVOCATION_TIME);
expectedRequiredFields.add(AggregatedServiceUsageRecord.MIN_INVOCATION_TIME);
expectedRequiredFields.addAll(AggregatedUsageRecordTest.getExpectedRequiredFields());
logger.debug("Expected Required Fields : {}", expectedRequiredFields);
Set<String> gotRequiredFields = aggregatedServiceUsageRecord.getRequiredFields();

View File

@ -3,7 +3,10 @@
*/
package org.gcube.accounting.datamodel.aggregation;
import java.util.Set;
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecord;
import org.gcube.accounting.datamodel.usagerecords.StorageUsageRecordTest;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.documentstore.exception.NotAggregatableRecordsExceptions;
import org.gcube.testutility.ScopedTest;
@ -21,6 +24,28 @@ public class AggregatedStorageUsageRecordTest extends ScopedTest {
private static Logger logger = LoggerFactory.getLogger(AggregatedStorageUsageRecordTest.class);
@Test
public void testRequiredFields() throws InvalidValueException {
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();
Assert.assertTrue(storageUsageRecord.getScope()==null);
storageUsageRecord.setScope(TestUsageRecord.TEST_SCOPE);
AggregatedStorageUsageRecord aggregatedStorageUsageRecord = new AggregatedStorageUsageRecord(storageUsageRecord);
Set<String> expectedRequiredFields = StorageUsageRecordTest.getExpectedRequiredFields();
expectedRequiredFields.addAll(AggregatedUsageRecordTest.getExpectedRequiredFields());
logger.debug("Expected Required Fields : {}", expectedRequiredFields);
Set<String> gotRequiredFields = aggregatedStorageUsageRecord.getRequiredFields();
logger.debug("Got Required Fields : {}", gotRequiredFields);
Assert.assertTrue(expectedRequiredFields.containsAll(gotRequiredFields));
Assert.assertTrue(gotRequiredFields.containsAll(expectedRequiredFields));
}
@Test
public void secondAsNotAggregated() throws InvalidValueException, NotAggregatableRecordsExceptions {
StorageUsageRecord storageUsageRecord = TestUsageRecord.createTestStorageUsageRecord();

View File

@ -0,0 +1,24 @@
/**
*
*/
package org.gcube.accounting.datamodel.aggregation;
import java.util.HashSet;
import java.util.Set;
import org.gcube.accounting.datamodel.AggregatedUsageRecord;
/**
* @author Luca Frosini (ISTI - CNR) http://www.lucafrosini.com/
*
*/
public class AggregatedUsageRecordTest {
public static Set<String> getExpectedRequiredFields(){
Set<String> expectedRequiredFields = new HashSet<String>();
expectedRequiredFields.add(AggregatedUsageRecord.AGGREGATED);
expectedRequiredFields.add(AggregatedUsageRecord.END_TIME);
expectedRequiredFields.add(AggregatedUsageRecord.START_TIME);
expectedRequiredFields.add(AggregatedUsageRecord.OPERATION_COUNT);
return expectedRequiredFields;
}
}