Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolovison committed Mar 11, 2019
1 parent efb1911 commit 0335ce5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
11 changes: 7 additions & 4 deletions client/src/test/java/org/perfrepo/client/test/ClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public static Archive<?> createDeployment() {
war.delete(ArchivePaths.create("WEB-INF/classes/META-INF/persistence.xml"));
war.delete(ArchivePaths.create("WEB-INF/jboss-web.xml"));

war.add(new FileAsset(new File("target/test-classes/test-persistence.xml")), ArchivePaths.create("WEB-INF/classes/META-INF/persistence.xml"));
war.add(new FileAsset(new File("target/test-classes/test-jboss-web.xml")), ArchivePaths.create("WEB-INF/jboss-web.xml"));
war.add(new FileAsset(new File(ClientTest.class.getResource("/test-persistence.xml").getFile())), ArchivePaths.create("WEB-INF/classes/META-INF/persistence.xml"));
war.add(new FileAsset(new File(ClientTest.class.getResource("/test-jboss-web.xml").getFile())), ArchivePaths.create("WEB-INF/jboss-web.xml"));

return war;
}
Expand All @@ -82,8 +82,10 @@ public static void createClient() {

@AfterClass
public static void destroyClient() {
client.shutdown();
client = null;
if (client != null) {
client.shutdown();
client = null;
}
}

@org.junit.Test
Expand Down Expand Up @@ -180,6 +182,7 @@ public void testCreateInvalidMultivalueTestExecution() throws Exception {
client.deleteTest(testId);
}

@Ignore("https://github.com/PerfCake/PerfRepo/issues/95")
@org.junit.Test
public void testUpdateTestExecution() throws Exception {
Test test = createTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class ConditionCheckerImpl implements ConditionChecker {

private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm");

private static final ScriptEngine JAVA_SCRIPT_ENGINE = new ScriptEngineManager(null).getEngineByName("JavaScript");

@Inject
private TestExecutionDAO testExecutionDAO;

Expand Down Expand Up @@ -82,7 +84,7 @@ public class ConditionCheckerImpl implements ConditionChecker {
public void checkConditionSyntax(String condition, Metric metric) {
// creates dummy execution and triggers evaluation against it
// if we had a 'perfect' grammar, we would only need to call parseTree(condition);
// but ATM we need script engine to evaluate CONDITION and tell us if there were any errors
// but ATM we need script JAVA_SCRIPT_ENGINE to evaluate CONDITION and tell us if there were any errors
// e.g. current grammar cannot catch nonsenses such as: CONDITION x <!= 10
TestExecution testExecution;
TestExecutionBuilder builder = TestExecution.builder();
Expand Down Expand Up @@ -184,10 +186,9 @@ public boolean checkCondition(String condition, TestExecution currentResult, Met
* @return evaluated condition, true if it holds, false otherwise
*/
private boolean evaluate(String expression, Map<String, Object> variables) {
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
Object result;
try {
result = engine.eval(expression, new SimpleBindings(variables));
result = JAVA_SCRIPT_ENGINE.eval(expression, new SimpleBindings(variables));
} catch (ScriptException e) {
throw new IllegalArgumentException("Error occurred while evaluating the expression.", e);
}
Expand Down Expand Up @@ -485,12 +486,12 @@ private Double getValueFromMetric(TestExecution testExecution) {
private CommonTree parseTree(String string) {
//lexer splits input into tokens
ANTLRStringStream input = new ANTLRStringStream(string);
TokenStream tokens = new CommonTokenStream(new AlertingDSLLexer(input));
TokenStream tokens = new CommonTokenStream(new org.perfrepo.web.alerting.AlertingDSLLexer(input));

//parser generates abstract syntax tree
AlertingDSLParser parser = new AlertingDSLParser(tokens);
org.perfrepo.web.alerting.AlertingDSLParser parser = new org.perfrepo.web.alerting.AlertingDSLParser(tokens);

AlertingDSLParser.expression_return ret;
org.perfrepo.web.alerting.AlertingDSLParser.expression_return ret;
try {
ret = parser.expression();
} catch (RecognitionException ex) {
Expand Down
8 changes: 6 additions & 2 deletions web/src/test/java/org/perfrepo/test/TestServiceBeanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public class TestServiceBeanTest {

@Deployment
public static Archive<?> createDeployment() {

File testClassFolder = new File(TestServiceBeanTest.class.getResource("/.").getFile());
File testLibsFolder = new File(testClassFolder.getParentFile(), "test-libs");

WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war");
war.addPackages(true, Alert.class.getPackage());
war.addPackages(true, TestService.class.getPackage());
Expand All @@ -83,8 +87,8 @@ public static Archive<?> createDeployment() {
war.addPackage(MultiValue.class.getPackage());
war.addPackage(DAO.class.getPackage());
war.addPackages(true, Alert.class.getPackage());
war.addAsLibrary(new File("target/test-libs/antlr-runtime.jar"));
war.addAsLibrary(new File("target/test-libs/maven-artifact.jar"));
war.addAsLibrary(new File(testLibsFolder,"antlr-runtime.jar"));
war.addAsLibrary(new File(testLibsFolder, "maven-artifact.jar"));
war.addAsResource("test-persistence.xml", "META-INF/persistence.xml");
war.addAsResource("users.properties");
war.addAsResource("roles.properties");
Expand Down

0 comments on commit 0335ce5

Please sign in to comment.