2424import org .testng .annotations .BeforeMethod ;
2525import org .testng .annotations .Test ;
2626
27- import java .net .MalformedURLException ;
2827import java .net .URI ;
2928import java .net .URISyntaxException ;
30- import java .net .URL ;
3129import java .util .Collection ;
3230
3331import 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