@Test public void testValidateTemplateItem1WhereTemplateIdIsUpdated() throws FileNotFoundException, JAXBException { TemplateValidator tv = new TemplateValidator(webHookTemplateManager, permissionChecker, projectManager); TemplateItem templateItem = new JaxHelper<TemplateItem>().read(ELASTICSEARCH_TEMPLATE_ITEM_ONE_TEMPLATE_XML, TemplateItem.class); TemplateItem templateItem2 = new JaxHelper<TemplateItem>().read(ELASTICSEARCH_TEMPLATE_ITEM_ONE_TEMPLATE_XML, TemplateItem.class); templateItem2.setId("someOtherId"); ErrorResult result = tv.validateTemplateItem(templateItem, templateItem2, new ErrorResult()); assertTrue(result.isErrored()); assertEquals(1,result.getErrors().size()); assertTrue(result.getErrors().get("id").contains("The id field must match the existing one")); }
public ErrorResult validateTemplateItem(TemplateItem templateItem, TemplateItem requestTemplateItem, ErrorResult result) { if (!"_new".equals(requestTemplateItem.getId()) && !templateItem.getId().equals(requestTemplateItem.getId())) { result.addError("id", "The id field must match the existing one."); } validateTemplateText(requestTemplateItem, result); for (WebHookTemplateStateRest requestItemState : requestTemplateItem.getBuildStates()) { if (BuildStateEnum.findBuildState(requestItemState.getType()) == null){ result.addError(requestItemState.getType(), requestItemState.getType() + " is an not a valid buildState"); } } for (WebHookTemplateStateRest itemState : templateItem.getBuildStates()) { WebHookTemplateStateRest requestItemState = requestTemplateItem.findConfigForBuildState(itemState.getType()); if (requestItemState != null && itemState.isEnabled() != requestItemState.isEnabled() && !Boolean.TRUE.equals(itemState.getEditable())) { result.addError(itemState.getType(), itemState.getType() + " is not editable for this templateItem"); } } return result; }
TemplateValidator { public ErrorResult validateTemplateItem(TemplateItem templateItem, TemplateItem requestTemplateItem, ErrorResult result) { if (!"_new".equals(requestTemplateItem.getId()) && !templateItem.getId().equals(requestTemplateItem.getId())) { result.addError("id", "The id field must match the existing one."); } validateTemplateText(requestTemplateItem, result); for (WebHookTemplateStateRest requestItemState : requestTemplateItem.getBuildStates()) { if (BuildStateEnum.findBuildState(requestItemState.getType()) == null){ result.addError(requestItemState.getType(), requestItemState.getType() + " is an not a valid buildState"); } } for (WebHookTemplateStateRest itemState : templateItem.getBuildStates()) { WebHookTemplateStateRest requestItemState = requestTemplateItem.findConfigForBuildState(itemState.getType()); if (requestItemState != null && itemState.isEnabled() != requestItemState.isEnabled() && !Boolean.TRUE.equals(itemState.getEditable())) { result.addError(itemState.getType(), itemState.getType() + " is not editable for this templateItem"); } } return result; } }
TemplateValidator { public ErrorResult validateTemplateItem(TemplateItem templateItem, TemplateItem requestTemplateItem, ErrorResult result) { if (!"_new".equals(requestTemplateItem.getId()) && !templateItem.getId().equals(requestTemplateItem.getId())) { result.addError("id", "The id field must match the existing one."); } validateTemplateText(requestTemplateItem, result); for (WebHookTemplateStateRest requestItemState : requestTemplateItem.getBuildStates()) { if (BuildStateEnum.findBuildState(requestItemState.getType()) == null){ result.addError(requestItemState.getType(), requestItemState.getType() + " is an not a valid buildState"); } } for (WebHookTemplateStateRest itemState : templateItem.getBuildStates()) { WebHookTemplateStateRest requestItemState = requestTemplateItem.findConfigForBuildState(itemState.getType()); if (requestItemState != null && itemState.isEnabled() != requestItemState.isEnabled() && !Boolean.TRUE.equals(itemState.getEditable())) { result.addError(itemState.getType(), itemState.getType() + " is not editable for this templateItem"); } } return result; } TemplateValidator(WebHookTemplateManager templateManager, PermissionChecker permissionChecker,
			ProjectManager projectManager); }
TemplateValidator { public ErrorResult validateTemplateItem(TemplateItem templateItem, TemplateItem requestTemplateItem, ErrorResult result) { if (!"_new".equals(requestTemplateItem.getId()) && !templateItem.getId().equals(requestTemplateItem.getId())) { result.addError("id", "The id field must match the existing one."); } validateTemplateText(requestTemplateItem, result); for (WebHookTemplateStateRest requestItemState : requestTemplateItem.getBuildStates()) { if (BuildStateEnum.findBuildState(requestItemState.getType()) == null){ result.addError(requestItemState.getType(), requestItemState.getType() + " is an not a valid buildState"); } } for (WebHookTemplateStateRest itemState : templateItem.getBuildStates()) { WebHookTemplateStateRest requestItemState = requestTemplateItem.findConfigForBuildState(itemState.getType()); if (requestItemState != null && itemState.isEnabled() != requestItemState.isEnabled() && !Boolean.TRUE.equals(itemState.getEditable())) { result.addError(itemState.getType(), itemState.getType() + " is not editable for this templateItem"); } } return result; } TemplateValidator(WebHookTemplateManager templateManager, PermissionChecker permissionChecker,
			ProjectManager projectManager); ErrorResult validateNewTemplate(String projectId, Template requestTemplate, ErrorResult result); ErrorResult validateTemplate(WebHookTemplateConfigWrapper webHookTemplateConfigWrapper, Template requestTemplate, ErrorResult result); ErrorResult validateTemplateItem(TemplateItem templateItem, TemplateItem requestTemplateItem, ErrorResult result); ErrorResult validateDefaultTemplateItem(TemplateItem requestTemplateItem, ErrorResult result); }
TemplateValidator { public ErrorResult validateTemplateItem(TemplateItem templateItem, TemplateItem requestTemplateItem, ErrorResult result) { if (!"_new".equals(requestTemplateItem.getId()) && !templateItem.getId().equals(requestTemplateItem.getId())) { result.addError("id", "The id field must match the existing one."); } validateTemplateText(requestTemplateItem, result); for (WebHookTemplateStateRest requestItemState : requestTemplateItem.getBuildStates()) { if (BuildStateEnum.findBuildState(requestItemState.getType()) == null){ result.addError(requestItemState.getType(), requestItemState.getType() + " is an not a valid buildState"); } } for (WebHookTemplateStateRest itemState : templateItem.getBuildStates()) { WebHookTemplateStateRest requestItemState = requestTemplateItem.findConfigForBuildState(itemState.getType()); if (requestItemState != null && itemState.isEnabled() != requestItemState.isEnabled() && !Boolean.TRUE.equals(itemState.getEditable())) { result.addError(itemState.getType(), itemState.getType() + " is not editable for this templateItem"); } } return result; } TemplateValidator(WebHookTemplateManager templateManager, PermissionChecker permissionChecker,
			ProjectManager projectManager); ErrorResult validateNewTemplate(String projectId, Template requestTemplate, ErrorResult result); ErrorResult validateTemplate(WebHookTemplateConfigWrapper webHookTemplateConfigWrapper, Template requestTemplate, ErrorResult result); ErrorResult validateTemplateItem(TemplateItem templateItem, TemplateItem requestTemplateItem, ErrorResult result); ErrorResult validateDefaultTemplateItem(TemplateItem requestTemplateItem, ErrorResult result);  }