Fixed more exception throws and todo and tests

This commit is contained in:
Willem 2016-05-13 01:19:40 +02:00
parent 8aa55ddbff
commit 2d383ff50e
4 changed files with 22 additions and 24 deletions

View file

@ -32,8 +32,6 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import javax.script.Compilable;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.xml.bind.JAXBException;
@ -190,7 +188,7 @@ public final class TPQFactory {
public void initializeConfig(TPQConfig config) {
config.addStatementParameter(new TPQStatementParameterValue(VALUE));
config.addStatementParameter(new TPQStatementParameterList(LIST));
config.addStatementParameter(new TPQStatementParameterRaw(RAW,"")); // TODO: write best-practice-example and remove raw* from default ?
config.addStatementParameter(new TPQStatementParameterRaw(RAW,""));
config.addStatementParameter(new TPQStatementParameterRaw(RAW_NULL,"null"));
}
}
@ -494,8 +492,9 @@ public final class TPQFactory {
private TPQueryStoreScriptEngine createScriptEngine() {
ScriptEngine engine = new ScriptEngineManager().getEngineByMimeType(DEFAULT_SCRIPT_ENGINE_MINE_TYPE);
Validate.isInstanceOf(Compilable.class, engine, "ScriptEngine does not implement Compilable interface.");// TODO: use TPQueryStoreScriptEngine interface list
Validate.isInstanceOf(Invocable.class, engine, "ScriptEngine does not implement Invocable interface.");
for (Class<?> engineFeature:TPQueryStoreScriptEngine.class.getInterfaces()) {
Validate.isInstanceOf(engineFeature, engine, "ScriptEngine does not implement "+engineFeature.getName()+" interface.");
}
return (TPQueryStoreScriptEngine) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[]{TPQueryStoreScriptEngine.class}, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

View file

@ -56,7 +56,6 @@ public class TPQConfigBuilder<T> {
* Creates a config builder.
* @param storeConfig The config to build.
* @param resultBuilder the result of this builder.
* @throws JAXBException If the jaxb marshaller throws an error.
*/
public TPQConfigBuilder(TPQConfig storeConfig,Supplier<T> resultBuilder) {
Validate.notNull(storeConfig,"Can't build null config.");
@ -94,18 +93,21 @@ public class TPQConfigBuilder<T> {
return this;
}
protected TPQConfigBuilder<T> readQuerySet(InputStream input,String systemId) throws JAXBException {
protected TPQConfigBuilder<T> readQuerySet(InputStream input,String systemId) {
Validate.notNull(input, "Can't read null InputStream");
try {
return addQuerySet(systemId,xmlDriver.unmarshal(input));
} catch (JAXBException e) {
throw new TPQConfigException(e);
}
}
/**
* Reads an query set.
* @param resource The resource to read.
* @return The builder.
* @throws JAXBException When marshall error.
*/
public TPQConfigBuilder<T> readQuerySet(String resource) throws JAXBException {
public TPQConfigBuilder<T> readQuerySet(String resource) {
Validate.notNull(resource, "Can't read null resource");
return readQuerySet(getClass().getClassLoader().getResourceAsStream(resource),resource);
}
@ -114,11 +116,14 @@ public class TPQConfigBuilder<T> {
* Reads an query set.
* @param file The file to read.
* @return The builder.
* @throws JAXBException When marshall error.
*/
public TPQConfigBuilder<T> readQuerySet(File file) throws JAXBException, FileNotFoundException {
public TPQConfigBuilder<T> readQuerySet(File file) {
Validate.notNull(file, "Can't read null File");
try {
return readQuerySet(new FileInputStream(file),file.getAbsolutePath());
} catch (FileNotFoundException e) {
throw new TPQConfigException(e);
}
}
/**

View file

@ -6,8 +6,6 @@ import java.io.File;
import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.JAXBException;
import org.junit.Test;
import net.forwardfire.tpquery.TPQManager;
@ -130,14 +128,10 @@ public class TPQueryStoreConfigBuilderTest {
assertNotNull(q.getName());
}
@Test(expected=JAXBException.class)
@Test(expected=TPQConfigException.class)
public void testReadQuerySetFileNotFound() throws Exception {
TPQManager store = TPQFactory
.createManagerBuilder()
TPQFactory.createManagerBuilder()
.readQuerySet(new File("./src/test/resources/net/forwardfire/tpquery/test-query.not-found"))
.build();
assertNotNull(store);
TPQExecutorStatement q = store.getQueryExecutorContext().prepareQuery("article.insert", null);
assertNotNull(q.getName());
}
}

View file

@ -204,7 +204,7 @@ public class TPQueryStoreConfigTest {
assertNotNull(q.getName());
}
@Test(expected=IllegalArgumentException.class)
@Test(expected=TPQConfigException.class)
public void testWrongClassParameterType() throws Exception {
TPQManager manager = TPQFactory
.createManagerBuilder()