Skip to content
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 @@ -36,7 +36,6 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.testng.Assert.fail;

/**
* Project acceptance tests.
Expand Down Expand Up @@ -104,14 +103,14 @@ public void listProjectRoles() {

@Test(groups = "project", dependsOnMethods = "createProject")
public void getProjectById() {
final Project project = gd.getProjectService().getProjectById(this.project.getId());
assertThat(project, ProjectIdMatcher.hasSameIdAs(this.project));
final Project result = gd.getProjectService().getProjectById(project.getId());
assertThat(result, ProjectIdMatcher.hasSameIdAs(project));
}

@Test(groups = "project", dependsOnMethods = "createProject")
public void getProjectByUri() {
final Project project = gd.getProjectService().getProjectByUri(this.project.getUri());
assertThat(project, ProjectIdMatcher.hasSameIdAs(this.project));
final Project result = gd.getProjectService().getProjectByUri(project.getUri());
assertThat(result, ProjectIdMatcher.hasSameIdAs(project));
}

@Test(groups = "project", dependsOnMethods = "createProject")
Expand Down Expand Up @@ -165,7 +164,7 @@ public void getUserInProject() {

@Test(groups = {"project", "isolated_domain"}, dependsOnMethods = "disableUserInProject")
public void removeAccountFromProject() {
final User user = gd.getProjectService().getUser(project, account1);
gd.getProjectService().getUser(project, account1); // just verifying it doesn't throw before the removal
gd.getProjectService().removeUserFromProject(project, account1);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ public void removeUserFromProjectNotFound() {
.havingMethodEqualTo("DELETE")
.havingPathEqualTo(ProjectService.PROJECT_USER_TEMPLATE.expand("PROJECT_ID", "ID").toString())
.respond()
.withStatus(404);
.withStatus(404)
.withBody("{\"error\":{\"parameters\":[\"1234\"],\"requestId\":\"req1\",\"component\":\"GDC::LWP::UserAgent\",\"message\":\"User uid %s doesn't exist.\",\"errorClass\":\"GDC::Exception::NotFound\"}}");

gd.getProjectService().removeUserFromProject(enabled, account);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Collection;

import static com.gooddata.sdk.service.project.ProjectService.LIST_PROJECTS_TEMPLATE;
Expand Down Expand Up @@ -65,7 +63,7 @@ public class ProjectServiceTest {

@BeforeMethod
public void setUp() throws Exception {
MockitoAnnotations.openMocks(this).close();;
MockitoAnnotations.openMocks(this).close();
service = new ProjectService(restTemplate, accountService, new GoodDataSettings());
when(accountService.getCurrent()).thenReturn(account);
when(account.getId()).thenReturn(ACCOUNT_ID);
Expand Down Expand Up @@ -218,11 +216,18 @@ public void removeUserFromProjectInvalidAccount(){
service.removeUserFromProject(null, account);
}

@Test(expectedExceptions = GoodDataException.class)
public void removeUserProjectFail() throws URISyntaxException {
@Test(expectedExceptions = GoodDataException.class,
expectedExceptionsMessageRegExp = "500.*r1.*server error")
public void removeUserProjectFailUnexpectedly() throws URISyntaxException {
when(project.getId()).thenReturn("1");
when(account.getId()).thenReturn("1");
doThrow(GoodDataRestException.class).when(restTemplate).delete(new URI("/gdc/projects/1/users/1"));
final GoodDataRestException goodDataRestException = new GoodDataRestException(
HttpStatus.INTERNAL_SERVER_ERROR.value(),
"r1",
"server error",
"component",
"errorClass");
doThrow(goodDataRestException).when(restTemplate).delete(new URI("/gdc/projects/1/users/1"));
service.removeUserFromProject(project, account);
}

Expand All @@ -235,7 +240,7 @@ public void removeUserProjectFailForbidden() throws URISyntaxException {
final GoodDataRestException goodDataRestException = new GoodDataRestException(
HttpStatus.FORBIDDEN.value(),
"r1",
"not allowd",
"forbidden",
"component",
"errorClass");
doThrow(goodDataRestException).when(restTemplate).delete(new URI("/gdc/projects/1/users/1"));
Expand All @@ -252,17 +257,20 @@ public void removeUserProjectFailNotAllowed() throws URISyntaxException {
final GoodDataRestException goodDataRestException = new GoodDataRestException(
HttpStatus.METHOD_NOT_ALLOWED.value() ,
"r1",
"not allowd",
"not allowed",
"component",
"errorClass");
doThrow(goodDataRestException).when(restTemplate).delete(new URI("/gdc/projects/1/users/1"));
service.removeUserFromProject(project, account);
}

@Test(expectedExceptions = GoodDataException.class)
public void removeUserProjectFailRestletClientException() throws URISyntaxException {
@Test(expectedExceptions = GoodDataException.class,
expectedExceptionsMessageRegExp = "Unable to remove account /gdc/account/1 from project /gdc/projects/1")
public void removeUserProjectFailWithRestClientException() throws URISyntaxException {
when(project.getId()).thenReturn("1");
when(project.getUri()).thenReturn("/gdc/projects/1");
when(account.getId()).thenReturn("1");
when(account.getUri()).thenReturn("/gdc/account/1");
doThrow(RestClientException.class).when(restTemplate).delete(new URI("/gdc/projects/1/users/1"));
service.removeUserFromProject(project, account);
}
Expand Down