DevfileIntegrityValidator { public void validateDevfile(Devfile devfile) throws DevfileFormatException { validateProjects(devfile); Set<String> knownAliases = validateComponents(devfile); validateCommands(devfile, knownAliases); } @Inject  DevfileIntegrityValidator(Map<String, ComponentIntegrityValidator> validators); void validateDevfile(Devfile devfile); void validateContentReferences(Devfile devfile, FileContentProvider provider);  }
@Test public void shouldValidateCorrectDevfile() throws Exception { integrityValidator.validateDevfile(initialDevfile); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Duplicate component alias found:'mvn-stack'") public void shouldThrowExceptionOnDuplicateComponentAlias() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); ComponentImpl component = new ComponentImpl(); component.setAlias(initialDevfile.getComponents().get(0).getAlias()); broken.getComponents().add(component); integrityValidator.validateDevfile(broken); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Duplicated endpoint name 'e1' found in 'dockerimage:latest' component") public void shouldThrowExceptionOnDuplicateEndpointName() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); ComponentImpl component = new ComponentImpl(); component.setType(DOCKERIMAGE_COMPONENT_TYPE); component.setImage("dockerimage:latest"); component.setEndpoints( ImmutableList.of( new EndpointImpl("e1", 8080, Collections.emptyMap()), new EndpointImpl("e1", 8082, Collections.emptyMap()))); broken.getComponents().add(component); integrityValidator.validateDevfile(broken); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Multiple editor components found: 'eclipse/che-theia/0.0.3', 'editor-2'") public void shouldThrowExceptionOnMultipleEditors() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); ComponentImpl component = new ComponentImpl(); component.setAlias("editor-2"); component.setType(EDITOR_COMPONENT_TYPE); broken.getComponents().add(component); integrityValidator.validateDevfile(broken); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Duplicate command name found:'build'") public void shouldThrowExceptionOnDuplicateCommandName() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); CommandImpl command = new CommandImpl(); command.setName(initialDevfile.getCommands().get(0).getName()); broken.getCommands().add(command); integrityValidator.validateDevfile(broken); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Command 'build' does not have actions.") public void shouldThrowExceptionWhenCommandDoesNotHaveActions() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); broken.getCommands().get(0).getActions().clear(); integrityValidator.validateDevfile(broken); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Multiple actions in command 'build' are not supported yet.") public void shouldThrowExceptionWhenCommandHasMultipleActions() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); broken.getCommands().get(0).getActions().add(new ActionImpl()); integrityValidator.validateDevfile(broken); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Command 'build' has action that refers to a component with unknown alias 'no_such_component'") public void shouldThrowExceptionOnUnexistingCommandActionComponent() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); broken.getCommands().get(0).getActions().clear(); ActionImpl action = new ActionImpl(); action.setComponent("no_such_component"); broken.getCommands().get(0).getActions().add(action); integrityValidator.validateDevfile(broken); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Duplicate project name found:'petclinic'") public void shouldThrowExceptionOnDuplicateProjectName() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); ProjectImpl project = new ProjectImpl(); project.setName(initialDevfile.getProjects().get(0).getName()); broken.getProjects().add(project); integrityValidator.validateDevfile(broken); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Duplicate environment variable 'foo' found in component 'test1'") public void shouldThrowExceptionOnDuplicateEnvironmentVariable() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); ComponentImpl k8s1 = new ComponentImpl(); k8s1.setType(OPENSHIFT_COMPONENT_TYPE); k8s1.setAlias("test1"); k8s1.getEnv().add(new EnvImpl("foo", "bar")); k8s1.getEnv().add(new EnvImpl("foo", "baz")); broken.getComponents().add(k8s1); integrityValidator.validateDevfile(broken); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "Invalid project name found:'.*'. Name must contain only Latin letters," + "digits or these following special characters ._-") public void shouldThrowExceptionOnInvalidProjectName() throws Exception { DevfileImpl broken = new DevfileImpl(initialDevfile); broken.getProjects().get(0).setName("./" + initialDevfile.getProjects().get(0).getName()); integrityValidator.validateDevfile(broken); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "There are multiple components 'dockerimage:latest' of type 'dockerimage' that cannot be" + " uniquely identified. Please add aliases that would distinguish the components.") public void shouldRequireAliasWhenDockerImageComponentsHaveSameImage() throws Exception { DevfileImpl devfile = new DevfileImpl(initialDevfile); ComponentImpl docker1 = new ComponentImpl(); docker1.setType(DOCKERIMAGE_COMPONENT_TYPE); docker1.setImage("dockerimage:latest"); ComponentImpl docker2 = new ComponentImpl(); docker2.setType(DOCKERIMAGE_COMPONENT_TYPE); docker2.setImage("dockerimage:latest"); devfile.getComponents().add(docker1); devfile.getComponents().add(docker2); integrityValidator.validateDevfile(devfile); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "There are multiple components 'list.yaml' of type 'kubernetes' that cannot be" + " uniquely identified. Please add aliases that would distinguish the components.") public void shouldRequireAliasWhenKubernetesComponentsHaveSameReference() throws Exception { DevfileImpl devfile = new DevfileImpl(initialDevfile); ComponentImpl k8s1 = new ComponentImpl(); k8s1.setType(KUBERNETES_COMPONENT_TYPE); k8s1.setReference("list.yaml"); ComponentImpl k8s2 = new ComponentImpl(); k8s2.setType(KUBERNETES_COMPONENT_TYPE); k8s2.setReference("list.yaml"); devfile.getComponents().add(k8s1); devfile.getComponents().add(k8s2); integrityValidator.validateDevfile(devfile); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "There are multiple components 'list.yaml' of type 'openshift' that cannot be" + " uniquely identified. Please add aliases that would distinguish the components.") public void shouldRequireAliasWhenOpenshiftComponentsHaveSameReference() throws Exception { DevfileImpl devfile = new DevfileImpl(initialDevfile); ComponentImpl k8s1 = new ComponentImpl(); k8s1.setType(OPENSHIFT_COMPONENT_TYPE); k8s1.setReference("list.yaml"); ComponentImpl k8s2 = new ComponentImpl(); k8s2.setType(OPENSHIFT_COMPONENT_TYPE); k8s2.setReference("list.yaml"); devfile.getComponents().add(k8s1); devfile.getComponents().add(k8s2); integrityValidator.validateDevfile(devfile); }
@Test( expectedExceptions = DevfileFormatException.class, expectedExceptionsMessageRegExp = "There are multiple components 'openshift' of type 'openshift' that cannot be" + " uniquely identified. Please add aliases that would distinguish the components.") public void shouldRequireAliasWhenOpenshiftComponentsHaveNoReference() throws Exception { DevfileImpl devfile = new DevfileImpl(initialDevfile); ComponentImpl k8s1 = new ComponentImpl(); k8s1.setType(OPENSHIFT_COMPONENT_TYPE); ComponentImpl k8s2 = new ComponentImpl(); k8s2.setType(OPENSHIFT_COMPONENT_TYPE); devfile.getComponents().add(k8s1); devfile.getComponents().add(k8s2); integrityValidator.validateDevfile(devfile); }