78 lines
2.3 KiB
Java
78 lines
2.3 KiB
Java
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[]{
|
|
"AuthorizationService-generate",
|
|
"AuthorizationService-retrieve",
|
|
"AuthorizationService-scopes",
|
|
"Catalogue-WS-licenses",
|
|
"Catalogue-WS-organizations",
|
|
"Catalogue-WS-UNKNOWN",
|
|
"CkanConnector-connect",
|
|
"CkanConnector-disconnect",
|
|
"FullTextIndexNode-delete",
|
|
"FullTextIndexNode-dropCollection",
|
|
"FullTextIndexNode-insert",
|
|
"FullTextIndexNode-listCollections",
|
|
"FullTextIndexNode-search",
|
|
"GeoNetwork-login",
|
|
"TagMe-tag"
|
|
};
|
|
|
|
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();
|
|
}
|
|
|
|
}
|
|
} catch(Exception e) {
|
|
throw e;
|
|
}
|
|
}
|
|
|
|
@Test
|
|
public void testSingleRule() throws Exception {
|
|
testRule("Catalogue-WS-licenses");
|
|
}
|
|
|
|
}
|