PartnersHaveUniqueNamesValidator implements ITestSuiteValidator { @Override public void validate(XMLTestSuiteDocument suite) throws SpecificationException { Set<String> partnerNames = new HashSet<String>(); XMLDeploymentSection deployment = suite.getTestSuite().getDeployment(); for(XMLPartnerDeploymentInformation p : deployment.getPartnerList()) { String name = p.getName(); if(partnerNames.contains(name)) { throw new SpecificationException("There are at least two partners with the name <" + name + ">. There must be only one."); } partnerNames.add(name); } for(XMLHumanPartnerDeploymentInformation p :deployment.getHumanPartnerList()) { String name = p.getName(); if(partnerNames.contains(name)) { throw new SpecificationException("There are at least two partners with the name <" + name + ">. There must be only one."); } partnerNames.add(name); } }  @Override void validate(XMLTestSuiteDocument suite);  }
@Test public void testAllPartnerNamesUnique() throws Exception { deployment.addNewPartner().setName("A"); deployment.addNewPartner().setName("B"); deployment.addNewHumanPartner().setName("C"); deployment.addNewHumanPartner().setName("D"); validator.validate(testSuiteDoc); }
@Test(expected = SpecificationException.class) public void testTwoSOAPPartnersWithSameName() throws Exception { deployment.addNewPartner().setName("A"); deployment.addNewPartner().setName("B"); deployment.addNewPartner().setName("A"); deployment.addNewHumanPartner().setName("C"); deployment.addNewHumanPartner().setName("D"); validator.validate(testSuiteDoc); }
@Test(expected = SpecificationException.class) public void testTwoHumanPartnersWithSameName() throws Exception { deployment.addNewPartner().setName("A"); deployment.addNewPartner().setName("B"); deployment.addNewHumanPartner().setName("C"); deployment.addNewHumanPartner().setName("D"); deployment.addNewHumanPartner().setName("C"); validator.validate(testSuiteDoc); }
@Test(expected = SpecificationException.class) public void testOneSOAPPartnerAndOneHumanPartnerWithSameName() throws Exception { deployment.addNewPartner().setName("A"); deployment.addNewPartner().setName("B"); deployment.addNewHumanPartner().setName("C"); deployment.addNewHumanPartner().setName("A"); validator.validate(testSuiteDoc); }