@Test
  public void testUploadStreamMissing() {
    FormDataContentDispositionBuilder builder =
        FormDataContentDisposition.name("multipart;form-data");
    builder.fileName("adele1.png");
    FormDataContentDisposition formDataContentDisposition = builder.build();

    response =
        recordEndpoint.uploadFile(
            AUTH_TOKEN, AUTH_TOKEN, "image", "image:123456789", null, formDataContentDisposition);

    assertResponseStatusIs(Response.Status.BAD_REQUEST);
  }
  @Test
  public void testUpload() throws ParseException {
    InputStream stream = new ByteArrayInputStream("a string".getBytes(StandardCharsets.UTF_8));

    FormDataContentDispositionBuilder builder =
        FormDataContentDisposition.name("multipart;form-data");
    builder.fileName("adele1.png");
    FormDataContentDisposition formDataContentDisposition = builder.build();

    response =
        recordEndpoint.uploadFile(
            AUTH_TOKEN, AUTH_TOKEN, "image", "image:123456789", stream, formDataContentDisposition);

    String entity = (String) response.getEntity();

    assertEquals(
        entity,
        "{\"record\":{\"data\":{\"children\":[{\"children\":["
            + "{\"name\":\"id\",\"value\":\"image:123456789\"},"
            + "{\"name\":\"type\",\"value\":\"image\"},"
            + "{\"name\":\"createdBy\",\"value\":\"12345\"},"
            + "{\"children\":["
            + "{\"name\":\"linkedRecordType\",\"value\":\"system\"},"
            + "{\"name\":\"linkedRecordId\",\"value\":\"cora\"}],\"actionLinks\":"
            + "{\"read\":{\"requestMethod\":\"GET\",\"rel\":\"read\","
            + "\"url\":\"http://localhost:8080/therest/rest/record/system/cora\","
            + "\"accept\":\"application/uub+record+json\"}},\"name\":\"dataDivider\"}],"
            + "\"name\":\"recordInfo\"},{\"children\":[{\"children\":[{\"name\":\"streamId\","
            + "\"value\":\"1\"},{\"name\":\"filename\",\"value\":\"adele1.png\"}"
            + ",{\"name\":\"filesize\",\"value\":\"8\"}"
            + ",{\"name\":\"mimeType\",\"value\":\"application/octet-stream\"}]"
            + ",\"actionLinks\":{\"read\":{\"requestMethod\":\"GET\",\"rel\":\"read\","
            + "\"url\":\"http://localhost:8080/therest/rest/record/image/image:123456789/master\","
            + "\"accept\":\"application/octet-stream\"}},\"name\":\"master\"}],"
            + "\"name\":\"resourceInfo\"}],\"name\":\"binary\"},\"actionLinks\":{\"read\":"
            + "{\"requestMethod\":\"GET\",\"rel\":\"read\","
            + "\"url\":\"http://localhost:8080/therest/rest/record/image/image:123456789\","
            + "\"accept\":\"application/uub+record+json\"},"
            + "\"upload\":{\"requestMethod\":\"POST\",\"rel\":\"upload\","
            + "\"contentType\":\"multipart/form-data\",\"url\":"
            + "\"http://localhost:8080/therest/rest/record/image/image:123456789/master\"},"
            + "\"update\":{\"requestMethod\":\"POST\","
            + "\"rel\":\"update\",\"contentType\":\"application/uub+record+json\","
            + "\"url\":\"http://localhost:8080/therest/rest/record/image/image:123456789\","
            + "\"accept\":\"application/uub+record+json\"},\"delete\":"
            + "{\"requestMethod\":\"DELETE\",\"rel\":\"delete\","
            + "\"url\":\"http://localhost:8080/therest/rest/record/image/image:123456789\"}}}}");

    assertResponseStatusIs(Response.Status.OK);
  }
  @Test
  public void testUploadNotAChildOfBinary() {
    InputStream stream = new ByteArrayInputStream("a string".getBytes(StandardCharsets.UTF_8));

    FormDataContentDispositionBuilder builder =
        FormDataContentDisposition.name("multipart;form-data");
    builder.fileName("adele1.png");
    FormDataContentDisposition formDataContentDisposition = builder.build();

    response =
        recordEndpoint.uploadFile(
            AUTH_TOKEN, AUTH_TOKEN, PLACE, "image:123456789", stream, formDataContentDisposition);

    assertResponseStatusIs(Response.Status.METHOD_NOT_ALLOWED);
  }
  private void expectTokenForUploadToPrefereblyBeHeaderThanQuery(
      String headerAuthToken, String queryAuthToken, String authTokenExpected) {
    SpiderInstanceFactorySpy factorySpy = setupInstanceProviderWithFactorySpy();

    FormDataContentDispositionBuilder builder =
        FormDataContentDisposition.name("multipart;form-data");
    builder.fileName("adele1.png");
    FormDataContentDisposition formDataContentDisposition = builder.build();
    InputStream stream = new ByteArrayInputStream("a string".getBytes(StandardCharsets.UTF_8));

    response =
        recordEndpoint.uploadFile(
            headerAuthToken,
            queryAuthToken,
            "image",
            "image:123456789",
            stream,
            formDataContentDisposition);

    SpiderUploaderSpy spiderUploaderSpy = factorySpy.spiderUploaderSpy;
    assertEquals(spiderUploaderSpy.authToken, authTokenExpected);
  }