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

Avoid using DtoImpls directly #14320

Merged
merged 1 commit into from
Aug 23, 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 @@ -31,12 +31,13 @@
import org.eclipse.che.api.core.BadRequestException;
import org.eclipse.che.api.core.UnauthorizedException;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.core.server.dto.DtoServerImpls.ServiceErrorImpl;
import org.eclipse.che.api.core.rest.shared.dto.ServiceError;
import org.eclipse.che.api.workspace.server.WorkspaceRuntimes;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.RuntimeContext;
import org.eclipse.che.commons.env.EnvironmentContext;
import org.eclipse.che.commons.subject.Subject;
import org.eclipse.che.dto.server.DtoFactory;
import org.eclipse.che.multiuser.keycloak.server.KeycloakServiceClient;
import org.eclipse.che.multiuser.keycloak.server.KeycloakSettings;
import org.eclipse.che.multiuser.keycloak.shared.dto.KeycloakTokenResponse;
Expand Down Expand Up @@ -188,8 +189,11 @@ public void testThrowOnBadScope() throws Exception {
assertEquals(resultConfig.getOauthToken(), ACCESS_TOKEN);
}

@Test
public void testRethrowOnUnauthorizedException() throws Exception {
doThrow(new UnauthorizedException(ServiceErrorImpl.make().withMessage("Any other message")))
doThrow(
new UnauthorizedException(
DtoFactory.newDto(ServiceError.class).withMessage("Any other message")))
.when(keycloakServiceClient)
.getIdentityProviderToken(anyString());
try {
Expand All @@ -204,14 +208,19 @@ public void testRethrowOnUnauthorizedException() throws Exception {

@Test(expectedExceptions = {InfrastructureException.class})
public void testRethrowOnBadRequestException() throws Exception {
doThrow(new BadRequestException(ServiceErrorImpl.make().withMessage("Any other message")))
doThrow(
new BadRequestException(
DtoFactory.newDto(ServiceError.class).withMessage("Any other message")))
.when(keycloakServiceClient)
.getIdentityProviderToken(anyString());
configBuilder.buildConfig(defaultConfig, A_WORKSPACE_ID);
}

@Test
public void testRethrowOnInvalidTokenBadRequestException() throws Exception {
doThrow(new BadRequestException(ServiceErrorImpl.make().withMessage("Invalid token.")))
doThrow(
new BadRequestException(
DtoFactory.newDto(ServiceError.class).withMessage("Invalid token.")))
.when(keycloakServiceClient)
.getIdentityProviderToken(anyString());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
import org.eclipse.che.api.workspace.server.devfile.DevfileManager;
import org.eclipse.che.api.workspace.server.devfile.URLFetcher;
import org.eclipse.che.api.workspace.server.devfile.exception.DevfileFormatException;
import org.eclipse.che.api.workspace.server.dto.DtoServerImpls.DevfileDtoImpl;
import org.eclipse.che.api.workspace.server.model.impl.CommandImpl;
import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl;
import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl;
Expand Down Expand Up @@ -188,7 +187,7 @@ public void shouldCreateWorkspaceFromConfig() throws Exception {

@Test
public void shouldCreateWorkspaceFromDevfile() throws Exception {
final DevfileDtoImpl devfileDto = createDevfileDto();
final DevfileDto devfileDto = createDevfileDto();
final WorkspaceImpl workspace = createWorkspace(devfileDto);

when(devfileManager.parseJson(any())).thenReturn(new DevfileImpl());
Expand All @@ -201,7 +200,7 @@ public void shouldCreateWorkspaceFromDevfile() throws Exception {
.auth()
.basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
.contentType("application/json")
.body(devfileDto.toJson())
.body(devfileDto)
.when()
.post(
SECURE_PATH
Expand All @@ -228,7 +227,7 @@ public void shouldCreateWorkspaceFromDevfile() throws Exception {

@Test
public void shouldAcceptYamlDevfileWhenCreatingWorkspace() throws Exception {
final DevfileDtoImpl devfileDto = createDevfileDto();
final DevfileDto devfileDto = createDevfileDto();
final WorkspaceImpl workspace = createWorkspace(devfileDto);

when(devfileManager.parseYaml(any())).thenReturn(new DevfileImpl());
Expand Down Expand Up @@ -267,7 +266,7 @@ public void shouldAcceptYamlDevfileWhenCreatingWorkspace() throws Exception {

@Test
public void shouldReturnBadRequestOnInvalidDevfile() throws Exception {
final DevfileDtoImpl devfileDto = createDevfileDto();
final DevfileDto devfileDto = createDevfileDto();
final WorkspaceImpl workspace = createWorkspace(devfileDto);

when(devfileManager.parseJson(any())).thenThrow(new DevfileFormatException("boom"));
Expand All @@ -280,7 +279,7 @@ public void shouldReturnBadRequestOnInvalidDevfile() throws Exception {
.auth()
.basic(ADMIN_USER_NAME, ADMIN_USER_PASSWORD)
.contentType("application/json")
.body(devfileDto.toJson())
.body(devfileDto)
.when()
.post(
SECURE_PATH
Expand Down Expand Up @@ -1352,18 +1351,17 @@ private WorkspaceImpl createWorkspace(DevfileDto devfileDto) {
.build();
}

private DevfileDtoImpl createDevfileDto() {
return (DevfileDtoImpl)
newDto(DevfileDto.class)
.withApiVersion("0.0.1")
.withMetadata(newDto(MetadataDto.class).withName("ws"))
.withProjects(
singletonList(
newDto(ProjectDto.class)
.withName("project")
.withSource(
newDto(SourceDto.class)
.withLocation("https://github.com/eclipse/che.git"))));
private DevfileDto createDevfileDto() {
return newDto(DevfileDto.class)
.withApiVersion("0.0.1")
.withMetadata(newDto(MetadataDto.class).withName("ws"))
.withProjects(
singletonList(
newDto(ProjectDto.class)
.withName("project")
.withSource(
newDto(SourceDto.class)
.withLocation("https://github.com/eclipse/che.git"))));
}

private static WorkspaceImpl createWorkspace(WorkspaceConfig configDto) {
Expand Down