@Test
  public void testCreateFundWithEmptyExternalId() {
    FundsHelper fh = FundsHelper.create(Utils.randomNameGenerator("", 10)).externalId(null).build();
    String jsonData = fh.toJSON();

    final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
    Assert.assertNotNull(fundID);
  }
  @Test
  public void testCreateFundWithEmptyName() {
    FundsHelper fh =
        FundsHelper.create(null).externalId(Utils.randomNameGenerator("fund-", 5)).build();
    String jsonData = fh.toJSON();

    ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(400).build();
    final Long fundID = createFund(jsonData, this.requestSpec, responseSpec);
    Assert.assertNull(fundID);
  }
  @Test
  public void testUpdateFundWithNewName() {
    FundsHelper fh =
        FundsHelper.create(Utils.randomNameGenerator("", 10))
            .externalId(Utils.randomNameGenerator("fund-", 5))
            .build();
    String jsonData = fh.toJSON();

    final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
    Assert.assertNotNull(fundID);

    String newName = Utils.randomNameGenerator("", 10);
    FundsHelper fh2 =
        FundsResourceHandler.updateFund(
            fundID, newName, null, this.requestSpec, this.statusOkResponseSpec);

    Assert.assertEquals(newName, fh2.getName());
  }
  @Test
  public void testRetrieveAllFunds() {
    FundsHelper fh =
        FundsHelper.create(Utils.randomNameGenerator("", 10))
            .externalId(Utils.randomNameGenerator("fund-", 5))
            .build();
    String jsonData = fh.toJSON();

    final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
    Assert.assertNotNull(fundID);

    List<FundsHelper> fhList =
        FundsResourceHandler.retrieveAllFunds(this.requestSpec, this.statusOkResponseSpec);

    Assert.assertNotNull(fhList);
    Assert.assertThat(fhList.size(), greaterThanOrEqualTo(1));
    Assert.assertThat(fhList, hasItem(fh));
  }
  @Test
  public void testUpdateFundWithInvalidNewExternalId() {
    FundsHelper fh =
        FundsHelper.create(Utils.randomNameGenerator("", 10))
            .externalId(Utils.randomNameGenerator("fund-", 5))
            .build();
    String jsonData = fh.toJSON();

    final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
    Assert.assertNotNull(fundID);

    String newName = Utils.randomNameGenerator("", 10);
    String newExternalId = Utils.randomNameGenerator("fund-", 120);
    ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(400).build();
    FundsHelper fh2 =
        FundsResourceHandler.updateFund(
            fundID, newName, newExternalId, this.requestSpec, responseSpec);

    Assert.assertNull(fh2);
  }
  @Test
  public void testRetrieveFund() {
    FundsHelper fh =
        FundsHelper.create(Utils.randomNameGenerator("", 10))
            .externalId(Utils.randomNameGenerator("fund-", 5))
            .build();
    String jsonData = fh.toJSON();

    final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
    Assert.assertNotNull(fundID);

    jsonData =
        FundsResourceHandler.retrieveFund(fundID, this.requestSpec, this.statusOkResponseSpec);
    FundsHelper fh2 = FundsHelper.fromJSON(jsonData);

    assertEquals(fh.getName(), fh2.getName());
  }
  @Test
  public void testCreateFundWithDuplicateName() {
    FundsHelper fh =
        FundsHelper.create(Utils.randomNameGenerator("", 10))
            .externalId(Utils.randomNameGenerator("fund-", 5))
            .build();
    String jsonData = fh.toJSON();

    final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
    Assert.assertNotNull(fundID);

    FundsHelper fh2 =
        FundsHelper.create(fh.getName()).externalId(Utils.randomNameGenerator("fund-", 5)).build();
    jsonData = fh2.toJSON();

    ResponseSpecification responseSpec = new ResponseSpecBuilder().expectStatusCode(403).build();
    final Long fundID2 = createFund(jsonData, this.requestSpec, responseSpec);
    Assert.assertNull(fundID2);
  }
  @Test
  public void testUpdateFundWithEmptyParams() {
    FundsHelper fh =
        FundsHelper.create(Utils.randomNameGenerator("", 10))
            .externalId(Utils.randomNameGenerator("fund-", 5))
            .build();
    String jsonData = fh.toJSON();

    final Long fundID = createFund(jsonData, this.requestSpec, this.statusOkResponseSpec);
    Assert.assertNotNull(fundID);

    FundsHelper fh2 =
        FundsResourceHandler.updateFund(
            fundID, null, null, this.requestSpec, this.statusOkResponseSpec);

    Assert.assertNull(fh2.getName());
    Assert.assertNull(fh2.getExternalId());

    // assert that there was no change in
    // the name and external ID of the fund
    jsonData =
        FundsResourceHandler.retrieveFund(fundID, this.requestSpec, this.statusOkResponseSpec);
    FundsHelper fh3 = new Gson().fromJson(jsonData, FundsHelper.class);

    Assert.assertEquals(fh.getName(), fh3.getName());
    Assert.assertEquals(fh.getExternalId(), fh3.getExternalId());
  }