use of org.eclipse.che.api.workspace.server.model.impl.RecipeImpl in project che-server by eclipse-che.
the class URLFactoryBuilderTest method checkWithCustomDevfileAndRecipe.
@Test
public void checkWithCustomDevfileAndRecipe() throws Exception {
DevfileImpl devfile = new DevfileImpl();
WorkspaceConfigImpl workspaceConfigImpl = new WorkspaceConfigImpl();
String myLocation = "http://foo-location/";
RecipeImpl expectedRecipe = new RecipeImpl(KUBERNETES_COMPONENT_TYPE, "application/x-yaml", "content", "");
EnvironmentImpl expectedEnv = new EnvironmentImpl(expectedRecipe, emptyMap());
workspaceConfigImpl.setEnvironments(singletonMap("name", expectedEnv));
workspaceConfigImpl.setDefaultEnv("name");
when(devfileParser.parseYamlRaw(anyString())).thenReturn(new ObjectNode(JsonNodeFactory.instance));
when(devfileParser.parseJsonNode(any(JsonNode.class), anyMap())).thenReturn(devfile);
when(devfileVersionDetector.devfileMajorVersion(any(JsonNode.class))).thenReturn(1);
FactoryMetaDto factory = urlFactoryBuilder.createFactoryFromDevfile(new DefaultFactoryUrl().withDevfileFileLocation(myLocation), s -> myLocation + ".list", emptyMap()).get();
assertNotNull(factory);
assertNull(factory.getSource());
assertTrue(factory instanceof FactoryDto);
}
use of org.eclipse.che.api.workspace.server.model.impl.RecipeImpl in project che-server by eclipse-che.
the class WorkspaceRuntimesTest method internalEnvironmentShouldThrowExceptionWhenNoEnvironmentFactoryFoundForRecipeType.
@Test(expectedExceptions = NotFoundException.class, expectedExceptionsMessageRegExp = "InternalEnvironmentFactory is not configured for recipe type: 'not-supported-type'")
public void internalEnvironmentShouldThrowExceptionWhenNoEnvironmentFactoryFoundForRecipeType() throws Exception {
EnvironmentImpl environment = new EnvironmentImpl();
environment.setRecipe(new RecipeImpl("not-supported-type", "", "", null));
runtimes.createInternalEnvironment(environment, emptyMap(), emptyList(), null);
}
use of org.eclipse.che.api.workspace.server.model.impl.RecipeImpl in project che-server by eclipse-che.
the class KubernetesEnvironmentProvisionerTest method shouldProvisionComponentObjectsIntoExistingKubernetesRecipe.
@Test
public void shouldProvisionComponentObjectsIntoExistingKubernetesRecipe() throws Exception {
// given
workspaceConfig.setDefaultEnv("default");
RecipeImpl existingRecipe = new RecipeImpl(KUBERNETES_COMPONENT_TYPE, "yaml", "existing-content", null);
workspaceConfig.getEnvironments().put("default", new EnvironmentImpl(existingRecipe, emptyMap()));
List<HasMetadata> recipeObjects = new ArrayList<>();
Deployment recipeDeployment = new DeploymentBuilder().withNewMetadata().withName("db").endMetadata().withNewSpec().endSpec().build();
recipeObjects.add(new DeploymentBuilder(recipeDeployment).build());
doReturn(recipeObjects).when(k8sRecipeParser).parse(anyString());
List<HasMetadata> componentsObject = new ArrayList<>();
Deployment componentDeployment = new DeploymentBuilder().withNewMetadata().withName("web-app").endMetadata().withNewSpec().endSpec().build();
componentsObject.add(new DeploymentBuilder(componentDeployment).build());
// when
k8sEnvProvisioner.provision(workspaceConfig, KubernetesEnvironment.TYPE, componentsObject, emptyMap());
// then
// it is expected that applier wrap original recipes objects in new Kubernetes list
KubernetesList expectedKubernetesList = new KubernetesListBuilder().withItems(Arrays.asList(recipeDeployment, componentDeployment)).build();
EnvironmentImpl resultEnv = workspaceConfig.getEnvironments().get(workspaceConfig.getDefaultEnv());
assertEquals(toK8SList(resultEnv.getRecipe().getContent()).getItems(), expectedKubernetesList.getItems());
}
use of org.eclipse.che.api.workspace.server.model.impl.RecipeImpl in project che-server by eclipse-che.
the class KubernetesEnvironmentProvisionerTest method shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromK8SList.
@Test
public void shouldProvisionEnvironmentWithCorrectRecipeTypeAndContentFromK8SList() throws Exception {
// given
String yamlRecipeContent = getResource("devfile/petclinic.yaml");
List<HasMetadata> componentsObjects = toK8SList(yamlRecipeContent).getItems();
// when
k8sEnvProvisioner.provision(workspaceConfig, KubernetesEnvironment.TYPE, componentsObjects, emptyMap());
// then
String defaultEnv = workspaceConfig.getDefaultEnv();
assertNotNull(defaultEnv);
EnvironmentImpl environment = workspaceConfig.getEnvironments().get(defaultEnv);
assertNotNull(environment);
RecipeImpl recipe = environment.getRecipe();
assertNotNull(recipe);
assertEquals(recipe.getType(), KUBERNETES_COMPONENT_TYPE);
assertEquals(recipe.getContentType(), YAML_CONTENT_TYPE);
// it is expected that applier wrap original recipes objects in new Kubernetes list
KubernetesList expectedKubernetesList = new KubernetesListBuilder().withItems(toK8SList(yamlRecipeContent).getItems()).build();
assertEquals(toK8SList(recipe.getContent()).getItems(), expectedKubernetesList.getItems());
}
use of org.eclipse.che.api.workspace.server.model.impl.RecipeImpl in project che-server by eclipse-che.
the class KubernetesEnvironmentProvisionerTest method shouldUpgradeKubernetesEnvironmentToOpenShiftTypeOnOpenShiftComponentProvisioning.
@Test
public void shouldUpgradeKubernetesEnvironmentToOpenShiftTypeOnOpenShiftComponentProvisioning() throws Exception {
// given
workspaceConfig.setDefaultEnv("default");
RecipeImpl existingRecipe = new RecipeImpl(KubernetesEnvironment.TYPE, "yaml", "existing-content", null);
workspaceConfig.getEnvironments().put("default", new EnvironmentImpl(existingRecipe, emptyMap()));
List<HasMetadata> componentsObject = new ArrayList<>();
Deployment componentDeployment = new DeploymentBuilder().withNewMetadata().withName("web-app").endMetadata().withNewSpec().endSpec().build();
componentsObject.add(new DeploymentBuilder(componentDeployment).build());
doReturn(new ArrayList<>()).when(k8sRecipeParser).parse(anyString());
// when
k8sEnvProvisioner.provision(workspaceConfig, "openshift", componentsObject, emptyMap());
// then
EnvironmentImpl resultEnv = workspaceConfig.getEnvironments().get(workspaceConfig.getDefaultEnv());
RecipeImpl resultRecipe = resultEnv.getRecipe();
assertEquals(resultRecipe.getType(), "openshift");
}
Aggregations