Refs #10646: Add the posisbility to rewrite the calledMethod which match a regular expression
Task-Url: https://support.d4science.org/issues/10646 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@160492 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
7471e6cc06
commit
2e4c076bd2
|
@ -9,6 +9,8 @@ import java.util.Set;
|
|||
import org.gcube.accounting.datamodel.UsageRecord;
|
||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.basetypes.AbstractServiceUsageRecord;
|
||||
import org.gcube.accounting.datamodel.validations.validators.CalledMethodRegexReplaceValidator;
|
||||
import org.gcube.accounting.datamodel.validations.validators.RegexReplace;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.documentstore.exception.InvalidValueException;
|
||||
|
@ -111,4 +113,47 @@ public class ServiceUsageRecordTest extends ScopedTest {
|
|||
logger.debug("{}", aggregatedServiceUsageRecord);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegexReplace() throws Exception{
|
||||
RecordUtility.addRecordPackage(ServiceUsageRecord.class.getPackage());
|
||||
RecordUtility.addRecordPackage(AggregatedServiceUsageRecord.class.getPackage());
|
||||
|
||||
String usageRecordString = "{"
|
||||
+ "\"startTime\": 1507334430481,"
|
||||
+ "\"endTime\": 1507334430481,"
|
||||
+ "\"creationTime\":1507334430724,"
|
||||
+ "\"serviceClass\":\"Index\","
|
||||
+ "\"callerHost\":\"88.197.53.47\","
|
||||
+ "\"callerQualifier\":\"UNKNOWN\","
|
||||
+ "\"recordType\":\"ServiceUsageRecord\","
|
||||
+ "\"consumerId\":\"UNKNOWN\","
|
||||
+ "\"aggregated\":true,"
|
||||
+ "\"serviceName\":\"FullTextIndexNode\","
|
||||
+ "\"duration\":3,"
|
||||
+ "\"maxInvocationTime\": 58,"
|
||||
+ "\"minInvocationTime\": 1,"
|
||||
+ "\"scope\":\"/d4science.research-infrastructures.eu/gCubeApps/iSearch\","
|
||||
+ "\"host\":\"dewn10.madgik.di.uoa.gr:8080\","
|
||||
+ "\"id\":\"12a631da-1541-4771-8961-8d7e4a694bc0\","
|
||||
+ "\"calledMethod\":\"/delete/3121eccdcbf9c6e982dcc5a2164b8b4029f51d8b1c448ddaf46316178d755c6f/oai:oai.datacite.org:352019\","
|
||||
+ "\"operationResult\":\"SUCCESS\""
|
||||
+ "}";
|
||||
|
||||
|
||||
String replace = "/delete/COLLECTION_ID/ITEM_ID";
|
||||
RegexReplace regexReplace = new RegexReplace("Index", "FullTextIndexNode",
|
||||
"/delete/[^\\t\\n\\r\\f\\v]+/[^\\t\\n\\r\\f\\v]+", replace);
|
||||
CalledMethodRegexReplaceValidator.addRegexReplace(regexReplace);
|
||||
|
||||
|
||||
UsageRecord usageRecord = DSMapper.unmarshal(AggregatedServiceUsageRecord.class, usageRecordString);
|
||||
logger.debug("{}", usageRecord);
|
||||
AggregatedServiceUsageRecord aggregatedServiceUsageRecord = new AggregatedServiceUsageRecord(usageRecord.getResourceProperties());
|
||||
logger.debug("{}", aggregatedServiceUsageRecord);
|
||||
|
||||
Assert.assertTrue(aggregatedServiceUsageRecord.getCalledMethod().compareTo(replace)==0);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue