From 2d383ff50ee6f43a21532fa9f31297616531c316 Mon Sep 17 00:00:00 2001 From: Willem Date: Fri, 13 May 2016 01:19:40 +0200 Subject: [PATCH] Fixed more exception throws and todo and tests --- .../net/forwardfire/tpquery/TPQFactory.java | 9 ++++---- .../config/builder/TPQConfigBuilder.java | 21 ++++++++++++------- .../config/TPQueryStoreConfigBuilderTest.java | 14 ++++--------- .../config/TPQueryStoreConfigTest.java | 2 +- 4 files changed, 22 insertions(+), 24 deletions(-) diff --git a/ff-tpquery-store/src/main/java/net/forwardfire/tpquery/TPQFactory.java b/ff-tpquery-store/src/main/java/net/forwardfire/tpquery/TPQFactory.java index a69c6a9..0c1cc54 100644 --- a/ff-tpquery-store/src/main/java/net/forwardfire/tpquery/TPQFactory.java +++ b/ff-tpquery-store/src/main/java/net/forwardfire/tpquery/TPQFactory.java @@ -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 { diff --git a/ff-tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQConfigBuilder.java b/ff-tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQConfigBuilder.java index 9921ffb..70bb527 100644 --- a/ff-tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQConfigBuilder.java +++ b/ff-tpquery-store/src/main/java/net/forwardfire/tpquery/config/builder/TPQConfigBuilder.java @@ -56,7 +56,6 @@ public class TPQConfigBuilder { * 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 resultBuilder) { Validate.notNull(storeConfig,"Can't build null config."); @@ -94,18 +93,21 @@ public class TPQConfigBuilder { return this; } - protected TPQConfigBuilder readQuerySet(InputStream input,String systemId) throws JAXBException { + protected TPQConfigBuilder readQuerySet(InputStream input,String systemId) { Validate.notNull(input, "Can't read null InputStream"); - return addQuerySet(systemId,xmlDriver.unmarshal(input)); + 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 readQuerySet(String resource) throws JAXBException { + public TPQConfigBuilder 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 { * Reads an query set. * @param file The file to read. * @return The builder. - * @throws JAXBException When marshall error. */ - public TPQConfigBuilder readQuerySet(File file) throws JAXBException, FileNotFoundException { + public TPQConfigBuilder readQuerySet(File file) { Validate.notNull(file, "Can't read null File"); - return readQuerySet(new FileInputStream(file),file.getAbsolutePath()); + try { + return readQuerySet(new FileInputStream(file),file.getAbsolutePath()); + } catch (FileNotFoundException e) { + throw new TPQConfigException(e); + } } /** diff --git a/ff-tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigBuilderTest.java b/ff-tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigBuilderTest.java index 6284979..e63330a 100644 --- a/ff-tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigBuilderTest.java +++ b/ff-tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigBuilderTest.java @@ -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() - .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()); + TPQFactory.createManagerBuilder() + .readQuerySet(new File("./src/test/resources/net/forwardfire/tpquery/test-query.not-found")) + .build(); } } diff --git a/ff-tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigTest.java b/ff-tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigTest.java index 843cdf8..38c8005 100644 --- a/ff-tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigTest.java +++ b/ff-tpquery-store/src/test/java/net/forwardfire/tpquery/config/TPQueryStoreConfigTest.java @@ -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()