org.neo4j.io.fs.FileUtils.writeToFile()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(194)

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

FileUtils.writeToFile介绍

暂无

代码示例

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

@Test
public void shouldAcceptFolderWithCypFilesAsFixtures() throws Exception
{
  // Given two files in the root folder
  File targetFolder = testDir.directory();
  FileUtils.writeToFile( new File( targetFolder, "fixture1.cyp" ), "CREATE (u:User)\n" + "CREATE (a:OtherUser)",
      false );
  FileUtils.writeToFile( new File( targetFolder, "fixture2.cyp" ), "CREATE (u:User)\n" + "CREATE (a:OtherUser)",
      false );
  // And given one file in a sub directory
  File subDir = new File( targetFolder, "subdirectory" );
  subDir.mkdir();
  FileUtils.writeToFile( new File( subDir, "subDirFixture.cyp" ), "CREATE (u:User)\n" + "CREATE (a:OtherUser)",
      false );
  // When
  try ( ServerControls server = getServerBuilder( targetFolder ).withFixture( targetFolder ).newServer() )
  {
    // Then
    HTTP.Response response = HTTP.POST( server.httpURI().toString() + "db/data/transaction/commit",
        quotedJson( "{'statements':[{'statement':'MATCH (n:User) RETURN n'}]}" ) );
    assertThat( response.toString(), response.get( "results" ).get(0).get("data").size(), equalTo(3) );
  }
}

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

@Test
public void shouldHandleFixturesWithSyntaxErrorsGracefully() throws Exception
{
  // Given two files in the root folder
  File targetFolder = testDir.directory();
  FileUtils.writeToFile( new File( targetFolder, "fixture1.cyp" ), "this is not a valid cypher statement", false );
  // When
  try ( ServerControls ignore = getServerBuilder( targetFolder )
      .withFixture( targetFolder ).newServer() )
  {
    fail("Should have thrown exception");
  }
  catch ( RuntimeException e )
  {
    assertThat( e.getMessage(), equalTo(
        "Invalid input 't': expected <init> (line 1, column 1 (offset: 0))" + lineSeparator() +
        "\"this is not a valid cypher statement\"" + lineSeparator() + " ^" ) );
  }
}

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

@Test
public void shouldIgnoreEmptyFixtureFiles() throws Exception
{
  // Given two files in the root folder
  File targetFolder = testDir.directory();
  FileUtils.writeToFile( new File( targetFolder, "fixture1.cyp" ), "CREATE (u:User)\n" + "CREATE (a:OtherUser)",
      false );
  FileUtils.writeToFile( new File( targetFolder, "fixture2.cyp" ), "", false );
  // When
  try ( ServerControls server = getServerBuilder( targetFolder )
      .withFixture( targetFolder ).newServer() )
  {
    // Then
    HTTP.Response response = HTTP.POST( server.httpURI().toString() + "db/data/transaction/commit",
        quotedJson( "{'statements':[{'statement':'MATCH (n:User) RETURN n'}]}" ) );
    assertThat( response.get( "results" ).get(0).get("data").size(), equalTo(1));
  }
}

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

@Test
public void shouldFailIfSupplyingBothFileArgumentAndAnyOtherArgument() throws Exception
{
  // given
  List<String> nodeIds = nodeIds();
  Configuration config = Configuration.COMMAS;
  File argumentFile = file( "args" );
  String arguments = format(
      "--into %s%n" +
      "--nodes %s --relationships %s",
      dbRule.getDatabaseDirAbsolutePath(),
      nodeData( true, config, nodeIds, TRUE ).getAbsolutePath(),
      relationshipData( true, config, nodeIds, TRUE, true ).getAbsolutePath() );
  writeToFile( argumentFile, arguments, false );
  try
  {
    // when
    importTool( "-f", argumentFile.getAbsolutePath(), "--into", dbRule.getDatabaseDirAbsolutePath() );
    fail( "Should have failed" );
  }
  catch ( IllegalArgumentException e )
  {
    // then good
    assertThat( e.getMessage(), containsString( "in addition to" ) );
    assertThat( e.getMessage(), containsString( ImportTool.Options.FILE.argument() ) );
  }
}

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

@Test
public void shouldAccepSingleCypherFileAsFixture() throws Exception
{
  // Given
  File targetFolder = testDir.directory();
  File fixture = new File( targetFolder, "fixture.cyp" );
  FileUtils.writeToFile(fixture,
      "CREATE (u:User)" +
      "CREATE (a:OtherUser)", false);
  // When
  try ( ServerControls server = getServerBuilder( targetFolder ).withFixture( fixture ).newServer() )
  {
    // Then
    HTTP.Response response = HTTP.POST( server.httpURI().toString() + "db/data/transaction/commit",
        quotedJson( "{'statements':[{'statement':'MATCH (n:User) RETURN n'}]}" ) );
    assertThat( response.status(), equalTo( 200 ) );
    assertThat(response.get( "results" ).get(0).get("data").size(), equalTo(1));
  }
}

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

@Test
public void shouldHandleMultipleFixtures() throws Exception
{
  // Given two files in the root folder
  File targetFolder = testDir.directory();
  File fixture1 = new File( targetFolder, "fixture1.cyp" );
  FileUtils.writeToFile( fixture1,
      "CREATE (u:User)\n" +
      "CREATE (a:OtherUser)", false);
  File fixture2 = new File( targetFolder, "fixture2.cyp" );
  FileUtils.writeToFile( fixture2,
      "CREATE (u:User)\n" +
      "CREATE (a:OtherUser)", false);
  // When
  try ( ServerControls server = getServerBuilder( targetFolder )
      .withFixture( fixture1 )
      .withFixture( fixture2 )
      .newServer() )
  {
    // Then
    HTTP.Response response = HTTP.POST( server.httpURI().toString() + "db/data/transaction/commit",
        quotedJson( "{'statements':[{'statement':'MATCH (n:User) RETURN n'}]}" ) );
    assertThat( response.get( "results" ).get(0).get("data").size(), equalTo(2));
  }
}

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

@Test
public void shouldSupplyArgumentsAsFile() throws Exception
{
  // given
  List<String> nodeIds = nodeIds();
  Configuration config = Configuration.COMMAS;
  File argumentFile = file( "args" );
  String nodesEscapedSpaces = escapePath( nodeData( true, config, nodeIds, TRUE ).getAbsolutePath() );
  String relationshipsEscapedSpaced = escapePath( relationshipData( true, config, nodeIds, TRUE, true ).getAbsolutePath() );
  String arguments = format(
      "--into %s%n" +
      "--nodes %s --relationships %s",
      escapePath( dbRule.getDatabaseDirAbsolutePath() ), nodesEscapedSpaces, relationshipsEscapedSpaced );
  writeToFile( argumentFile, arguments, false );
  // when
  importTool( "-f", argumentFile.getAbsolutePath() );
  // then
  verifyData();
}

相关文章