2019-11-15 14:40:11 +01:00
|
|
|
package org.gcube.accounting.datamodel.validations.validators;
|
|
|
|
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileReader;
|
|
|
|
import java.io.InputStream;
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
import org.gcube.documentstore.records.DSMapper;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
public class TestRules {
|
|
|
|
|
|
|
|
private static final Logger logger = LoggerFactory.getLogger(TestRules.class);
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testAllRules() throws Exception {
|
|
|
|
|
|
|
|
String[] aggregationTests = new String[]{
|
2019-11-15 15:59:46 +01:00
|
|
|
"AuthorizationService-generate",
|
|
|
|
"AuthorizationService-retrieve",
|
|
|
|
"AuthorizationService-scopes",
|
|
|
|
"CkanConnector-connect",
|
|
|
|
"CkanConnector-disconnect",
|
|
|
|
"FullTextIndexNode-delete",
|
|
|
|
"FullTextIndexNode-dropCollection",
|
|
|
|
"FullTextIndexNode-insert",
|
|
|
|
"FullTextIndexNode-listCollections",
|
|
|
|
"FullTextIndexNode-search",
|
|
|
|
"GeoNetwork-login",
|
|
|
|
"TagMe-tag"
|
2019-11-15 14:40:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
for(String aggregationTest : aggregationTests) {
|
|
|
|
testRule(aggregationTest);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testRule(String rulePrefix) throws Exception {
|
|
|
|
ObjectMapper mapper = DSMapper.getObjectMapper();
|
|
|
|
InputStream regexInputStream = TestRules.class.getClassLoader().getResourceAsStream(rulePrefix + "-rule.json");
|
|
|
|
MatcherReplace matcherReplace = mapper.readValue(regexInputStream, MatcherReplace.class);
|
|
|
|
Replacer replacer = matcherReplace.getReplacer();
|
|
|
|
|
|
|
|
URL url = TestRules.class.getClassLoader().getResource(rulePrefix + "-values.csv");
|
|
|
|
File elaborationFile = new File(url.toURI());
|
|
|
|
try(BufferedReader br = new BufferedReader(new FileReader(elaborationFile))) {
|
|
|
|
for(String line; (line = br.readLine()) != null;) {
|
|
|
|
String[] splittedLine = line.split(",");
|
|
|
|
boolean matched = matcherReplace.check(splittedLine[0],splittedLine[1],splittedLine[2]);
|
|
|
|
if(matched) {
|
|
|
|
logger.info("{} -> {},{},{}", line, replacer.getServiceClass(), replacer.getServiceName(), replacer.getCalledMethod());
|
|
|
|
} else {
|
|
|
|
logger.error("{} does not match {}. This MUST not occur.", line, matcherReplace.getMultiMatcher().toString());
|
|
|
|
throw new Exception(line + " does not match "+ matcherReplace.getMultiMatcher().toString() + ". This MUST not occur.");
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch(Exception e) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testSingleRule() throws Exception {
|
2019-11-15 15:59:46 +01:00
|
|
|
testRule("FullTextIndexNode-listCollections");
|
2019-11-15 14:40:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|