/** * Method that will try to convert value of this node to a Java <b>int</b>. * Numbers are coerced using default Java rules; booleans convert to 0 (false) * and 1 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an int (including structured types * like Objects and Arrays), * default value of <b>0</b> will be returned; no exceptions are thrown. * * @since 1.9 (replaces <code>getValueAsInt</code>) */ public int asInt() { return asInt(0); }
/** * Method that will try to convert value of this node to a Java <b>int</b>. * Numbers are coerced using default Java rules; booleans convert to 0 (false) * and 1 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an int (including structured types * like Objects and Arrays), * default value of <b>0</b> will be returned; no exceptions are thrown. * * @since 1.6 * * @deprecated Since 1.9, use {@link #asInt} instead */ @Deprecated public int getValueAsInt() { return asInt(0); }
/** * Method that will try to convert value of this node to a Java <b>int</b>. * Numbers are coerced using default Java rules; booleans convert to 0 (false) * and 1 (true), and Strings are parsed using default Java language integer * parsing rules. *<p> * If representation can not be converted to an int (including structured types * like Objects and Arrays), * specified <b>defaultValue</b> will be returned; no exceptions are thrown. * * @since 1.6 * * @deprecated Since 1.9, use {@link #asInt} instead */ @Deprecated public int getValueAsInt(int defaultValue) { return asInt(defaultValue); }
@Override public int getInt(IntConfigs config) { JsonNode node = tree.get(fixName(config)); if ( node == null ) { return 0; } return node.asInt(); } };
@Test public void shouldWriteNestedMaps() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); JsonGenerator json = new JsonFactory( new Neo4jJsonCodec() ).createJsonGenerator( out ); JsonNode row = serialize( out, json, new RowWriter( ) ); MatcherAssert.assertThat( row.size(), equalTo( 1 ) ); JsonNode firstCell = row.get( 0 ); MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).size(), is( 2 ) ); MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).get( 0 ).asBoolean(), is( true ) ); MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).get( 1 ).get( "three" ).asInt(), is( 42 ) ); }
@Test public void shouldWriteNestedMaps() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); JsonGenerator json = new JsonFactory( new Neo4jJsonCodec() ).createJsonGenerator( out ); JsonNode rest = serialize( out, json, new RestRepresentationWriter( URI.create( "localhost" ) ) ); MatcherAssert.assertThat( rest.size(), equalTo( 1 ) ); JsonNode firstCell = rest.get( 0 ); MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).size(), is( 2 ) ); MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).get( 0 ).asBoolean(), is( true ) ); MatcherAssert.assertThat( firstCell.get( "one" ).get( "two" ).get( 1 ).get( "three" ).asInt(), is( 42 ) ); }
@Test public void shouldSerializeMapsCorrectlyInRowsFormat() throws Exception { Response response = http.POST( "db/data/transaction/commit", quotedJson( "{ 'statements': [ { 'statement': 'RETURN {one:{two:[true, {three: 42}]}}' } ] }" ) ); // then assertThat( response.status(), equalTo( 200 ) ); JsonNode data = response.get( "results" ).get( 0 ); JsonNode row = data.get( "data" ).get( 0 ).get( "row" ); assertThat( row.size(), equalTo( 1 ) ); JsonNode firstCell = row.get( 0 ); assertThat( firstCell.get( "one" ).get( "two" ).size(), is( 2 ) ); assertThat( firstCell.get( "one" ).get( "two" ).get( 0 ).asBoolean(), is( true ) ); assertThat( firstCell.get( "one" ).get( "two" ).get( 1 ).get( "three" ).asInt(), is( 42 ) ); assertThat( response.get( "errors" ).size(), equalTo( 0 ) ); }
@Test public void shouldHandleMapParametersCorrectly() throws Exception { Response response = http.POST( "db/data/transaction/commit", quotedJson("{ 'statements': [ { 'statement': " + "'WITH {map} AS map RETURN map[0]', 'parameters':{'map':[{'index':0,'name':'a'},{'index':1,'name':'b'}]} } ] }")); // then assertThat( response.status(), equalTo( 200 ) ); JsonNode data = response.get( "results" ).get( 0 ); JsonNode row = data.get( "data" ).get( 0 ).get( "row" ); assertThat( row.size(), equalTo( 1 ) ); assertThat( row.get(0).get("index").asInt(), equalTo( 0 ) ); assertThat( row.get(0).get("name").asText(), equalTo( "a" ) ); assertThat( response.get( "errors" ).size(), equalTo( 0 ) ); }
@Test public void shouldSerializeMapsCorrectlyInRestFormat() throws Exception { Response response = http.POST( "db/data/transaction/commit", quotedJson( "{ 'statements': [ { 'statement': " + "'RETURN {one:{two:[true, {three: " + "42}]}}', " + "'resultDataContents':['rest'] } ] " + "}" ) ); // then assertThat( response.status(), equalTo( 200 ) ); JsonNode data = response.get( "results" ).get( 0 ); JsonNode rest = data.get( "data" ).get( 0 ).get( "rest" ); assertThat( rest.size(), equalTo( 1 ) ); JsonNode firstCell = rest.get( 0 ); assertThat( firstCell.get( "one" ).get( "two" ).size(), is( 2 ) ); assertThat( firstCell.get( "one" ).get( "two" ).get( 0 ).asBoolean(), is( true ) ); assertThat( firstCell.get( "one" ).get( "two" ).get( 1 ).get( "three" ).asInt(), is( 42 ) ); assertThat( response.get( "errors" ).size(), equalTo( 0 ) ); }
} else if (node.isNumber()) { if (node.isInt()) { return node.asInt(); } else if (node.isLong()) { return node.asLong();
@Test public void shouldLaunchWithDeclaredProcedures() throws Exception { // When try ( ServerControls server = createServer( MyProcedures.class ).newServer() ) { // Then HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(), quotedJson( "{ 'statements': [ { 'statement': 'CALL org.neo4j.harness.myProc' } ] }" ) ); JsonNode result = response.get( "results" ).get( 0 ); assertEquals( "someNumber", result.get( "columns" ).get( 0 ).asText() ); assertEquals( 1337, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asInt() ); assertEquals( "[]", response.get( "errors" ).toString() ); } }
@Test public void shouldLaunchWithDeclaredFunctions() throws Exception { // When try ( ServerControls server = createServer( MyFunctions.class ).newServer() ) { // Then HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(), quotedJson( "{ 'statements': [ { 'statement': 'RETURN org.neo4j.harness.myFunc() AS someNumber' } ] " + "}" ) ); JsonNode result = response.get( "results" ).get( 0 ); assertEquals( "someNumber", result.get( "columns" ).get( 0 ).asText() ); assertEquals( 1337, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asInt() ); assertEquals( "[]", response.get( "errors" ).toString() ); } }
@Test public void shouldLaunchWithDeclaredFunctions() throws Exception { // When Class<MyFunctions> functionClass = MyFunctions.class; try ( ServerControls server = createServer( functionClass ).newServer() ) { // Then HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(), quotedJson( "{ 'statements': [ { 'statement': 'RETURN org.neo4j.harness.myFunc() AS someNumber' } ] " + "}" ) ); JsonNode result = response.get( "results" ).get( 0 ); assertEquals( "someNumber", result.get( "columns" ).get( 0 ).asText() ); assertEquals( 1337, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asInt() ); assertEquals( "[]", response.get( "errors" ).toString() ); } }
scale = fileSchema.getJsonProp(AvroSerDe.AVRO_PROP_SCALE).asInt(); } catch(Exception ex) { throw new AvroSerdeException("Failed to obtain scale value from file schema: " + fileSchema, ex);
int code = value.get("state").asInt(); String description = value.get("description").getTextValue(); return new ServerStatus(spec.getHostname(), code, description, value.get("isLeader").getBooleanValue());
assertTrue(jsonTree.isObject()); assertEquals("test_rp_2", jsonTree.get("name").asText()); assertEquals(10, jsonTree.get("parallelism").asInt()); assertEquals("def", jsonTree.get("defaultPool").asText()); assertTrue(jsonTree.get("pools").isArray()); assertEquals("pool2", pool2.get("name").asText()); assertEquals("fcfs", pool2.get("schedulingPolicy").asText()); assertEquals(7, pool2.get("parallelism").asInt()); assertEquals(0.7, pool2.get("allocFraction").asDouble(), 0.00001); assertTrue(pool2.get("triggers").isArray()); assertEquals("pool1", pool1.get("name").asText()); assertEquals("fair", pool1.get("schedulingPolicy").asText()); assertEquals(3, pool1.get("parallelism").asInt()); assertEquals(0.3, pool1.get("allocFraction").asDouble(), 0.00001); assertTrue(pool1.get("triggers").isArray());
assertEquals( "child", child.get( "operatorType" ).getTextValue() ); identifiers.add( identifiersOf( child ) ); childIds.add( child.get( "id" ).asInt() );
@Documented( "Get the degree of a node\n" + "\n" + "Return the total number of relationships associated with a node." ) @Test @GraphDescription.Graph( {"Root knows Mattias", "Root knows Johan"} ) public void get_degree() throws JsonParseException { Map<String,Node> nodes = data.get(); String nodeUri = getNodeUri( nodes.get( "Root" ) ); // Document RESTRequestGenerator.ResponseEntity response = gen.get() .expectedStatus( 200 ) .get( nodeUri + "/degree/all" ); // Then assertEquals( 2, JsonHelper.jsonNode( response.response().getEntity() ).asInt() ); }
@Documented( "Get the degree of a node by direction\n" + "\n" + "Return the number of relationships of a particular direction for a node.\n" + "Specify `all`, `in` or `out`." ) @Test @GraphDescription.Graph( {"Root knows Mattias", "Root knows Johan"} ) public void get_degree_by_direction() throws JsonParseException { Map<String,Node> nodes = data.get(); String nodeUri = getNodeUri( nodes.get( "Root" ) ); // Document RESTRequestGenerator.ResponseEntity response = gen.get() .expectedStatus( 200 ) .get( nodeUri + "/degree/out" ); // Then assertEquals( 2, JsonHelper.jsonNode( response.response().getEntity() ).asInt() ); }
@Documented( "Get the degree of a node by direction and types\n" + "\n" + "If you are only interested in the degree of a particular relationship type, or a set of " + "relationship types, you specify relationship types after the direction.\n" + "You can combine multiple relationship types by using the `&` character." ) @Test @GraphDescription.Graph( {"Root KNOWS Mattias", "Root KNOWS Johan", "Root LIKES Cookie"} ) public void get_degree_by_direction_and_type() throws JsonParseException { Map<String,Node> nodes = data.get(); String nodeUri = getNodeUri( nodes.get( "Root" ) ); // Document RESTRequestGenerator.ResponseEntity response = gen.get() .expectedStatus( 200 ) .get( nodeUri + "/degree/out/KNOWS&LIKES" ); // Then assertEquals( 3, JsonHelper.jsonNode( response.response().getEntity() ).asInt() ); } }