Skip to content

Commit

Permalink
make tests work again
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaskrause committed Sep 11, 2015
1 parent db51d42 commit 258776e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 68 deletions.
3 changes: 0 additions & 3 deletions annis-service/src/test/java/annis/dao/TestSpringAnnisDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,8 @@
import javax.annotation.Resource;
import org.junit.Assert;
import org.springframework.dao.DataAccessException;
import org.springframework.test.web.ModelAndViewAssert;
import org.springframework.validation.BindingResultUtils;

@RunWith(SpringJUnit4ClassRunner.class)
// TODO: do not test context only for annopool
@ContextConfiguration(locations =
{
"file:src/main/distribution/conf/spring/Common.xml",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,114 +15,107 @@
*/
package annis.ql.parser;

import annis.AnnisXmlContextLoader;
import annis.exceptions.AnnisQLSemanticsException;
import annis.exceptions.AnnisQLSyntaxException;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static annis.test.TestHelper.springFiles;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
import org.junit.runner.RunWith;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import annis.test.SpringQueryExamples;
import annis.test.SpringSyntaxTreeExamples;
import annis.test.SyntaxTreeExample;
import java.util.LinkedList;
import org.junit.Ignore;
import javax.annotation.Resource;
import org.junit.Before;
import org.junit.Test;
import org.junit.experimental.theories.Theories;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestContextManager;

// see http://junit.sourceforge.net/doc/ReleaseNotes4.4.html
// and http://popper.tigris.org/tutorial.html
@RunWith(Theories.class)
public class TestAnnisParserExamples {

// where to find query and syntax tree examples
private static final String EXAMPLES = "annis/ql/parser/TestAnnisParser-examples.xml";
@ContextConfiguration(locations =
{
"file:src/main/distribution/conf/spring/Common.xml",
"file:src/main/distribution/conf/spring/Dao.xml",
"/annis/ql/parser/AnnisParser-context.xml"
}, loader = AnnisXmlContextLoader.class)
public class TestAnnisParserExamples
{

// where to find query and syntax tree examples
private static final String EXAMPLES = "annis/ql/parser/TestAnnisParser-examples.xml";

// access to AnnisParser
static ApplicationContext ctx;
private TestContextManager testContextManager;

// simple AnnisParser instance
// simple AnnisParser instance
@Resource(name = "annisParserAntlr")
private AnnisParserAntlr parserAntlr;

// load Spring application context once
@BeforeClass
public static void loadApplicationContext() {
final String[] ctxFiles =
springFiles(TestAnnisParserExamples.class, "AnnisParser-context.xml");
ctx = new ClassPathXmlApplicationContext(ctxFiles);
}

// setup a fresh parser
@Before
public void setup() {
parserAntlr = (AnnisParserAntlr) ctx.getBean("annisParserAntlr");
}


@Before
public void setUpContext() throws Exception
{
this.testContextManager = new TestContextManager(getClass());
this.testContextManager.prepareTestInstance(this);
}

///// Syntax-Tree tests

@Theory
@Theory
@Test
public void testSyntaxTrees(
@SpringSyntaxTreeExamples(exampleMap = "exampleSyntaxTrees", contextLocation=EXAMPLES)
SyntaxTreeExample example)
public void testSyntaxTrees(
@SpringSyntaxTreeExamples(exampleMap = "exampleSyntaxTrees", contextLocation = EXAMPLES) SyntaxTreeExample example)
{

QueryData data = parserAntlr.parse(example.getQuery(), new LinkedList<Long>());
assertThat(data, is(not(nullValue())));

String actual = data.toAQL().trim();

String provided = example.getSyntaxTree();

assertEquals("wrong parse result for: " + example.getQuery(),provided.trim(), actual.trim());
}


assertEquals("wrong parse result for: " + example.getQuery(), provided.trim(), actual.trim());
}

@Theory
@Test
public void testGoodQueriesAntLR(
@SpringQueryExamples(exampleList = "good", contextLocation=EXAMPLES)
String annisQuery)
public void testGoodQueriesAntLR(
@SpringQueryExamples(exampleList = "good", contextLocation = EXAMPLES) String annisQuery)
{

try
{
QueryData result = parserAntlr.parse(annisQuery,
QueryData result = parserAntlr.parse(annisQuery,
new LinkedList<Long>());
assertThat(result, is(not(nullValue())));
}
catch (Exception ex)
} catch (Exception ex)
{
ex.printStackTrace(System.err);
fail("good query throw exception: " + annisQuery);
}
}
@Theory
}

@Theory
@Test
public void testBadQueriesAntLR(
@SpringQueryExamples(exampleList = "bad", contextLocation=EXAMPLES)
String annisQuery) {
public void testBadQueriesAntLR(
@SpringQueryExamples(exampleList = "bad", contextLocation = EXAMPLES) String annisQuery)
{

try
{
parserAntlr.parse(annisQuery, new LinkedList<Long>());

fail("bad query passed as good: " + annisQuery);
}
catch (Exception ex)

fail("bad query passed as good: " + annisQuery);
} catch (AnnisQLSyntaxException | AnnisQLSemanticsException ex)
{
// ok
}

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package annis.ql.parser;

import annis.AnnisXmlContextLoader;
import annis.model.QueryNode;
import annis.model.Join;
import annis.sqlgen.model.Precedence;
Expand All @@ -35,8 +36,12 @@
* @author Thomas Krause <krauseto@hu-berlin.de>
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:annis/ql/parser/AnnisParser-context.xml",
"classpath:annis/AutowiredContext.xml"})
@ContextConfiguration(locations={
"file:src/main/distribution/conf/spring/Common.xml",
"file:src/main/distribution/conf/spring/Dao.xml",
"classpath:annis/ql/parser/AnnisParser-context.xml",
"classpath:annis/AutowiredContext.xml"},
loader = AnnisXmlContextLoader.class)
public class TransitivePrecedenceOptimizerTest
{
private boolean postProcessorExists = false;
Expand Down

0 comments on commit 258776e

Please sign in to comment.