Skip to content

Commit 8f82a92

Browse files
committed
Fine tune ProjectService tests
1 parent bd6abe6 commit 8f82a92

3 files changed

Lines changed: 25 additions & 17 deletions

File tree

gooddata-java/src/test/java/com/gooddata/sdk/service/project/ProjectServiceAT.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import static org.hamcrest.Matchers.is;
3737
import static org.hamcrest.Matchers.not;
3838
import static org.hamcrest.Matchers.notNullValue;
39-
import static org.testng.Assert.fail;
4039

4140
/**
4241
* Project acceptance tests.
@@ -104,14 +103,14 @@ public void listProjectRoles() {
104103

105104
@Test(groups = "project", dependsOnMethods = "createProject")
106105
public void getProjectById() {
107-
final Project project = gd.getProjectService().getProjectById(this.project.getId());
108-
assertThat(project, ProjectIdMatcher.hasSameIdAs(this.project));
106+
final Project result = gd.getProjectService().getProjectById(project.getId());
107+
assertThat(result, ProjectIdMatcher.hasSameIdAs(project));
109108
}
110109

111110
@Test(groups = "project", dependsOnMethods = "createProject")
112111
public void getProjectByUri() {
113-
final Project project = gd.getProjectService().getProjectByUri(this.project.getUri());
114-
assertThat(project, ProjectIdMatcher.hasSameIdAs(this.project));
112+
final Project result = gd.getProjectService().getProjectByUri(project.getUri());
113+
assertThat(result, ProjectIdMatcher.hasSameIdAs(project));
115114
}
116115

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

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

171170
try {

gooddata-java/src/test/java/com/gooddata/sdk/service/project/ProjectServiceIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,8 @@ public void removeUserFromProjectNotFound() {
447447
.havingMethodEqualTo("DELETE")
448448
.havingPathEqualTo(ProjectService.PROJECT_USER_TEMPLATE.expand("PROJECT_ID", "ID").toString())
449449
.respond()
450-
.withStatus(404);
450+
.withStatus(404)
451+
.withBody("{\"error\":{\"parameters\":[\"1234\"],\"requestId\":\"req1\",\"component\":\"GDC::LWP::UserAgent\",\"message\":\"User uid %s doesn't exist.\",\"errorClass\":\"GDC::Exception::NotFound\"}}");
451452

452453
gd.getProjectService().removeUserFromProject(enabled, account);
453454
}

gooddata-java/src/test/java/com/gooddata/sdk/service/project/ProjectServiceTest.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424
import org.testng.annotations.BeforeMethod;
2525
import org.testng.annotations.Test;
2626

27-
import java.net.MalformedURLException;
2827
import java.net.URI;
2928
import java.net.URISyntaxException;
30-
import java.net.URL;
3129
import java.util.Collection;
3230

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

6664
@BeforeMethod
6765
public void setUp() throws Exception {
68-
MockitoAnnotations.openMocks(this).close();;
66+
MockitoAnnotations.openMocks(this).close();
6967
service = new ProjectService(restTemplate, accountService, new GoodDataSettings());
7068
when(accountService.getCurrent()).thenReturn(account);
7169
when(account.getId()).thenReturn(ACCOUNT_ID);
@@ -218,11 +216,18 @@ public void removeUserFromProjectInvalidAccount(){
218216
service.removeUserFromProject(null, account);
219217
}
220218

221-
@Test(expectedExceptions = GoodDataException.class)
222-
public void removeUserProjectFail() throws URISyntaxException {
219+
@Test(expectedExceptions = GoodDataException.class,
220+
expectedExceptionsMessageRegExp = "500.*r1.*server error")
221+
public void removeUserProjectFailUnexpectedly() throws URISyntaxException {
223222
when(project.getId()).thenReturn("1");
224223
when(account.getId()).thenReturn("1");
225-
doThrow(GoodDataRestException.class).when(restTemplate).delete(new URI("/gdc/projects/1/users/1"));
224+
final GoodDataRestException goodDataRestException = new GoodDataRestException(
225+
HttpStatus.INTERNAL_SERVER_ERROR.value(),
226+
"r1",
227+
"server error",
228+
"component",
229+
"errorClass");
230+
doThrow(goodDataRestException).when(restTemplate).delete(new URI("/gdc/projects/1/users/1"));
226231
service.removeUserFromProject(project, account);
227232
}
228233

@@ -235,7 +240,7 @@ public void removeUserProjectFailForbidden() throws URISyntaxException {
235240
final GoodDataRestException goodDataRestException = new GoodDataRestException(
236241
HttpStatus.FORBIDDEN.value(),
237242
"r1",
238-
"not allowd",
243+
"forbidden",
239244
"component",
240245
"errorClass");
241246
doThrow(goodDataRestException).when(restTemplate).delete(new URI("/gdc/projects/1/users/1"));
@@ -252,17 +257,20 @@ public void removeUserProjectFailNotAllowed() throws URISyntaxException {
252257
final GoodDataRestException goodDataRestException = new GoodDataRestException(
253258
HttpStatus.METHOD_NOT_ALLOWED.value() ,
254259
"r1",
255-
"not allowd",
260+
"not allowed",
256261
"component",
257262
"errorClass");
258263
doThrow(goodDataRestException).when(restTemplate).delete(new URI("/gdc/projects/1/users/1"));
259264
service.removeUserFromProject(project, account);
260265
}
261266

262-
@Test(expectedExceptions = GoodDataException.class)
263-
public void removeUserProjectFailRestletClientException() throws URISyntaxException {
267+
@Test(expectedExceptions = GoodDataException.class,
268+
expectedExceptionsMessageRegExp = "Unable to remove account /gdc/account/1 from project /gdc/projects/1")
269+
public void removeUserProjectFailWithRestClientException() throws URISyntaxException {
264270
when(project.getId()).thenReturn("1");
271+
when(project.getUri()).thenReturn("/gdc/projects/1");
265272
when(account.getId()).thenReturn("1");
273+
when(account.getUri()).thenReturn("/gdc/account/1");
266274
doThrow(RestClientException.class).when(restTemplate).delete(new URI("/gdc/projects/1/users/1"));
267275
service.removeUserFromProject(project, account);
268276
}

0 commit comments

Comments
 (0)