|
|
|
@ -87,6 +87,7 @@ public class TestRules extends ContextTest {
|
|
|
|
|
final String requiredMatchesFileName = rulesFile.getName().replaceAll(".json", ".csv");
|
|
|
|
|
File elaborationFile = new File(rulesDirectory, requiredMatchesFileName);
|
|
|
|
|
try(BufferedReader br = new BufferedReader(new FileReader(elaborationFile))) {
|
|
|
|
|
int lineNumber = 1;
|
|
|
|
|
for(String line; (line = br.readLine()) != null;) {
|
|
|
|
|
String[] splittedLine = line.split(",");
|
|
|
|
|
|
|
|
|
@ -96,10 +97,10 @@ public class TestRules extends ContextTest {
|
|
|
|
|
|
|
|
|
|
Replace replace = matcherReplace.check(serviceClass, serviceName, calledMethod);
|
|
|
|
|
if(replace != null) {
|
|
|
|
|
logger.info("{} --> {},{},{}", line, replace.getServiceClass(), replace.getServiceName(),
|
|
|
|
|
logger.info("line {}: {} --> {},{},{}", lineNumber, line, replace.getServiceClass(), replace.getServiceName(),
|
|
|
|
|
replace.getCalledMethod());
|
|
|
|
|
} else {
|
|
|
|
|
logger.error("{} does not match {}. This MUST not occur.", line,
|
|
|
|
|
logger.error("{} (line {}) does not match {}. This MUST not occur.", line, lineNumber,
|
|
|
|
|
matcherReplace.getMultiMatcher().toString());
|
|
|
|
|
throw new Exception();
|
|
|
|
|
}
|
|
|
|
@ -157,6 +158,8 @@ public class TestRules extends ContextTest {
|
|
|
|
|
Assert.assertTrue(aggregated.getMaxInvocationTime() == surDuration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++lineNumber;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
throw e;
|
|
|
|
@ -173,35 +176,42 @@ public class TestRules extends ContextTest {
|
|
|
|
|
for(File elaborationFileNoMatch : rulesDirectory.listFiles(filenameFilter)) {
|
|
|
|
|
logger.info("Comparing examples which must not match from file {}", elaborationFileNoMatch.getName());
|
|
|
|
|
try(BufferedReader br = new BufferedReader(new FileReader(elaborationFileNoMatch))) {
|
|
|
|
|
int lineCounter = 1;
|
|
|
|
|
for(String line; (line = br.readLine()) != null;) {
|
|
|
|
|
String[] splittedLine = line.split(",");
|
|
|
|
|
String serviceClass = splittedLine[0];
|
|
|
|
|
String serviceName = splittedLine[1];
|
|
|
|
|
String calledMethod = splittedLine[2];
|
|
|
|
|
Replace replace = matcherReplace.check(serviceClass, serviceName, calledMethod);
|
|
|
|
|
if(replace != null) {
|
|
|
|
|
logger.error("{} match {} but it should NOT. This MUST not occur.", line,
|
|
|
|
|
matcherReplace.getMultiMatcher().toString());
|
|
|
|
|
throw new Exception();
|
|
|
|
|
} else {
|
|
|
|
|
logger.trace("{} does NOT match as requested", line, replacementRegex.getServiceClass(),
|
|
|
|
|
replacementRegex.getServiceName(), replacementRegex.getCalledMethod());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServiceUsageRecord sur = TestUsageRecord.createTestServiceUsageRecord();
|
|
|
|
|
sur.setServiceClass(serviceClass);
|
|
|
|
|
sur.setServiceName(serviceName);
|
|
|
|
|
sur.setCalledMethod(calledMethod);
|
|
|
|
|
sur.validate();
|
|
|
|
|
//logger.trace("Should not be aggregated ServiceUsageRecord {}", sur);
|
|
|
|
|
for(AggregatedServiceUsageRecord asur : aggregatedMap.values()) {
|
|
|
|
|
try {
|
|
|
|
|
asur.aggregate(sur);
|
|
|
|
|
logger.error("The record {} has been aggregated and it should NOT", sur);
|
|
|
|
|
throw new Exception("The record has been aggregated and it should NOT");
|
|
|
|
|
} catch(NotAggregatableRecordsExceptions e) {
|
|
|
|
|
//logger.trace("{} is not aggragable as expected", sur);
|
|
|
|
|
try {
|
|
|
|
|
String[] splittedLine = line.split(",");
|
|
|
|
|
String serviceClass = splittedLine[0];
|
|
|
|
|
String serviceName = splittedLine[1];
|
|
|
|
|
String calledMethod = splittedLine[2];
|
|
|
|
|
Replace replace = matcherReplace.check(serviceClass, serviceName, calledMethod);
|
|
|
|
|
if(replace != null) {
|
|
|
|
|
logger.error("{} match {} but it should NOT. This MUST not occur.", line,
|
|
|
|
|
matcherReplace.getMultiMatcher().toString());
|
|
|
|
|
throw new Exception();
|
|
|
|
|
} else {
|
|
|
|
|
logger.trace("{} does NOT match as requested", line, replacementRegex.getServiceClass(),
|
|
|
|
|
replacementRegex.getServiceName(), replacementRegex.getCalledMethod());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ServiceUsageRecord sur = TestUsageRecord.createTestServiceUsageRecord();
|
|
|
|
|
sur.setServiceClass(serviceClass);
|
|
|
|
|
sur.setServiceName(serviceName);
|
|
|
|
|
sur.setCalledMethod(calledMethod);
|
|
|
|
|
sur.validate();
|
|
|
|
|
//logger.trace("Should not be aggregated ServiceUsageRecord {}", sur);
|
|
|
|
|
for(AggregatedServiceUsageRecord asur : aggregatedMap.values()) {
|
|
|
|
|
try {
|
|
|
|
|
asur.aggregate(sur);
|
|
|
|
|
logger.error("The record {} (line {}) has been aggregated and it should NOT", sur, lineCounter);
|
|
|
|
|
throw new Exception("The record has been aggregated and it should NOT");
|
|
|
|
|
} catch(NotAggregatableRecordsExceptions e) {
|
|
|
|
|
//logger.trace("{} is not aggragable as expected", sur);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
++lineCounter;
|
|
|
|
|
}catch (Exception e) {
|
|
|
|
|
logger.error("line {}", lineCounter, e.getMessage());
|
|
|
|
|
throw e;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
@ -227,7 +237,7 @@ public class TestRules extends ContextTest {
|
|
|
|
|
public void testAllRuleInAdirectory() throws Exception {
|
|
|
|
|
allRules();
|
|
|
|
|
File rulesDirectory = getRulesDirectory();
|
|
|
|
|
File rulesDirFile = new File(rulesDirectory, "perform-service");
|
|
|
|
|
File rulesDirFile = new File(rulesDirectory, "Thredds");
|
|
|
|
|
|
|
|
|
|
FilenameFilter filenameFilter = new FilenameFilter() {
|
|
|
|
|
@Override
|
|
|
|
|