SearchResourceImpl implements SearchResource { @Override @POST @ValidationRequired(processor = RestViolationProcessor.class) @ApiOperation(value = "Get features according to query", httpMethod="POST", response=FeatureDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Features were found", response=FeatureDTO.class), @ApiResponse(code = 400, message = "Invalid input parameter (header)"), @ApiResponse(code = 400, message = "Query is not correct")}) public Response getFeaturesByQuery(@Auth BasicAuth principal, @ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier, @ApiParam(value = "Query", required = true) @NotBlank @NotNull String query, @ApiParam(required=false,value="Layer",allowableValues="ALL,MAP,FEATURES",defaultValue="ALL") @QueryParam("layer") @DefaultValue("ALL") LayerDTO layer, @ApiParam(required=false,value="Index of page",defaultValue="0") @QueryParam("pageIndex") @DefaultValue("0") Integer pageIndex, @ApiParam(required=false,value="Size of page",defaultValue="20") @QueryParam("pageSize") @DefaultValue("20") Integer pageSize, @ApiParam(required=false,value="Order field") @QueryParam("orderField") String orderField, @ApiParam(required=false,value="Order",allowableValues="ASC,DESC") @DefaultValue("ASC") @QueryParam("order") String order) throws AssemblyException, QueryException { validations.checkIsNotNullAndNotBlank(appIdentifier,query); validations.checkIsNotNull(layer); validations.checkMin(0, pageIndex); validations.checkMin(1, pageSize); Collection<Feature> features = null; if(StringUtils.isEmpty(orderField)){ features = searchManager.getFeaturesByQuery(appIdentifier, query, layer, pageIndex, pageSize); }else{ features = searchManager.getFeaturesByQuery(appIdentifier, query, layer, pageIndex, pageSize, orderField, order); } Collection<FeatureDTO> collectionFeatureDTO=featureAssembler.createDataTransferObjects(features); return Response.ok(collectionFeatureDTO).build(); }  @Override @POST @ValidationRequired(processor = RestViolationProcessor.class) @ApiOperation(value = "Get features according to query", httpMethod="POST", response=FeatureDTO.class, responseContainer = "List") @ApiResponses(value = { @ApiResponse(code = 200, message = "Features were found", response=FeatureDTO.class), @ApiResponse(code = 400, message = "Invalid input parameter (header)"), @ApiResponse(code = 400, message = "Query is not correct")}) Response getFeaturesByQuery(@Auth BasicAuth principal,
			@ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier, 
			@ApiParam(value = "Query", required = true) @NotBlank @NotNull String query, 
			@ApiParam(required=false,value="Layer",allowableValues="ALL,MAP,FEATURES",defaultValue="ALL") @QueryParam("layer") @DefaultValue("ALL") LayerDTO layer,
			@ApiParam(required=false,value="Index of page",defaultValue="0") @QueryParam("pageIndex") @DefaultValue("0") Integer pageIndex, 
			@ApiParam(required=false,value="Size of page",defaultValue="20") @QueryParam("pageSize") @DefaultValue("20") Integer pageSize,
			@ApiParam(required=false,value="Order field") @QueryParam("orderField") String orderField, 
			@ApiParam(required=false,value="Order",allowableValues="ASC,DESC") @DefaultValue("ASC") @QueryParam("order") String order); @Override @Path("/room") @GET @ValidationRequired(processor = RestViolationProcessor.class) @ApiOperation(value = "Get room according to indoor location", httpMethod="GET",response=RoomDTO.class) @ApiResponses(value = { @ApiResponse(code = 200, message = "Room belongs to location", response=RoomDTO.class), @ApiResponse(code = 400, message = "Invalid input parameter"), @ApiResponse(code = 404, message = "Room not found"), @ApiResponse(code = 500, message = "Problem in the system")}) Response getRoomByLocation(@Auth BasicAuth principal,
			@ApiParam(value = "Application identifier", required = true) @NotBlank @NotNull @HeaderParam("api_key") String appIdentifier, 			
			@ApiParam(value="Longitude of location", required=true) @Min(-180) @Max(180) @NotNull @QueryParam("longitude") Double longitude,
			@ApiParam(value="Latitude of location", required=true) @Min(-90) @Max(90) @NotNull @QueryParam("latitude") Double latitude,
			@ApiParam(value = "Floor of location", required = true) @NotNull  @QueryParam("floor") Integer floor);  }
@Test public void getFeaturesByQueryTest() throws AssemblyException, QueryException{ Mockito.when(searchManagerImpl.getFeaturesByQuery(APP_IDENTIFIER,queryJson, layerDTO,pageIndex, pageSize)).thenReturn(collectionFeatures); Mockito.when(featureAssembler.createDataTransferObjects(collectionFeatures)).thenReturn(featuresDTO); Response response = searchResourceImpl.getFeaturesByQuery(principal, APP_IDENTIFIER, queryJson, layerDTO, pageIndex, pageSize, "", order); Mockito.verify(validations).checkIsNotNullAndNotBlank(APP_IDENTIFIER,queryJson); Mockito.verify(validations).checkIsNotNull(layerDTO); Mockito.verify(validations).checkMin(0, pageIndex); Mockito.verify(validations).checkMin(1, pageSize); Mockito.verify(searchManagerImpl).getFeaturesByQuery(APP_IDENTIFIER,queryJson,layerDTO, pageIndex, pageSize); Mockito.verify(featureAssembler).createDataTransferObjects(collectionFeatures); assertNotNull(response.getEntity()); assertEquals("CollectionFeatureDTO is not the expected", featuresDTO, (Collection<FeatureDTO>) response.getEntity()); assertEquals("The Status response is not the expected", 200, response.getStatus()); }
@Test public void getFeaturesByQueryWithOrderTest() throws AssemblyException, QueryException{ Mockito.when(searchManagerImpl.getFeaturesByQuery(APP_IDENTIFIER,queryJson, layerDTO,pageIndex, pageSize, orderField, order)).thenReturn(collectionFeatures); Mockito.when(featureAssembler.createDataTransferObjects(collectionFeatures)).thenReturn(featuresDTO); Response response = searchResourceImpl.getFeaturesByQuery(principal, APP_IDENTIFIER, queryJson, layerDTO, pageIndex, pageSize, orderField, order); Mockito.verify(searchManagerImpl).getFeaturesByQuery(APP_IDENTIFIER,queryJson,layerDTO, pageIndex, pageSize, orderField, order); Mockito.verify(featureAssembler).createDataTransferObjects(collectionFeatures); assertNotNull(response.getEntity()); assertEquals("CollectionFeatureDTO is not the expected", featuresDTO, (Collection<FeatureDTO>) response.getEntity()); assertEquals("The Status response is not the expected", 200, response.getStatus()); }