3

Blobstore APIを使用するコードをテストしようとしていますが、いくつかのファイルをblobstoreに取り込むために期待される方法が実際にはわかりません。以下は機能していません。

private BlobKey createBlob(String path) throws Exception {
    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile file = fileService.createNewBlobFile("foobar");
    FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
    OutputStream output = Channels.newOutputStream(writeChannel);

    // copy files, guava-style
    InputStream input = new FileInputStream(path);
    assertNotNull(input);
    ByteStreams.copy(input, output); 
    input.close();

    // just in case...
    output.flush();
    output.close();
    writeChannel.close();

    // U NO WORK!!!
    BlobKey blobKey = fileService.getBlobKey(file);
    assertNotNull(blobKey);
    return blobKey;
}

私の設定:

new LocalServiceTestHelper(
    new LocalBlobstoreServiceTestConfig()
        //.setNoStorage(true)
        .setBackingStoreLocation("war/WEB-INF/appengine-generated"),
    new LocalFileServiceTestConfig()
).setUp();

何か案は?

4

1 に答える 1

3

次のテストは正常に実行されました

public class TestBlobstore {
  private static final LocalServiceTestHelper helper = 
    new LocalServiceTestHelper(new LocalDatastoreServiceTestConfig(),
                               new LocalBlobstoreServiceTestConfig()
                              );

  public TestBlobstore() {
  }

  @Before
  public void setUp() {
    helper.setUp();
  }

  @Test
  public void testBlobstore() throws Exception {
    System.out.println(createBlob("test.txt"));
  }

  private BlobKey createBlob(String path) throws Exception {
    FileService fileService = FileServiceFactory.getFileService();
    AppEngineFile file = fileService.createNewBlobFile("foobar");
    FileWriteChannel writeChannel = fileService.openWriteChannel(file, true);
    OutputStream output = Channels.newOutputStream(writeChannel);

    // copy files, guava-style
    InputStream input = new FileInputStream(path);
    assertNotNull(input);
    ByteStreams.copy(input, output); 
    input.close();

    // just in case...
    output.flush();
    output.close();
    writeChannel.closeFinally();

    // U NO WORK!!!
    BlobKey blobKey = fileService.getBlobKey(file);
    assertNotNull(blobKey);
    return blobKey;
  }
}

2つの変更:

  • LocalFileServiceTestConfigの代わりにユーザーLocalBlobstoreServiceTestConfig
  • writeChannel.closeFinally(); writeChannel.close()の代わりに

この助けを願っています。

于 2012-09-12T04:48:03.357 に答える