/** Tests if all of a company's properties can be updated. */
  @Test
  public void updateTest() throws CompanyServiceValidationException {
    final String NEWADDRESS = "newaddress";
    final String NEWCOUNTRY = "newcountry";
    final String NEWCITY = "newcity";
    final String NEWNAME = "newname";
    final String NEWEMAIL = "newmail" + SUFFIX_EMAIL;
    final String NEWPHONE = "+361111111111";

    // persist a new company, then set new values
    Company company = persist();
    company.setAddress(NEWADDRESS);
    company.setCountry(NEWCOUNTRY);
    company.setCity(NEWCITY);
    company.setName(NEWNAME);
    company.setEmail(NEWEMAIL);
    company.setPhone(NEWPHONE);

    // merge the company with new values
    Company updated = companyService.save(company);

    // asserts
    assertTrue(updated.getAddress().equals(company.getAddress()));
    assertTrue(updated.getCity().equals(company.getCity()));
    assertTrue(updated.getCompanyId().equals(company.getCompanyId()));
    assertTrue(updated.getCountry().equals(company.getCountry()));
    assertTrue(updated.getName().equals(company.getName()));
    assertTrue(updated.getEmail().equals(company.getEmail()));
    assertTrue(updated.getPhone().equals(company.getPhone()));
  }
  /** Tests if exception is thrown when we try to save without mandatory properties */
  @Test
  public void createInvalidTest() throws CompanyServiceValidationException {
    Company company = new Company();
    Owner o = new Owner();
    o.setCompany(company);

    // test missing companyid
    try {
      companyService.save(company);
    } catch (CompanyServiceValidationException e) {
      assertEquals(e.getError(), MISSING_FIELD);
      assertEquals(e.getInfo(), COMPANYID.toString());
    }

    // test missing address
    try {
      company.setCompanyId("1");
      companyService.save(company);
    } catch (CompanyServiceValidationException e) {
      assertEquals(e.getError(), MISSING_FIELD);
      assertEquals(e.getInfo(), ADDRESS.toString());
    }

    // test missing city
    try {
      company.setAddress(PREFIX_ADDRESS);
      companyService.save(company);
    } catch (CompanyServiceValidationException e) {
      assertEquals(e.getError(), MISSING_FIELD);
      assertEquals(e.getInfo(), CITY.toString());
    }

    // test missing country
    try {
      company.setCity(PREFIX_CITY);
      companyService.save(company);
    } catch (CompanyServiceValidationException e) {
      assertEquals(e.getError(), MISSING_FIELD);
      assertEquals(e.getInfo(), COUNTRY.toString());
    }

    // test missing name
    try {
      company.setCountry(PREFIX_COUNTRY);
      companyService.save(company);
    } catch (CompanyServiceValidationException e) {
      assertEquals(e.getError(), MISSING_FIELD);
      assertEquals(e.getInfo(), NAME.toString());
    }

    // test if at least 1 owner is added
    try {
      company.setName(PREFIX_NAME);
      companyService.save(company);
    } catch (CompanyServiceValidationException e) {
      assertEquals(e.getError(), MISSING_OWNER);
    }

    // test missing owner firstname
    try {
      company.getOwners().add(o);
      companyService.save(company);
    } catch (CompanyServiceValidationException e) {
      assertEquals(e.getError(), MISSING_FIELD);
      assertEquals(e.getInfo(), OWNER_FIRSTNAME.toString());
    }

    // test missing owner lastname
    try {
      o.setFirstName(PREFIX_FIRSTNAME);
      companyService.save(company);
    } catch (CompanyServiceValidationException e) {
      assertEquals(e.getError(), MISSING_FIELD);
      assertEquals(e.getInfo(), OWNER_LASTNAME.toString());
    }

    // just save
    o.setLastName(PREFIX_LASTNAME);
    companyService.save(company);
    final String INVALID = "invalid";

    // test invalid phone
    try {
      company.setPhone(INVALID);
      companyService.save(company);
    } catch (CompanyServiceValidationException e) {
      assertEquals(e.getError(), INVALID_PHONE_NUMBER);
    }

    // test invalid email
    try {
      company.setPhone(null);
      company.setEmail(INVALID);
      companyService.save(company);
    } catch (CompanyServiceValidationException e) {
      assertEquals(e.getError(), INVALID_EMAIL);
    }
  }