org.codehaus.jackson.JsonNode.asText()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(174)

本文整理了Java中org.codehaus.jackson.JsonNode.asText()方法的一些代码示例,展示了JsonNode.asText()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JsonNode.asText()方法的具体详情如下:
包路径:org.codehaus.jackson.JsonNode
类名称:JsonNode
方法名:asText

JsonNode.asText介绍

[英]Method that will return valid String representation of the container value, if the node is a value node (method #isValueNode returns true), otherwise empty String.
[中]方法,如果该节点是值节点(方法#isValueNode返回true),则返回容器值的有效字符串表示形式,否则返回空字符串。

代码示例

代码示例来源:origin: neo4j/neo4j

private Set<String> identifiersOf( JsonNode root )
{
  Set<String> parentIds = new HashSet<>();
  for ( JsonNode id : root.get( "identifiers" ) )
  {
    parentIds.add( id.asText() );
  }
  return parentIds;
}

代码示例来源:origin: neo4j/neo4j

private JsonNode findNamedBean( JsonNode beans, String beanName )
{
  for ( JsonNode bean : beans )
  {
    JsonNode name = bean.get( "name" );
    if ( name != null && name.asText().endsWith( ",name=" + beanName ) )
    {
      return bean;
    }
  }
  throw new NoSuchElementException();
}

代码示例来源:origin: neo4j/neo4j

private void assertPath( JsonNode jsonURIString, String path, String hostname, final String scheme )
{
  assertTrue( "Expected a uri matching '" + scheme + "://" + hostname + ":\\d+/db/data" + path + "', " +
        "but got '" + jsonURIString.asText() + "'.",
      jsonURIString.asText().matches( scheme + "://" + hostname + ":\\d+/db/data" + path ) );
}

代码示例来源:origin: neo4j/neo4j

public String stringFromContent( String key ) throws JsonParseException
{
  return get(key).asText();
}

代码示例来源:origin: neo4j/neo4j

private void assertTemporalEquals( JsonNode data, String value, String type )
{
  JsonNode row = getSingle( data, "row" );
  assertThat( row.asText(), equalTo( value ) );
  JsonNode meta = getSingle( data, "meta" );
  assertEquals( type, meta.get( "type" ).asText() );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldIncludeCause() throws Exception
{
  // Given
  ExceptionRepresentation rep = new ExceptionRepresentation(
      new RuntimeException( "Hoho", new RuntimeException( "Haha", new RuntimeException( "HAHA!" ) ) ) );
  // When
  JsonNode out = serialize( rep );
  // Then
  assertThat( out.get("cause").get("message").asText(), is( "Haha" ) );
  assertThat( out.get( "cause" ).get("cause").get("message").asText(), is( "HAHA!") );
}

代码示例来源:origin: neo4j/neo4j

private static void assertCrsEqual( CoordinateReferenceSystem crs, JsonNode element )
{
  assertEquals( crs.getName(), element.get( "crs" ).get( "name" ).asText() );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldRenderErrorsWithNeo4jStatusCode() throws Exception
{
  // Given
  ExceptionRepresentation rep = new ExceptionRepresentation( new KernelException( UnknownError, "Hello" )
  {
  } );
  // When
  JsonNode out = serialize( rep );
  // Then
  assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError"));
  assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello"));
}

代码示例来源:origin: neo4j/neo4j

private static void assertGeometryTypeEqual( GeometryType expected, JsonNode element )
{
  assertEquals( expected.getName(), element.get( "type" ).asText() );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldReturnReadOnlyStatusWhenCreatingNodes() throws Exception
{
  // Given
  HTTP.Response response = http.POST( "db/data/transaction/commit",
      quotedJson( "{ 'statements': [ { 'statement': 'CREATE (node)' } ] }" ) );
  // Then
  JsonNode error = response.get( "errors" ).get( 0 );
  String code = error.get( "code" ).asText();
  String message = error.get( "message" ).asText();
  assertEquals( "Neo.ClientError.General.ForbiddenOnReadOnlyDatabase", code );
  assertThat( message, containsString( "This is a read only Neo4j instance" ) );
}

代码示例来源:origin: neo4j/neo4j

private static void assertTypeEqual( String expectedType, HTTP.Response response ) throws JsonParseException
{
  JsonNode data = response.get( "results" ).get( 0 ).get( "data" );
  JsonNode meta = data.get( 0 ).get( "meta" );
  assertEquals( 1, meta.size() );
  assertEquals( expectedType, meta.get( 0 ).get( "type" ).asText() );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldOnlyGetNodeTypeInMetaAsNodeProperties() throws Throwable
{
  HTTP.Response response = runQuery(
      "CREATE (account {name: \\\"zhen\\\", creationTime: localdatetime({year: 1984, month: 10, day: 21, hour: 12, minute: 34})}) RETURN account" );
  assertEquals( 200, response.status() );
  assertNoErrors( response );
  JsonNode data = getSingleData( response );
  JsonNode row = getSingle( data, "row" );
  assertThat( row.get( "creationTime" ).asText(), equalTo( "1984-10-21T12:34" ) );
  assertThat( row.get( "name" ).asText(), equalTo( "zhen" ) );
  JsonNode meta = getSingle( data, "meta" );
  assertThat( meta.get( "type" ).asText(), equalTo( "node" ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldReturnReadOnlyStatusWhenCreatingNodesWhichTransitivelyCreateTokens() throws Exception
{
  // Given
  // When
  HTTP.Response response = http.POST( "db/data/transaction/commit",
      quotedJson( "{ 'statements': [ { 'statement': 'CREATE (node:Node)' } ] }" ) );
  // Then
  JsonNode error = response.get( "errors" ).get( 0 );
  String code = error.get( "code" ).asText();
  String message = error.get( "message" ).asText();
  assertEquals( "Neo.ClientError.General.ForbiddenOnReadOnlyDatabase", code );
  assertThat( message, containsString( "This is a read only Neo4j instance" ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldExcludeLegacyFormatIfAsked() throws Exception
{
  // Given
  ExceptionRepresentation rep = new ExceptionRepresentation( new KernelException( UnknownError, "Hello" )
  {
  }, /*legacy*/false );
  // When
  JsonNode out = serialize( rep );
  // Then
  assertThat(out.get("errors").get(0).get("code").asText(), equalTo("Neo.DatabaseError.General.UnknownError"));
  assertThat(out.get("errors").get(0).get("message").asText(), equalTo("Hello"));
  assertThat(out.has( "message" ), equalTo(false));
}

代码示例来源:origin: neo4j/neo4j

private void assertQueryGetsValue( ServerControls server, String query, long value ) throws Throwable
{
  HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(),
      quotedJson( "{ 'statements': [ { 'statement': '" + query + "' } ] }" ) );
  assertEquals( "[]", response.get( "errors" ).toString() );
  JsonNode result = response.get( "results" ).get( 0 );
  assertEquals( "value", result.get( "columns" ).get( 0 ).asText() );
  assertEquals( value, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asLong() );
}

代码示例来源:origin: neo4j/neo4j

private void assertQueryGetsValue( ServerControls server, String query, long value ) throws Throwable
{
  HTTP.Response response = HTTP.POST( server.httpURI().resolve( "db/data/transaction/commit" ).toString(),
      quotedJson( "{ 'statements': [ { 'statement': '" + query + "' } ] }" ) );
  assertEquals( "[]", response.get( "errors" ).toString() );
  JsonNode result = response.get( "results" ).get( 0 );
  assertEquals( "value", result.get( "columns" ).get( 0 ).asText() );
  assertEquals( value, result.get( "data" ).get( 0 ).get( "row" ).get( 0 ).asLong() );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldSayMalformedHeaderIfMalformedAuthorization() throws Exception
{
  // Given
  startServerWithConfiguredUser();
  // When
  HTTP.Response response = HTTP.withHeaders( HttpHeaders.AUTHORIZATION, "This makes no sense" ).GET( dataURL() );
  // Then
  assertThat( response.status(), equalTo( 400 ) );
  assertThat( response.get( "errors" ).get( 0 ).get( "code" ).asText(), equalTo( "Neo.ClientError.Request.InvalidFormat" ) );
  assertThat( response.get( "errors" ).get( 0 ).get( "message" ).asText(), equalTo( "Invalid authentication header." ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shouldGetHelpfulErrorOnProcedureThrowsException() 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.procThatThrows' } ] }" ) );
    String error = response.get( "errors" ).get( 0 ).get( "message" ).asText();
    assertEquals( "Failed to invoke procedure `org.neo4j.harness.procThatThrows`: " +
        "Caused by: java.lang.RuntimeException: This is an exception", error );
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
  public void shouldReportCommunityEdition() throws Exception
  {
    // Given
    String releaseVersion = server.getDatabase().getGraph().getDependencyResolver().resolveDependency( KernelData
        .class ).version().getReleaseVersion();
    // When
    HTTP.Response res =
        HTTP.GET( functionalTestHelper.managementUri() + "/" + VersionAndEditionService.SERVER_PATH );
    // Then
    assertEquals( 200, res.status() );
    assertThat( res.get( "edition" ).asText(), equalTo( "community" ) );
    assertThat( res.get( "version" ).asText(), equalTo( releaseVersion ) );
  }
}

代码示例来源:origin: neo4j/neo4j

@Test
public void txEndpointShouldReplyWithHttpsWhenItReturnsURLs() throws Exception
{
  startServer();
  String baseUri = server.baseUri().toString();
  HTTP.Response response = POST( baseUri + "db/data/transaction", quotedJson( "{'statements':[]}" ) );
  assertThat( response.location(), startsWith( baseUri ) );
  assertThat( response.get( "commit" ).asText(), startsWith( baseUri ) );
}

相关文章