Search in sources :

Example 1 with ParamValue

use of org.neo4j.shell.state.ParamValue in project neo4j by neo4j.

the class ParamsTest method runCommandWithArg.

@Test
public void runCommandWithArg() throws CommandException {
    // given
    vars.put("var", new ParamValue(String.valueOf(9), 9));
    vars.put("param", new ParamValue(String.valueOf(9999), 9999));
    // when
    cmd.execute("var");
    // then
    verify(logger).printOut(":param var => 9");
    verifyNoMoreInteractions(logger);
}
Also used : ParamValue(org.neo4j.shell.state.ParamValue) Test(org.junit.Test)

Example 2 with ParamValue

use of org.neo4j.shell.state.ParamValue in project neo4j by neo4j.

the class ParamsTest method runCommandWithUnknownArg.

@Test
public void runCommandWithUnknownArg() throws CommandException {
    // then
    thrown.expect(CommandException.class);
    thrown.expectMessage(containsString("Unknown parameter: bob"));
    // given
    vars.put("var", new ParamValue(String.valueOf(9), 9));
    // when
    cmd.execute("bob");
}
Also used : ParamValue(org.neo4j.shell.state.ParamValue) Test(org.junit.Test)

Example 3 with ParamValue

use of org.neo4j.shell.state.ParamValue in project neo4j by neo4j.

the class ShellParameterMap method setParameter.

@Override
public Object setParameter(@Nonnull String name, @Nonnull String valueString) throws ParameterException {
    String parameterName = CypherVariablesFormatter.unescapedCypherVariable(name);
    try {
        Object value = new Cypher(interpreter, ParameterException.FACTORY, new CypherCharStream(valueString)).Expression();
        queryParams.put(parameterName, new ParamValue(valueString, toJavaObject(value)));
        return value;
    } catch (ParseException | UnsupportedOperationException e) {
        try {
            Object value = evaluator.evaluate(valueString, Object.class);
            queryParams.put(parameterName, new ParamValue(valueString, toJavaObject(value)));
            return value;
        } catch (EvaluationException e1) {
            throw new ParameterException(e1.getMessage());
        }
    }
}
Also used : Cypher(org.neo4j.cypher.internal.parser.javacc.Cypher) ParamValue(org.neo4j.shell.state.ParamValue) CypherCharStream(org.neo4j.cypher.internal.parser.javacc.CypherCharStream) ParameterException(org.neo4j.shell.exception.ParameterException) ParseException(org.neo4j.cypher.internal.parser.javacc.ParseException) EvaluationException(org.neo4j.cypher.internal.evaluator.EvaluationException)

Example 4 with ParamValue

use of org.neo4j.shell.state.ParamValue in project neo4j by neo4j.

the class ShellParameterMapTest method getUserInput.

@Test
public void getUserInput() throws ParameterException {
    parameterMap.setParameter("`bob`", "99");
    assertEquals(new ParamValue("99", 99L), parameterMap.getAllAsUserInput().get("bob"));
}
Also used : ParamValue(org.neo4j.shell.state.ParamValue) Test(org.junit.Test)

Example 5 with ParamValue

use of org.neo4j.shell.state.ParamValue in project neo4j by neo4j.

the class ParamsTest method runCommandWithSpecialCharacters.

@Test
public void runCommandWithSpecialCharacters() throws CommandException {
    // given
    vars.put("var `", new ParamValue(String.valueOf(9), 9));
    vars.put("param", new ParamValue(String.valueOf(9999), 9999));
    // when
    cmd.execute("`var ```");
    // then
    verify(logger).printOut(":param `var ``` => 9");
    verifyNoMoreInteractions(logger);
}
Also used : ParamValue(org.neo4j.shell.state.ParamValue) Test(org.junit.Test)

Aggregations

ParamValue (org.neo4j.shell.state.ParamValue)9 Test (org.junit.Test)8 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 EvaluationException (org.neo4j.cypher.internal.evaluator.EvaluationException)1 Cypher (org.neo4j.cypher.internal.parser.javacc.Cypher)1 CypherCharStream (org.neo4j.cypher.internal.parser.javacc.CypherCharStream)1 ParseException (org.neo4j.cypher.internal.parser.javacc.ParseException)1 ParameterException (org.neo4j.shell.exception.ParameterException)1