@Test
  public void doFileCopyChunkResponseTest() throws IOException {
    short requestVersionToUse = FileCopyGetChunkResponse.CURRENT_VERSION;
    String fileName = "testFile";
    long fileSize = 12345L;
    ByteBuf byteBuf = Unpooled.buffer();
    byteBuf.writeBytes(fileName.getBytes());
    byteBuf.writeLong(fileSize);
    DataInputStream fileStream = new DataInputStream(new ByteBufferInputStream(byteBuf.nioBuffer()));

    FileCopyGetChunkResponse response = new FileCopyGetChunkResponse(requestVersionToUse, 111, "id1",
        ServerErrorCode.NoError, new MockPartitionId(), "file1", fileStream, 0L, fileSize, false);
    DataInputStream responseStream = serAndPrepForRead(response, -1, false);
    FileCopyGetChunkResponse deserialisedResponse = FileCopyGetChunkResponse.readFrom(responseStream, new MockClusterMap());

    Assert.assertEquals("file1", deserialisedResponse.getFileName());
    Assert.assertEquals(0L, deserialisedResponse.getStartOffset());
    Assert.assertEquals(fileSize, deserialisedResponse.getChunkSizeInBytes());
    Assert.assertEquals(111, deserialisedResponse.getCorrelationId());
    Assert.assertEquals(ServerErrorCode.NoError, deserialisedResponse.getError());
    Assert.assertEquals(0, deserialisedResponse.getPartitionId().getId());
    Assert.assertEquals("0", deserialisedResponse.getPartitionId().toPathString());
    Assert.assertEquals(requestVersionToUse, deserialisedResponse.getVersionId());
    response.release();
    byteBuf.release();

    try {
      // Sending CURRENT_VERSION + 1 as version. Expected to throw exception.
      new FileCopyGetChunkResponse((short) (FileCopyGetChunkResponse.CURRENT_VERSION + 1),
          111, "id1", ServerErrorCode.NoError, null, "file1", fileStream, 0L, fileSize, false);
      Assert.fail("Should have failed");
    } catch (IllegalArgumentException e) {
      //expected
    }
    try {
      // Sending null partition id. Expected to throw exception.
      new FileCopyGetChunkResponse(requestVersionToUse, 111, "id1", ServerErrorCode.NoError, null, "file1",
          fileStream, 0L, fileSize, false);
      Assert.fail("Should have failed");
    } catch (NullPointerException e) {
      //expected
    }
    try {
      // Sending empty file name. Expected to throw exception.
      new FileCopyGetChunkResponse(requestVersionToUse, 111, "id1", ServerErrorCode.NoError, new MockPartitionId(), "",
          fileStream, 0L, fileSize, false);
      Assert.fail("Should have failed");
    } catch (IllegalArgumentException e) {
      //expected
    }
    try {
      // Sending null file stream. Expected to throw exception.
      new FileCopyGetChunkResponse(requestVersionToUse, 111, "id1", ServerErrorCode.NoError, new MockPartitionId(),
          "file1", null, 0L, fileSize, false);
      Assert.fail("Should have failed");
    } catch (NullPointerException e) {
      //expected
    }
    try {
      // Sending negative start offset. Expected to throw exception.
      new FileCopyGetChunkResponse(requestVersionToUse, 111, "id1", ServerErrorCode.NoError, new MockPartitionId(),
          "file1", fileStream, -1, fileSize, false);
      Assert.fail("Should have failed");
    } catch (IllegalArgumentException e) {
      //expected
    }
    try {
      // Sending negative chunk size. Expected to throw exception.
      new FileCopyGetChunkResponse(requestVersionToUse, 111, "id1", ServerErrorCode.NoError, new MockPartitionId(),
          "file1", fileStream, 0L, -1, false);
      Assert.fail("Should have failed");
    } catch (IllegalArgumentException e) {
      //expected
    }
  }
Test the {@link StoreFileChunk#from} method.
@throws IOException
ambry-protocol/src/test/java/com/github/ambry/protocol/RequestResponseTest.java