1010import com .gooddata .GoodDataSettings ;
1111import com .gooddata .gdc .UriResponse ;
1212import com .gooddata .md .report .ReportDefinition ;
13+ import com .gooddata .md .visualization .VisualizationClass ;
1314import com .gooddata .project .Project ;
1415import org .mockito .Matchers ;
1516import org .mockito .Mock ;
3233import static org .hamcrest .CoreMatchers .notNullValue ;
3334import static org .hamcrest .MatcherAssert .assertThat ;
3435import static org .hamcrest .collection .IsCollectionWithSize .hasSize ;
36+ import static org .mockito .Matchers .any ;
37+ import static org .mockito .Matchers .anyString ;
3538import static org .mockito .Matchers .eq ;
3639import static org .mockito .Mockito .doThrow ;
3740import static org .mockito .Mockito .mock ;
@@ -276,7 +279,7 @@ public void testGetObjUriToFindOneObjByTitle() throws Exception {
276279 final Entry resultEntry = mock (Entry .class );
277280 final String uri = "myURI" ;
278281 final String title = "myTitle" ;
279- when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryable " )).thenReturn (queryResult );
282+ when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryables " )).thenReturn (queryResult );
280283 when (queryResult .getEntries ()).thenReturn (asList (resultEntry ));
281284 when (resultEntry .getTitle ()).thenReturn (title );
282285 when (resultEntry .getUri ()).thenReturn (uri );
@@ -290,7 +293,7 @@ public void testGetObjUriMoreThanOneResult() throws Exception {
290293 final Query queryResult = mock (Query .class );
291294 final Entry resultEntry1 = mock (Entry .class );
292295 final Entry resultEntry2 = mock (Entry .class );
293- when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryable " )).thenReturn (queryResult );
296+ when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryables " )).thenReturn (queryResult );
294297 when (queryResult .getEntries ()).thenReturn (asList (resultEntry1 , resultEntry2 ));
295298
296299 service .getObjUri (project , Queryable .class );
@@ -301,7 +304,7 @@ public void testGetObjUriNothingFound() throws Exception {
301304 final Query queryResult = mock (Query .class );
302305 final Entry resultEntry = mock (Entry .class );
303306 final String title = "myTitle" ;
304- when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryable " )).thenReturn (queryResult );
307+ when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryables " )).thenReturn (queryResult );
305308 when (queryResult .getEntries ()).thenReturn (asList (resultEntry ));
306309
307310 service .getObjUri (project , Queryable .class , Restriction .title (title ));
@@ -314,7 +317,7 @@ public void testGetObjToFindOneObjById() throws Exception {
314317 final Entry resultEntry = mock (Entry .class );
315318 final String uri = "myURI" ;
316319 final String id = "myId" ;
317- when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryable " )).thenReturn (queryResult );
320+ when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryables " )).thenReturn (queryResult );
318321 when (queryResult .getEntries ()).thenReturn (asList (resultEntry ));
319322 when (resultEntry .getIdentifier ()).thenReturn (id );
320323 when (resultEntry .getUri ()).thenReturn (uri );
@@ -329,7 +332,7 @@ public void testGetObjMoreThanOneResult() throws Exception {
329332 final Query queryResult = mock (Query .class );
330333 final Entry resultEntry1 = mock (Entry .class );
331334 final Entry resultEntry2 = mock (Entry .class );
332- when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryable " )).thenReturn (queryResult );
335+ when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryables " )).thenReturn (queryResult );
333336 when (queryResult .getEntries ()).thenReturn (asList (resultEntry1 , resultEntry2 ));
334337
335338 service .getObj (project , Queryable .class );
@@ -340,7 +343,7 @@ public void testGetObjNothingFound() throws Exception {
340343 final Query queryResult = mock (Query .class );
341344 final Entry resultEntry = mock (Entry .class );
342345 final String title = "myTitle" ;
343- when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryable " )).thenReturn (queryResult );
346+ when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryables " )).thenReturn (queryResult );
344347 when (queryResult .getEntries ()).thenReturn (asList (resultEntry ));
345348
346349 service .getObj (project , Queryable .class , Restriction .title (title ));
@@ -351,16 +354,27 @@ public void testFindMoreResults() throws Exception {
351354 final Query queryResult = mock (Query .class );
352355 final Entry resultEntry1 = mock (Entry .class );
353356 final Entry resultEntry2 = mock (Entry .class );
354- when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryable " )).thenReturn (queryResult );
357+ when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryables " )).thenReturn (queryResult );
355358 when (queryResult .getEntries ()).thenReturn (asList (resultEntry1 , resultEntry2 ));
356359
357360 final Collection <Entry > results = service .find (project , Queryable .class );
358361 assertThat (results , allOf (hasItem (resultEntry1 ), hasItem (resultEntry2 )));
359362 }
360363
364+ @ Test
365+ public void testFindIrregularQueryTypeNames () {
366+ when (restTemplate .getForObject (anyString (), any (), anyString (), anyString ())).thenReturn (mock (Query .class ));
367+
368+ service .find (project , ReportDefinition .class );
369+ verify (restTemplate ).getForObject (Query .URI , Query .class , project .getId (), "reportdefinition" );
370+
371+ service .find (project , VisualizationClass .class );
372+ verify (restTemplate ).getForObject (Query .URI , Query .class , project .getId (), "visualizationclasses" );
373+ }
374+
361375 @ Test (expectedExceptions = GoodDataException .class )
362376 public void testFindWithWithClientSideHTTPError () throws Exception {
363- when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryable " )).thenThrow (new RestClientException ("" ));
377+ when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryables " )).thenThrow (new RestClientException ("" ));
364378 service .find (project , Queryable .class );
365379 }
366380
@@ -372,7 +386,7 @@ public void testFindUrisBySummary() throws Exception {
372386 final String summary = "mySummary" ;
373387 final String uri1 = "uri1" ;
374388 final String uri2 = "uri2" ;
375- when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryable " )).thenReturn (queryResult );
389+ when (restTemplate .getForObject (Query .URI , Query .class , project .getId (), "queryables " )).thenReturn (queryResult );
376390 when (queryResult .getEntries ()).thenReturn (asList (resultEntry1 , resultEntry2 ));
377391 when (resultEntry1 .getSummary ()).thenReturn (summary );
378392 when (resultEntry2 .getSummary ()).thenReturn (summary );
0 commit comments