/** 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); } }