Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate /api/devfile REST API #13868

Merged
merged 4 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
package org.eclipse.che.api.workspace.server.devfile;

import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.eclipse.che.api.workspace.server.DtoConverter.asDto;
import static org.eclipse.che.api.workspace.server.WorkspaceKeyValidator.validateKey;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -43,10 +41,7 @@
import org.eclipse.che.api.core.rest.Service;
import org.eclipse.che.api.workspace.server.WorkspaceLinksGenerator;
import org.eclipse.che.api.workspace.server.WorkspaceService;
import org.eclipse.che.api.workspace.server.devfile.exception.DevfileException;
import org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl;
import org.eclipse.che.api.workspace.server.model.impl.devfile.DevfileImpl;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceDto;
import org.eclipse.che.api.workspace.shared.dto.devfile.DevfileDto;

Expand Down Expand Up @@ -124,16 +119,8 @@ public Response createFromYaml(String data)
throws ServerException, ConflictException, NotFoundException, ValidationException,
BadRequestException {

WorkspaceImpl workspace;
try {
DevfileImpl devfile = devfileManager.parseYaml(data);
workspace = devfileManager.createWorkspace(devfile, urlFileContentProvider);
} catch (DevfileException e) {
throw new BadRequestException(e.getMessage());
}
return Response.status(201)
.entity(asDto(workspace).withLinks(linksGenerator.genLinks(workspace, getServiceContext())))
.build();
throw new BadRequestException(
"This method is deprecated and may be removed at any time. Please use /api/workspace/devfile to create a new workspace");
}

/**
Expand Down Expand Up @@ -166,9 +153,7 @@ public Response createFromWorkspace(
String key)
throws NotFoundException, ServerException, BadRequestException, ConflictException,
JsonProcessingException {
validateKey(key);
return Response.ok()
.entity(objectMapper.writeValueAsString(devfileManager.exportWorkspace(key)))
.build();
throw new BadRequestException(
"This method is deprecated and may be removed at any time. Please use /api/workspace/devfile to create a new workspace");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
import static org.everrest.assured.JettyHttpServer.ADMIN_USER_NAME;
import static org.everrest.assured.JettyHttpServer.ADMIN_USER_PASSWORD;
import static org.everrest.assured.JettyHttpServer.SECURE_PATH;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -30,6 +27,7 @@
import java.io.IOException;
import org.eclipse.che.account.spi.AccountImpl;
import org.eclipse.che.api.core.model.workspace.WorkspaceStatus;
import org.eclipse.che.api.core.rest.ApiExceptionMapper;
import org.eclipse.che.api.workspace.server.WorkspaceLinksGenerator;
import org.eclipse.che.api.workspace.server.devfile.schema.DevfileSchemaProvider;
import org.eclipse.che.api.workspace.server.model.impl.WorkspaceConfigImpl;
Expand All @@ -55,6 +53,10 @@ public class DevfileServiceTest {

@Mock private DevfileManager devfileManager;
@Mock private URLFetcher urlFetcher;

@SuppressWarnings("unused") // is declared for deploying by everrest-assured
private ApiExceptionMapper exceptionMapper;

private DevfileSchemaProvider schemaProvider = new DevfileSchemaProvider();
private ObjectMapper mapper = new ObjectMapper(new YAMLFactory());

Expand Down Expand Up @@ -89,8 +91,6 @@ public void shouldAcceptDevFileContentAndCreateWorkspace() throws Exception {
Files.readFile(getClass().getClassLoader().getResourceAsStream("devfile/devfile.yaml"));
DevfileImpl devfile = createDevfile(yamlContent);
WorkspaceImpl ws = createWorkspace(WorkspaceStatus.STOPPED);
when(devfileManager.parseYaml(anyString())).thenReturn(devfile);
when(devfileManager.createWorkspace(any(DevfileImpl.class), any())).thenReturn(ws);
final Response response =
given()
.auth()
Expand All @@ -100,9 +100,8 @@ public void shouldAcceptDevFileContentAndCreateWorkspace() throws Exception {
.when()
.post(SECURE_PATH + "/devfile");

assertEquals(response.getStatusCode(), 201);
verify(devfileManager).createWorkspace(captor.capture(), any());
assertEquals(devfile, captor.getValue());
assertEquals(response.getStatusCode(), 400);
verifyNoMoreInteractions(devfileManager);
}

private DevfileImpl createDevfile(String yamlContent) throws IOException {
Expand All @@ -122,9 +121,8 @@ public void shouldCreateDevFileFromWorkspace() throws Exception {
.when()
.get(SECURE_PATH + "/devfile/ws123456");

assertEquals(response.getStatusCode(), 200);
DevfileImpl devFile = objectMapper.readValue(response.getBody().asString(), DevfileImpl.class);
assertNotNull(devFile);
assertEquals(response.getStatusCode(), 400);
verifyNoMoreInteractions(devfileManager);
}

private WorkspaceImpl createWorkspace(WorkspaceStatus status)
Expand Down