@Test public void testProcessRequestFailsValidationDueToMissingId() { Configuration configuration = new SystemPropertiesConfiguration(); IncomingSearchRequestTranslator translator = mock(IncomingSearchRequestTranslator.class); RelatedContentSearchRequestProcessorHandler hanlder = mock(RelatedContentSearchRequestProcessorHandler.class); SearchRequestParameterValidatorLocator validatorFactory = new MapBasedSearchRequestParameterValidatorLookup(configuration); processor = new DisruptorBasedSearchRequestProcessor(translator, hanlder,new RelatedItemSearchRequestFactory(configuration),configuration,validatorFactory); SearchRequestSubmissionStatus status = processor.processRequest(RelatedItemSearchType.FREQUENTLY_RELATED_WITH,new HashMap<String,String>(),null); assertEquals(SearchRequestSubmissionStatus.REQUEST_VALIDATION_FAILURE,status); verify(translator, times(0)).translateTo(any(RelatedItemSearchRequest.class), anyLong(), any(RelatedItemSearchType.class), anyMap(), any(SearchResponseContext[].class)); }
@Override public SearchRequestSubmissionStatus processRequest(RelatedItemSearchType requestType, Map<String,String> parameters, SearchResponseContext[] context) { SearchRequestParameterValidator validator = requestValidators.getValidatorForType(requestType); if(validator !=null) { ValidationMessage isValid = validator.validateParameters(parameters); if(!isValid.isValid()) { log.warn("Invalid parameter :{} for search request type {}",isValid.getInvalidProperty(), requestType); return SearchRequestSubmissionStatus.REQUEST_VALIDATION_FAILURE; } } log.debug("Processing requesttype {} with parameters {}",requestType,parameters); boolean published = ringBuffer.tryPublishEvent(searchRequestTranslator, requestType, parameters, context); if(published) return SearchRequestSubmissionStatus.PROCESSING; else return SearchRequestSubmissionStatus.PROCESSING_REJECTED_AT_MAX_CAPACITY; }
DisruptorBasedSearchRequestProcessor implements RelatedItemSearchRequestProcessor { @Override public SearchRequestSubmissionStatus processRequest(RelatedItemSearchType requestType, Map<String,String> parameters, SearchResponseContext[] context) { SearchRequestParameterValidator validator = requestValidators.getValidatorForType(requestType); if(validator !=null) { ValidationMessage isValid = validator.validateParameters(parameters); if(!isValid.isValid()) { log.warn("Invalid parameter :{} for search request type {}",isValid.getInvalidProperty(), requestType); return SearchRequestSubmissionStatus.REQUEST_VALIDATION_FAILURE; } } log.debug("Processing requesttype {} with parameters {}",requestType,parameters); boolean published = ringBuffer.tryPublishEvent(searchRequestTranslator, requestType, parameters, context); if(published) return SearchRequestSubmissionStatus.PROCESSING; else return SearchRequestSubmissionStatus.PROCESSING_REJECTED_AT_MAX_CAPACITY; } }
DisruptorBasedSearchRequestProcessor implements RelatedItemSearchRequestProcessor { @Override public SearchRequestSubmissionStatus processRequest(RelatedItemSearchType requestType, Map<String,String> parameters, SearchResponseContext[] context) { SearchRequestParameterValidator validator = requestValidators.getValidatorForType(requestType); if(validator !=null) { ValidationMessage isValid = validator.validateParameters(parameters); if(!isValid.isValid()) { log.warn("Invalid parameter :{} for search request type {}",isValid.getInvalidProperty(), requestType); return SearchRequestSubmissionStatus.REQUEST_VALIDATION_FAILURE; } } log.debug("Processing requesttype {} with parameters {}",requestType,parameters); boolean published = ringBuffer.tryPublishEvent(searchRequestTranslator, requestType, parameters, context); if(published) return SearchRequestSubmissionStatus.PROCESSING; else return SearchRequestSubmissionStatus.PROCESSING_REJECTED_AT_MAX_CAPACITY; } DisruptorBasedSearchRequestProcessor(IncomingSearchRequestTranslator searchRequestTranslator ,
                                                RelatedContentSearchRequestProcessorHandler eventHandler,
                                                RelatedItemSearchRequestFactory relatedItemSearchRequestFactory,
                                                Configuration configuration,
                                                SearchRequestParameterValidatorLocator searchRequestValidator); }
DisruptorBasedSearchRequestProcessor implements RelatedItemSearchRequestProcessor { @Override public SearchRequestSubmissionStatus processRequest(RelatedItemSearchType requestType, Map<String,String> parameters, SearchResponseContext[] context) { SearchRequestParameterValidator validator = requestValidators.getValidatorForType(requestType); if(validator !=null) { ValidationMessage isValid = validator.validateParameters(parameters); if(!isValid.isValid()) { log.warn("Invalid parameter :{} for search request type {}",isValid.getInvalidProperty(), requestType); return SearchRequestSubmissionStatus.REQUEST_VALIDATION_FAILURE; } } log.debug("Processing requesttype {} with parameters {}",requestType,parameters); boolean published = ringBuffer.tryPublishEvent(searchRequestTranslator, requestType, parameters, context); if(published) return SearchRequestSubmissionStatus.PROCESSING; else return SearchRequestSubmissionStatus.PROCESSING_REJECTED_AT_MAX_CAPACITY; } DisruptorBasedSearchRequestProcessor(IncomingSearchRequestTranslator searchRequestTranslator ,
                                                RelatedContentSearchRequestProcessorHandler eventHandler,
                                                RelatedItemSearchRequestFactory relatedItemSearchRequestFactory,
                                                Configuration configuration,
                                                SearchRequestParameterValidatorLocator searchRequestValidator); @Override SearchRequestSubmissionStatus processRequest(RelatedItemSearchType requestType, Map<String,String> parameters, SearchResponseContext[] context); @PreDestroy void shutdown(); }
DisruptorBasedSearchRequestProcessor implements RelatedItemSearchRequestProcessor { @Override public SearchRequestSubmissionStatus processRequest(RelatedItemSearchType requestType, Map<String,String> parameters, SearchResponseContext[] context) { SearchRequestParameterValidator validator = requestValidators.getValidatorForType(requestType); if(validator !=null) { ValidationMessage isValid = validator.validateParameters(parameters); if(!isValid.isValid()) { log.warn("Invalid parameter :{} for search request type {}",isValid.getInvalidProperty(), requestType); return SearchRequestSubmissionStatus.REQUEST_VALIDATION_FAILURE; } } log.debug("Processing requesttype {} with parameters {}",requestType,parameters); boolean published = ringBuffer.tryPublishEvent(searchRequestTranslator, requestType, parameters, context); if(published) return SearchRequestSubmissionStatus.PROCESSING; else return SearchRequestSubmissionStatus.PROCESSING_REJECTED_AT_MAX_CAPACITY; } DisruptorBasedSearchRequestProcessor(IncomingSearchRequestTranslator searchRequestTranslator ,
                                                RelatedContentSearchRequestProcessorHandler eventHandler,
                                                RelatedItemSearchRequestFactory relatedItemSearchRequestFactory,
                                                Configuration configuration,
                                                SearchRequestParameterValidatorLocator searchRequestValidator); @Override SearchRequestSubmissionStatus processRequest(RelatedItemSearchType requestType, Map<String,String> parameters, SearchResponseContext[] context); @PreDestroy void shutdown();  }