DataItemQueryController { @GetMapping( value = API_RESOURCE_PATH, produces = APPLICATION_JSON_VALUE ) public ResponseEntity<RootNode> getJson( @RequestParam final Map<String, String> urlParameters, final OrderParams orderParams, final User currentUser ) throws QueryParserException { log.debug( "Looking for data items (JSON response)" ); return getDimensionalItems( currentUser, urlParameters, orderParams ); } DataItemQueryController( final DataItemServiceFacade dataItemServiceFacade,
        final ContextService contextService, final ResponseHandler responseHandler, final AclService aclService ); @GetMapping( value = API_RESOURCE_PATH, produces = APPLICATION_JSON_VALUE ) ResponseEntity<RootNode> getJson( @RequestParam
    final Map<String, String> urlParameters, final OrderParams orderParams, final User currentUser ); @GetMapping( value = API_RESOURCE_PATH + ".xml", produces = APPLICATION_XML_VALUE ) ResponseEntity<RootNode> getXml( @RequestParam
    final Map<String, String> urlParameters, final OrderParams orderParams, final User currentUser );  }
@Test public void testGetWithSuccess() { final Map<String, String> anyUrlParameters = new HashMap<>(); final OrderParams anyOrderParams = new OrderParams(); final User anyUser = new User(); final Set<Class<? extends BaseDimensionalItemObject>> targetEntities = new HashSet<>( asList( Indicator.class ) ); final List<BaseDimensionalItemObject> itemsFound = asList( new Indicator() ); when( dataItemServiceFacade.extractTargetEntities( anyList() ) ).thenReturn( targetEntities ); when( aclService.canRead( anyUser, Indicator.class ) ).thenReturn( true ); when( dataItemServiceFacade.retrieveDataItemEntities( anySet(), anyList(), any( WebOptions.class ), any( OrderParams.class ) ) ).thenReturn( itemsFound ); final ResponseEntity<RootNode> actualResponse = dataItemQueryController.getJson( anyUrlParameters, anyOrderParams, anyUser ); assertThat( actualResponse, is( not( nullValue() ) ) ); assertThat( actualResponse.getStatusCode(), is( FOUND ) ); verify( responseHandler, times( 1 ) ).addResultsToNode( any( RootNode.class ), anyList(), anyList() ); verify( responseHandler, times( 1 ) ).addPaginationToNode( any( RootNode.class ), anyList(), any(), any(), anyList() ); }
@Test public void testGetWhenItemsAreNotFound() { final Map<String, String> anyUrlParameters = new HashMap<>(); final OrderParams anyOrderParams = new OrderParams(); final User anyUser = new User(); final Set<Class<? extends BaseDimensionalItemObject>> targetEntities = new HashSet<>( asList( Indicator.class ) ); final List<BaseDimensionalItemObject> itemsFound = emptyList(); when( dataItemServiceFacade.extractTargetEntities( anyList() ) ).thenReturn( targetEntities ); when( aclService.canRead( anyUser, Indicator.class ) ).thenReturn( true ); when( dataItemServiceFacade.retrieveDataItemEntities( anySet(), anyList(), any( WebOptions.class ), any( OrderParams.class ) ) ).thenReturn( itemsFound ); final ResponseEntity<RootNode> actualResponse = dataItemQueryController.getJson( anyUrlParameters, anyOrderParams, anyUser ); assertThat( actualResponse, is( not( nullValue() ) ) ); assertThat( actualResponse.getStatusCode(), is( NOT_FOUND ) ); verify( responseHandler, times( 1 ) ).addResultsToNode( any(), anyList(), anyList() ); verify( responseHandler, times( 1 ) ).addPaginationToNode( any(), anyList(), any(), any(), anyList() ); }
@Test public void testGetWhenAclIsInvalid() { final Map<String, String> anyUrlParameters = new HashMap<>(); final OrderParams anyOrderParams = new OrderParams(); final User anyUser = new User(); final Set<Class<? extends BaseDimensionalItemObject>> targetEntities = new HashSet<>( asList( Indicator.class ) ); final boolean invalidAcl = false; expectedException.expect( IllegalQueryException.class ); expectedException .expectMessage( containsString( "does not have read access for object" ) ); when( dataItemServiceFacade.extractTargetEntities( anyList() ) ).thenReturn( targetEntities ); when( aclService.canRead( anyUser, Indicator.class ) ).thenReturn( invalidAcl ); dataItemQueryController.getJson( anyUrlParameters, anyOrderParams, anyUser ); }