use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentIntegrityValidatorTest method shouldApplyEntrypoint.
@Test
public void shouldApplyEntrypoint() throws Exception {
// given
when(kubernetesRecipeParser.parse(any(String.class))).thenReturn(Arrays.asList(new PodBuilder().withNewSpec().addNewContainer().withName("container_a").endContainer().endSpec().build(), new PodBuilder().withNewSpec().addNewContainer().withName("container_b").endContainer().endSpec().build()));
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReferenceContent("content");
component.setReference("ref");
EntrypointImpl entrypoint = new EntrypointImpl();
entrypoint.setContainerName("container_a");
component.setEntrypoints(Collections.singletonList(entrypoint));
// when
validator.validateComponent(component, __ -> "");
// then no exception is thrown
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldThrowExceptionWhenRecipeContentIsNotAValidYaml.
@Test(expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = "Error occurred during parsing list from file " + REFERENCE_FILENAME + " for component '" + COMPONENT_NAME + "': .*")
public void shouldThrowExceptionWhenRecipeContentIsNotAValidYaml() throws Exception {
// given
doThrow(new ValidationException("non valid")).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
// when
applier.apply(workspaceConfig, component, s -> "some_non_yaml_content");
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldThrowExceptionWhenDevfileVolumeNameExists.
@Test(expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = "Conflicting volume with same name \\('foo_volume'\\) but different path \\('/foo1'\\) found for component 'foo' and its container 'server'.")
public void shouldThrowExceptionWhenDevfileVolumeNameExists() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
component.setVolumes(Collections.singletonList(new VolumeImpl("foo_volume", "/foo1")));
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldThrowExceptionWhenExceptionHappensOnContentProvider.
@Test(expectedExceptions = DevfileException.class, expectedExceptionsMessageRegExp = "Error during recipe content retrieval for component 'foo' with type 'kubernetes': fetch failed")
public void shouldThrowExceptionWhenExceptionHappensOnContentProvider() throws Exception {
// given
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
// when
applier.apply(workspaceConfig, component, e -> {
throw new IOException("fetch failed");
});
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.ComponentImpl in project che-server by eclipse-che.
the class KubernetesComponentToWorkspaceApplierTest method shouldProvisionProjectVolumesIfSpecifiedIntoK8SList.
@Test
public void shouldProvisionProjectVolumesIfSpecifiedIntoK8SList() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
List<HasMetadata> k8sList = toK8SList(yamlRecipeContent).getItems();
doReturn(k8sList).when(k8sRecipeParser).parse(anyString());
ComponentImpl component = new ComponentImpl();
component.setType(KUBERNETES_COMPONENT_TYPE);
component.setReference(REFERENCE_FILENAME);
component.setAlias(COMPONENT_NAME);
component.setMountSources(true);
// when
applier.apply(workspaceConfig, component, s -> yamlRecipeContent);
// then
verify(k8sEnvProvisioner).provision(any(), any(), objectsCaptor.capture(), any());
List<HasMetadata> list = objectsCaptor.getValue();
// Make sure PVC is created
assertTrue(list.stream().filter(hasMeta -> hasMeta instanceof PersistentVolumeClaim).map(o -> (PersistentVolumeClaim) o).anyMatch(claim -> claim.getMetadata().getName().equals(PROJECTS_VOLUME_NAME)));
for (HasMetadata o : list) {
if (o instanceof Pod) {
Pod p = (Pod) o;
// ignore pods that don't have containers
if (p.getSpec() == null) {
continue;
}
// Make sure volume is created
assertTrue(p.getSpec().getVolumes().stream().anyMatch(v -> v.getName().equals(PROJECTS_VOLUME_NAME) && v.getPersistentVolumeClaim().getClaimName().equals(PROJECTS_VOLUME_NAME)));
for (Container c : p.getSpec().getContainers()) {
assertEquals(c.getImagePullPolicy(), "Always");
assertTrue(c.getVolumeMounts().stream().anyMatch(vm -> vm.getName().equals(PROJECTS_VOLUME_NAME) && vm.getMountPath().equals(PROJECT_MOUNT_PATH)));
}
}
}
}
Aggregations