use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project devspaces-images by redhat-developer.
the class UserDevfileDaoTest method shouldUpdateUserDevfile.
@Test
public void shouldUpdateUserDevfile() throws Exception {
// given
DevfileImpl newDevfile = TestObjectGenerator.createDevfile("newUpdate");
newDevfile.setApiVersion("V15.0");
newDevfile.setProjects(ImmutableList.of(new ProjectImpl("projectUp2", new SourceImpl("typeUp2", "http://location", "branch2", "point2", "tag2", "commit2", "sparseCheckoutDir2"), "path2")));
newDevfile.setComponents(ImmutableList.of(new ComponentImpl("type3", "id54")));
newDevfile.setCommands(ImmutableList.of(new CommandImpl(new CommandImpl("cmd1", Collections.singletonList(new ActionImpl("exe44", "compo2nent2", "run.sh", "/home/user/2", null, null)), Collections.singletonMap("attr1", "value1"), null))));
newDevfile.setAttributes(ImmutableMap.of("key2", "val34"));
newDevfile.setMetadata(new MetadataImpl("myNewName"));
final UserDevfileImpl update = devfiles[0];
update.setDevfile(newDevfile);
// when
userDevfileDaoDao.update(update);
// then
assertEquals(userDevfileDaoDao.getById(update.getId()), Optional.of(update));
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project devspaces-images by redhat-developer.
the class WorkspaceManagerTest method doNotEvaluateInfraNamespaceIfItIsSpecifiedOnWorkspaceStart.
@Test
public void doNotEvaluateInfraNamespaceIfItIsSpecifiedOnWorkspaceStart() throws Exception {
DevfileImpl devfile = mock(DevfileImpl.class);
WorkspaceImpl workspace = createAndMockWorkspace(devfile, NAMESPACE_1, ImmutableMap.of(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "user-defined"));
mockAnyWorkspaceStart();
workspaceManager.startWorkspace(workspace.getId(), null, emptyMap());
verify(runtimes).startAsync(eq(workspace), eq(null), anyMap());
verify(workspaceDao, times(2)).update(workspaceCaptor.capture());
assertEquals(workspaceCaptor.getAllValues().get(0).getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE), "user-defined");
verify(runtimes, never()).evalInfrastructureNamespace(any());
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project devspaces-images by redhat-developer.
the class WorkspaceManagerTest method evaluatesLegacyInfraNamespaceIfMissingOnWorkspaceStart.
@Test
public void evaluatesLegacyInfraNamespaceIfMissingOnWorkspaceStart() throws Exception {
DevfileImpl devfile = mock(DevfileImpl.class);
WorkspaceImpl workspace = createAndMockWorkspace(devfile, NAMESPACE_1, new HashMap<>());
workspace.getAttributes().remove(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE);
when(runtimes.evalInfrastructureNamespace(any())).thenReturn("evaluated-legacy");
mockAnyWorkspaceStart();
workspaceManager.startWorkspace(workspace.getId(), null, emptyMap());
verify(runtimes).startAsync(eq(workspace), eq(null), anyMap());
verify(workspaceDao, times(2)).update(workspaceCaptor.capture());
assertEquals(workspaceCaptor.getAllValues().get(0).getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE), "evaluated-legacy");
verify(runtimes).evalInfrastructureNamespace(new NamespaceResolutionContext(workspace.getId(), USER_ID, NAMESPACE_1));
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project devspaces-images by redhat-developer.
the class WorkspaceManagerTest method nameIsUsedWhenNameAndGenerateNameSet.
@Test
public void nameIsUsedWhenNameAndGenerateNameSet() throws ValidationException, ConflictException, NotFoundException, ServerException, InfrastructureException {
final String devfileName = "workspacename";
final DevfileImpl devfile = new DevfileImpl();
devfile.setApiVersion(CURRENT_API_VERSION);
devfile.getMetadata().setName(devfileName);
devfile.getMetadata().setGenerateName("this_will_not_be_set_as_a_name");
when(runtimes.evalInfrastructureNamespace(any())).thenReturn("ns");
Workspace workspace = workspaceManager.createWorkspace(devfile, NAMESPACE_1, null, null);
assertEquals(workspace.getDevfile().getName(), devfileName);
}
use of org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl in project devspaces-images by redhat-developer.
the class WorkspaceManagerTest method evaluatesDefaultInfraNamespaceIfInvalidOnWorkspaceStart.
@Test
public void evaluatesDefaultInfraNamespaceIfInvalidOnWorkspaceStart() throws Exception {
DevfileImpl devfile = mock(DevfileImpl.class);
WorkspaceImpl workspace = createAndMockWorkspace(devfile, NAMESPACE_1, ImmutableMap.of(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE, "-invalid-dns-name"));
when(runtimes.evalInfrastructureNamespace(any())).thenReturn("evaluated-legal");
when(runtimes.isInfrastructureNamespaceValid(eq("-invalid-dns-name"))).thenReturn(false);
mockAnyWorkspaceStart();
workspaceManager.startWorkspace(workspace.getId(), null, emptyMap());
verify(runtimes).startAsync(eq(workspace), eq(null), anyMap());
verify(workspaceDao, times(2)).update(workspaceCaptor.capture());
assertEquals(workspaceCaptor.getAllValues().get(0).getAttributes().get(WORKSPACE_INFRASTRUCTURE_NAMESPACE_ATTRIBUTE), "evaluated-legal");
verify(runtimes).evalInfrastructureNamespace(new NamespaceResolutionContext(workspace.getId(), USER_ID, NAMESPACE_1));
}
Aggregations