idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
28,300 | public GroovyActionBuilder script ( Resource scriptResource , Charset charset ) { try { action . setScript ( FileUtils . readToString ( scriptResource , charset ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read script resource file" , e ) ; } return this ; } | Sets the Groovy script to execute . |
28,301 | public GroovyActionBuilder template ( Resource scriptTemplate , Charset charset ) { try { action . setScriptTemplate ( FileUtils . readToString ( scriptTemplate , charset ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read script template file" , e ) ; } return this ; } | Use a script template resource . |
28,302 | private Object getObjectInstanceFromClass ( TestContext context ) throws ClassNotFoundException , SecurityException , NoSuchMethodException , IllegalArgumentException , InstantiationException , IllegalAccessException , InvocationTargetException { if ( ! StringUtils . hasText ( className ) ) { throw new CitrusRuntimeException ( "Neither class name nor object instance reference " + "is set for Java reflection call" ) ; } log . info ( "Instantiating class for name '" + className + "'" ) ; Class < ? > classToRun = Class . forName ( className ) ; Class < ? > [ ] constructorTypes = new Class < ? > [ constructorArgs . size ( ) ] ; Object [ ] constructorObjects = new Object [ constructorArgs . size ( ) ] ; for ( int i = 0 ; i < constructorArgs . size ( ) ; i ++ ) { constructorTypes [ i ] = constructorArgs . get ( i ) . getClass ( ) ; if ( constructorArgs . get ( i ) . getClass ( ) . equals ( String . class ) ) { constructorObjects [ i ] = context . replaceDynamicContentInString ( constructorArgs . get ( i ) . toString ( ) ) ; } else { constructorObjects [ i ] = constructorArgs . get ( i ) ; } } Constructor < ? > constr = classToRun . getConstructor ( constructorTypes ) ; return constr . newInstance ( constructorObjects ) ; } | Instantiate class for name . Constructor arguments are supported if specified . |
28,303 | public void onInboundMessage ( Message message , TestContext context ) { if ( message != null ) { for ( MessageListener listener : messageListener ) { listener . onInboundMessage ( message , context ) ; } } } | Delegate to all known message listener instances . |
28,304 | private String removeCDataElements ( String value ) { String data = value . trim ( ) ; if ( data . startsWith ( CDATA_SECTION_START ) ) { data = value . substring ( CDATA_SECTION_START . length ( ) ) ; data = data . substring ( 0 , data . length ( ) - CDATA_SECTION_END . length ( ) ) ; } return data ; } | Cut off CDATA elements . |
28,305 | public void afterPropertiesSet ( ) throws Exception { for ( MessageValidator < ? extends ValidationContext > messageValidator : messageValidatorRegistry . getMessageValidators ( ) ) { if ( messageValidator instanceof DomXmlMessageValidator && messageValidator . supportsMessageType ( MessageType . XML . name ( ) , new DefaultMessage ( "" ) ) ) { xmlMessageValidator = ( DomXmlMessageValidator ) messageValidator ; } } if ( xmlMessageValidator == null ) { LOG . warn ( "No XML message validator found in Spring bean context - setting default validator" ) ; xmlMessageValidator = new DomXmlMessageValidator ( ) ; xmlMessageValidator . setApplicationContext ( applicationContext ) ; } } | Initialize xml message validator if not injected by Spring bean context . |
28,306 | private String appendRequestPath ( String uri , Map < String , Object > headers ) { if ( ! headers . containsKey ( REQUEST_PATH_HEADER_NAME ) ) { return uri ; } String requestUri = uri ; String path = headers . get ( REQUEST_PATH_HEADER_NAME ) . toString ( ) ; while ( requestUri . endsWith ( "/" ) ) { requestUri = requestUri . substring ( 0 , requestUri . length ( ) - 1 ) ; } while ( path . startsWith ( "/" ) && path . length ( ) > 0 ) { path = path . length ( ) == 1 ? "" : path . substring ( 1 ) ; } return requestUri + "/" + path ; } | Appends optional request path to endpoint uri . |
28,307 | public void saveReplyDestination ( JmsMessage jmsMessage , TestContext context ) { if ( jmsMessage . getReplyTo ( ) != null ) { String correlationKeyName = endpointConfiguration . getCorrelator ( ) . getCorrelationKeyName ( getName ( ) ) ; String correlationKey = endpointConfiguration . getCorrelator ( ) . getCorrelationKey ( jmsMessage ) ; correlationManager . saveCorrelationKey ( correlationKeyName , correlationKey , context ) ; correlationManager . store ( correlationKey , jmsMessage . getReplyTo ( ) ) ; } else { log . warn ( "Unable to retrieve reply to destination for message \n" + jmsMessage + "\n - no reply to destination found in message headers!" ) ; } } | Store the reply destination either straight forward or with a given message correlation key . |
28,308 | protected void validateAttachmentContentData ( String receivedContent , String controlContent , String controlContentId ) { if ( ignoreAllWhitespaces ) { controlContent = StringUtils . trimAllWhitespace ( controlContent ) ; receivedContent = StringUtils . trimAllWhitespace ( receivedContent ) ; } Assert . isTrue ( receivedContent . equals ( controlContent ) , "Values not equal for attachment content '" + controlContentId + "', expected '" + controlContent . trim ( ) + "' but was '" + receivedContent . trim ( ) + "'" ) ; } | Validates content data . |
28,309 | public RmiServerBuilder remoteInterfaces ( Class < ? extends Remote > ... remoteInterfaces ) { endpoint . setRemoteInterfaces ( Arrays . asList ( remoteInterfaces ) ) ; return this ; } | Sets the remote interfaces property . |
28,310 | private void sendOrPublishMessage ( Message message ) { if ( endpointConfiguration . isPubSubDomain ( ) ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Publish Vert.x event bus message to address: '" + endpointConfiguration . getAddress ( ) + "'" ) ; } vertx . eventBus ( ) . publish ( endpointConfiguration . getAddress ( ) , message . getPayload ( ) ) ; } else { if ( log . isDebugEnabled ( ) ) { log . debug ( "Sending Vert.x event bus message to address: '" + endpointConfiguration . getAddress ( ) + "'" ) ; } vertx . eventBus ( ) . send ( endpointConfiguration . getAddress ( ) , message . getPayload ( ) ) ; } } | Sends or publishes new outbound message depending on eventbus nature . |
28,311 | public Type [ ] getParameterTypes ( ) { Type [ ] types = new Type [ parameterNames . size ( ) ] ; for ( int i = 0 ; i < types . length ; i ++ ) { types [ i ] = String . class ; } return types ; } | Provide parameter types for this step . |
28,312 | public Message < ? > receive ( MessageSelector selector ) { Object [ ] array = this . queue . toArray ( ) ; for ( Object o : array ) { Message < ? > message = ( Message < ? > ) o ; if ( selector . accept ( message ) && this . queue . remove ( message ) ) { return message ; } } return null ; } | Supports selective consumption of messages on the channel . The first message to be accepted by given message selector is returned as result . |
28,313 | public Message < ? > receive ( MessageSelector selector , long timeout ) { long timeLeft = timeout ; Message < ? > message = receive ( selector ) ; while ( message == null && timeLeft > 0 ) { timeLeft -= pollingInterval ; if ( RETRY_LOG . isDebugEnabled ( ) ) { RETRY_LOG . debug ( "No message received with message selector - retrying in " + ( timeLeft > 0 ? pollingInterval : pollingInterval + timeLeft ) + "ms" ) ; } try { Thread . sleep ( timeLeft > 0 ? pollingInterval : pollingInterval + timeLeft ) ; } catch ( InterruptedException e ) { RETRY_LOG . warn ( "Thread interrupted while waiting for retry" , e ) ; } message = receive ( selector ) ; } return message ; } | Consume messages on the channel via message selector . Timeout forces several retries with polling interval setting . |
28,314 | public void setInterceptors ( List < ClientInterceptor > interceptors ) { this . interceptors = interceptors ; getWebServiceTemplate ( ) . setInterceptors ( interceptors . toArray ( new ClientInterceptor [ interceptors . size ( ) ] ) ) ; } | Sets the client interceptors . |
28,315 | protected String randomValue ( List < String > values ) { if ( values == null || values . isEmpty ( ) ) { throw new InvalidFunctionUsageException ( "No values to choose from" ) ; } final int idx = random . nextInt ( values . size ( ) ) ; return values . get ( idx ) ; } | Pseudo - randomly choose one of the supplied values and return it . |
28,316 | public SeleniumActionBuilder navigate ( String page ) { NavigateAction action = new NavigateAction ( ) ; action . setPage ( page ) ; action ( action ) ; return this ; } | Navigate action . |
28,317 | public ElementActionBuilder select ( String option ) { DropDownSelectAction action = new DropDownSelectAction ( ) ; action . setOption ( option ) ; action ( action ) ; return new ElementActionBuilder ( action ) ; } | Dropdown select single option action . |
28,318 | public ElementActionBuilder select ( String ... options ) { DropDownSelectAction action = new DropDownSelectAction ( ) ; action . setOptions ( Arrays . asList ( options ) ) ; action ( action ) ; return new ElementActionBuilder ( action ) ; } | Dropdown select multiple options action . |
28,319 | public ElementActionBuilder setInput ( String value ) { SetInputAction action = new SetInputAction ( ) ; action . setValue ( value ) ; action ( action ) ; return new ElementActionBuilder ( action ) ; } | Set input action . |
28,320 | public ElementActionBuilder checkInput ( boolean checked ) { CheckInputAction action = new CheckInputAction ( ) ; action . setChecked ( checked ) ; action ( action ) ; return new ElementActionBuilder ( action ) ; } | Check input action . |
28,321 | public SeleniumActionBuilder screenshot ( String outputDir ) { MakeScreenshotAction action = new MakeScreenshotAction ( ) ; action . setOutputDir ( outputDir ) ; action ( action ) ; return this ; } | Make screenshot with custom output directory . |
28,322 | public SeleniumActionBuilder store ( String filePath ) { StoreFileAction action = new StoreFileAction ( ) ; action . setFilePath ( filePath ) ; action ( action ) ; return this ; } | Store file . |
28,323 | public SeleniumActionBuilder getStored ( String fileName ) { GetStoredFileAction action = new GetStoredFileAction ( ) ; action . setFileName ( fileName ) ; action ( action ) ; return this ; } | Get stored file . |
28,324 | private < T extends SeleniumAction > T action ( T delegate ) { if ( seleniumBrowser != null ) { delegate . setBrowser ( seleniumBrowser ) ; } action . setDelegate ( delegate ) ; return delegate ; } | Prepare selenium action . |
28,325 | public Message createMessage ( final String messageName ) { final Message [ ] message = { null } ; for ( final Object messageCreator : messageCreators ) { ReflectionUtils . doWithMethods ( messageCreator . getClass ( ) , new ReflectionUtils . MethodCallback ( ) { public void doWith ( Method method ) throws IllegalArgumentException , IllegalAccessException { if ( method . getAnnotation ( MessageCreator . class ) . value ( ) . equals ( messageName ) ) { try { message [ 0 ] = ( Message ) method . invoke ( messageCreator ) ; } catch ( InvocationTargetException e ) { throw new CitrusRuntimeException ( "Unsupported message creator method: " + method . getName ( ) , e ) ; } } } } , new ReflectionUtils . MethodFilter ( ) { public boolean matches ( Method method ) { return method . getAnnotationsByType ( MessageCreator . class ) . length > 0 ; } } ) ; } if ( message [ 0 ] == null ) { throw new CitrusRuntimeException ( "Unable to find message creator for message: " + messageName ) ; } return message [ 0 ] ; } | Create message by delegating message creation to known message creators that are able to create message with given name . |
28,326 | public void addType ( String type ) { try { messageCreators . add ( Class . forName ( type ) . newInstance ( ) ) ; } catch ( ClassNotFoundException | IllegalAccessException e ) { throw new CitrusRuntimeException ( "Unable to access message creator type: " + type , e ) ; } catch ( InstantiationException e ) { throw new CitrusRuntimeException ( "Unable to create message creator instance of type: " + type , e ) ; } } | Adds new message creator POJO instance from type . |
28,327 | private boolean checkAnswer ( String input ) { StringTokenizer tok = new StringTokenizer ( validAnswers , ANSWER_SEPARATOR ) ; while ( tok . hasMoreTokens ( ) ) { if ( tok . nextElement ( ) . toString ( ) . trim ( ) . equalsIgnoreCase ( input . trim ( ) ) ) { return true ; } } log . info ( "User input is not valid - must be one of " + validAnswers ) ; return false ; } | Validate given input according to valid answer tokens . |
28,328 | public T message ( Message controlMessage ) { StaticMessageContentBuilder staticMessageContentBuilder = StaticMessageContentBuilder . withMessage ( controlMessage ) ; staticMessageContentBuilder . setMessageHeaders ( getMessageContentBuilder ( ) . getMessageHeaders ( ) ) ; getAction ( ) . setMessageBuilder ( staticMessageContentBuilder ) ; return self ; } | Expect a control message in this receive action . |
28,329 | protected void setPayload ( String payload ) { MessageContentBuilder messageContentBuilder = getMessageContentBuilder ( ) ; if ( messageContentBuilder instanceof PayloadTemplateMessageBuilder ) { ( ( PayloadTemplateMessageBuilder ) messageContentBuilder ) . setPayloadData ( payload ) ; } else if ( messageContentBuilder instanceof StaticMessageContentBuilder ) { ( ( StaticMessageContentBuilder ) messageContentBuilder ) . getMessage ( ) . setPayload ( payload ) ; } else { throw new CitrusRuntimeException ( "Unable to set payload on message builder type: " + messageContentBuilder . getClass ( ) ) ; } } | Sets the payload data on the message builder implementation . |
28,330 | public T payload ( Resource payloadResource , Charset charset ) { try { setPayload ( FileUtils . readToString ( payloadResource , charset ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read payload resource" , e ) ; } return self ; } | Expect this message payload data in received message . |
28,331 | public T payload ( Object payload , Marshaller marshaller ) { StringResult result = new StringResult ( ) ; try { marshaller . marshal ( payload , result ) ; } catch ( XmlMappingException e ) { throw new CitrusRuntimeException ( "Failed to marshal object graph for message payload" , e ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to marshal object graph for message payload" , e ) ; } setPayload ( result . toString ( ) ) ; return self ; } | Expect this message payload as model object which is marshalled to a character sequence using the default object to xml mapper before validation is performed . |
28,332 | public T payload ( Object payload , ObjectMapper objectMapper ) { try { setPayload ( objectMapper . writer ( ) . writeValueAsString ( payload ) ) ; } catch ( JsonProcessingException e ) { throw new CitrusRuntimeException ( "Failed to map object graph for message payload" , e ) ; } return self ; } | Expect this message payload as model object which is mapped to a character sequence using the default object to json mapper before validation is performed . |
28,333 | public T payloadModel ( Object payload ) { Assert . notNull ( applicationContext , "Citrus application context is not initialized!" ) ; if ( ! CollectionUtils . isEmpty ( applicationContext . getBeansOfType ( Marshaller . class ) ) ) { return payload ( payload , applicationContext . getBean ( Marshaller . class ) ) ; } else if ( ! CollectionUtils . isEmpty ( applicationContext . getBeansOfType ( ObjectMapper . class ) ) ) { return payload ( payload , applicationContext . getBean ( ObjectMapper . class ) ) ; } throw new CitrusRuntimeException ( "Unable to find default object mapper or marshaller in application context" ) ; } | Expect this message payload as model object which is marshalled to a character sequence using the default object to xml mapper that is available in Spring bean application context . |
28,334 | public T header ( String name , Object value ) { getMessageContentBuilder ( ) . getMessageHeaders ( ) . put ( name , value ) ; return self ; } | Expect this message header entry in received message . |
28,335 | public T headers ( Map < String , Object > headers ) { getMessageContentBuilder ( ) . getMessageHeaders ( ) . putAll ( headers ) ; return self ; } | Expect this message header entries in received message . |
28,336 | public T headerFragment ( Object model ) { Assert . notNull ( applicationContext , "Citrus application context is not initialized!" ) ; if ( ! CollectionUtils . isEmpty ( applicationContext . getBeansOfType ( Marshaller . class ) ) ) { return headerFragment ( model , applicationContext . getBean ( Marshaller . class ) ) ; } else if ( ! CollectionUtils . isEmpty ( applicationContext . getBeansOfType ( ObjectMapper . class ) ) ) { return headerFragment ( model , applicationContext . getBean ( ObjectMapper . class ) ) ; } throw new CitrusRuntimeException ( "Unable to find default object mapper or marshaller in application context" ) ; } | Expect this message header data as model object which is marshalled to a character sequence using the default object to xml mapper that is available in Spring bean application context . |
28,337 | public T headerFragment ( Object model , String mapperName ) { Assert . notNull ( applicationContext , "Citrus application context is not initialized!" ) ; if ( applicationContext . containsBean ( mapperName ) ) { Object mapper = applicationContext . getBean ( mapperName ) ; if ( Marshaller . class . isAssignableFrom ( mapper . getClass ( ) ) ) { return headerFragment ( model , ( Marshaller ) mapper ) ; } else if ( ObjectMapper . class . isAssignableFrom ( mapper . getClass ( ) ) ) { return headerFragment ( model , ( ObjectMapper ) mapper ) ; } else { throw new CitrusRuntimeException ( String . format ( "Invalid bean type for mapper '%s' expected ObjectMapper or Marshaller but was '%s'" , mapperName , mapper . getClass ( ) ) ) ; } } throw new CitrusRuntimeException ( "Unable to find default object mapper or marshaller in application context" ) ; } | Expect this message header data as model object which is marshalled to a character sequence using the given object to xml mapper that is accessed by its bean name in Spring bean application context . |
28,338 | public T headerFragment ( Object model , Marshaller marshaller ) { StringResult result = new StringResult ( ) ; try { marshaller . marshal ( model , result ) ; } catch ( XmlMappingException e ) { throw new CitrusRuntimeException ( "Failed to marshal object graph for message header data" , e ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to marshal object graph for message header data" , e ) ; } return header ( result . toString ( ) ) ; } | Expect this message header data as model object which is marshalled to a character sequence using the default object to xml mapper before validation is performed . |
28,339 | public T headerFragment ( Object model , ObjectMapper objectMapper ) { try { return header ( objectMapper . writer ( ) . writeValueAsString ( model ) ) ; } catch ( JsonProcessingException e ) { throw new CitrusRuntimeException ( "Failed to map object graph for message header data" , e ) ; } } | Expect this message header data as model object which is mapped to a character sequence using the default object to json mapper before validation is performed . |
28,340 | public T header ( Resource resource , Charset charset ) { try { getMessageContentBuilder ( ) . getHeaderData ( ) . add ( FileUtils . readToString ( resource , charset ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read header resource" , e ) ; } return self ; } | Expect this message header data in received message from file resource . Message header data is used in SOAP messages as XML fragment for instance . |
28,341 | public T validateScript ( Resource scriptResource , Charset charset ) { try { validateScript ( FileUtils . readToString ( scriptResource , charset ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read script resource file" , e ) ; } return self ; } | Reads validation script file resource and sets content as validation script . |
28,342 | public T messageType ( String messageType ) { this . messageType = messageType ; getAction ( ) . setMessageType ( messageType ) ; if ( getAction ( ) . getValidationContexts ( ) . isEmpty ( ) ) { getAction ( ) . getValidationContexts ( ) . add ( headerValidationContext ) ; getAction ( ) . getValidationContexts ( ) . add ( xmlMessageValidationContext ) ; getAction ( ) . getValidationContexts ( ) . add ( jsonMessageValidationContext ) ; } return self ; } | Sets a explicit message type for this receive action . |
28,343 | public T validateNamespace ( String prefix , String namespaceUri ) { xmlMessageValidationContext . getControlNamespaces ( ) . put ( prefix , namespaceUri ) ; return self ; } | Validates XML namespace with prefix and uri . |
28,344 | public T validate ( String path , Object controlValue ) { if ( JsonPathMessageValidationContext . isJsonPathExpression ( path ) ) { getJsonPathValidationContext ( ) . getJsonPathExpressions ( ) . put ( path , controlValue ) ; } else { getXPathValidationContext ( ) . getXpathExpressions ( ) . put ( path , controlValue ) ; } return self ; } | Adds message element validation . |
28,345 | public T ignore ( String path ) { if ( messageType . equalsIgnoreCase ( MessageType . XML . name ( ) ) || messageType . equalsIgnoreCase ( MessageType . XHTML . name ( ) ) ) { xmlMessageValidationContext . getIgnoreExpressions ( ) . add ( path ) ; } else if ( messageType . equalsIgnoreCase ( MessageType . JSON . name ( ) ) ) { jsonMessageValidationContext . getIgnoreExpressions ( ) . add ( path ) ; } return self ; } | Adds ignore path expression for message element . |
28,346 | public T xpath ( String xPathExpression , Object controlValue ) { validate ( xPathExpression , controlValue ) ; return self ; } | Adds XPath message element validation . |
28,347 | public T jsonPath ( String jsonPathExpression , Object controlValue ) { validate ( jsonPathExpression , controlValue ) ; return self ; } | Adds JsonPath message element validation . |
28,348 | public T namespace ( String prefix , String namespaceUri ) { getXpathVariableExtractor ( ) . getNamespaces ( ) . put ( prefix , namespaceUri ) ; xmlMessageValidationContext . getNamespaces ( ) . put ( prefix , namespaceUri ) ; return self ; } | Adds explicit namespace declaration for later path validation expressions . |
28,349 | public T namespaces ( Map < String , String > namespaceMappings ) { getXpathVariableExtractor ( ) . getNamespaces ( ) . putAll ( namespaceMappings ) ; xmlMessageValidationContext . getNamespaces ( ) . putAll ( namespaceMappings ) ; return self ; } | Sets default namespace declarations on this action builder . |
28,350 | public T selector ( Map < String , Object > messageSelector ) { getAction ( ) . setMessageSelectorMap ( messageSelector ) ; return self ; } | Sets message selector elements . |
28,351 | public T validator ( MessageValidator < ? extends ValidationContext > ... validators ) { Stream . of ( validators ) . forEach ( getAction ( ) :: addValidator ) ; return self ; } | Sets explicit message validators for this receive action . |
28,352 | @ SuppressWarnings ( "unchecked" ) public T validator ( String ... validatorNames ) { Assert . notNull ( applicationContext , "Citrus application context is not initialized!" ) ; for ( String validatorName : validatorNames ) { getAction ( ) . addValidator ( applicationContext . getBean ( validatorName , MessageValidator . class ) ) ; } return self ; } | Sets explicit message validators by name . |
28,353 | public T headerValidator ( HeaderValidator ... validators ) { Stream . of ( validators ) . forEach ( headerValidationContext :: addHeaderValidator ) ; return self ; } | Sets explicit header validator for this receive action . |
28,354 | @ SuppressWarnings ( "unchecked" ) public T headerValidator ( String ... validatorNames ) { Assert . notNull ( applicationContext , "Citrus application context is not initialized!" ) ; for ( String validatorName : validatorNames ) { headerValidationContext . addHeaderValidator ( applicationContext . getBean ( validatorName , HeaderValidator . class ) ) ; } return self ; } | Sets explicit header validators by name . |
28,355 | @ SuppressWarnings ( "unchecked" ) public T dictionary ( String dictionaryName ) { Assert . notNull ( applicationContext , "Citrus application context is not initialized!" ) ; DataDictionary dictionary = applicationContext . getBean ( dictionaryName , DataDictionary . class ) ; getAction ( ) . setDataDictionary ( dictionary ) ; return self ; } | Sets explicit data dictionary by name . |
28,356 | public T extractFromHeader ( String headerName , String variable ) { if ( headerExtractor == null ) { headerExtractor = new MessageHeaderVariableExtractor ( ) ; getAction ( ) . getVariableExtractors ( ) . add ( headerExtractor ) ; } headerExtractor . getHeaderMappings ( ) . put ( headerName , variable ) ; return self ; } | Extract message header entry as variable . |
28,357 | public T extractFromPayload ( String path , String variable ) { if ( JsonPathMessageValidationContext . isJsonPathExpression ( path ) ) { getJsonPathVariableExtractor ( ) . getJsonPathExpressions ( ) . put ( path , variable ) ; } else { getXpathVariableExtractor ( ) . getXpathExpressions ( ) . put ( path , variable ) ; } return self ; } | Extract message element via XPath or JSONPath from message payload as new test variable . |
28,358 | public T validationCallback ( ValidationCallback callback ) { if ( callback instanceof ApplicationContextAware ) { ( ( ApplicationContextAware ) callback ) . setApplicationContext ( applicationContext ) ; } getAction ( ) . setValidationCallback ( callback ) ; return self ; } | Adds validation callback to the receive action for validating the received message with Java code . |
28,359 | protected AbstractMessageContentBuilder getMessageContentBuilder ( ) { if ( getAction ( ) . getMessageBuilder ( ) != null && getAction ( ) . getMessageBuilder ( ) instanceof AbstractMessageContentBuilder ) { return ( AbstractMessageContentBuilder ) getAction ( ) . getMessageBuilder ( ) ; } else { PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder ( ) ; getAction ( ) . setMessageBuilder ( messageBuilder ) ; return messageBuilder ; } } | Get message builder if already registered or create a new message builder and register it |
28,360 | private XpathMessageValidationContext getXPathValidationContext ( ) { if ( xmlMessageValidationContext instanceof XpathMessageValidationContext ) { return ( ( XpathMessageValidationContext ) xmlMessageValidationContext ) ; } else { XpathMessageValidationContext xPathContext = new XpathMessageValidationContext ( ) ; xPathContext . setNamespaces ( xmlMessageValidationContext . getNamespaces ( ) ) ; xPathContext . setControlNamespaces ( xmlMessageValidationContext . getControlNamespaces ( ) ) ; xPathContext . setIgnoreExpressions ( xmlMessageValidationContext . getIgnoreExpressions ( ) ) ; xPathContext . setSchema ( xmlMessageValidationContext . getSchema ( ) ) ; xPathContext . setSchemaRepository ( xmlMessageValidationContext . getSchemaRepository ( ) ) ; xPathContext . setSchemaValidation ( xmlMessageValidationContext . isSchemaValidationEnabled ( ) ) ; xPathContext . setDTDResource ( xmlMessageValidationContext . getDTDResource ( ) ) ; getAction ( ) . getValidationContexts ( ) . remove ( xmlMessageValidationContext ) ; getAction ( ) . getValidationContexts ( ) . add ( xPathContext ) ; xmlMessageValidationContext = xPathContext ; return xPathContext ; } } | Gets the validation context as XML validation context an raises exception if existing validation context is not a XML validation context . |
28,361 | private ScriptValidationContext getScriptValidationContext ( ) { if ( scriptValidationContext == null ) { scriptValidationContext = new ScriptValidationContext ( messageType . toString ( ) ) ; getAction ( ) . getValidationContexts ( ) . add ( scriptValidationContext ) ; } return scriptValidationContext ; } | Creates new script validation context if not done before and gets the script validation context . |
28,362 | private JsonPathMessageValidationContext getJsonPathValidationContext ( ) { if ( jsonPathValidationContext == null ) { jsonPathValidationContext = new JsonPathMessageValidationContext ( ) ; getAction ( ) . getValidationContexts ( ) . add ( jsonPathValidationContext ) ; } return jsonPathValidationContext ; } | Creates new JSONPath validation context if not done before and gets the validation context . |
28,363 | protected List < ValidationContext > parseValidationContexts ( Element messageElement , BeanDefinitionBuilder builder ) { List < ValidationContext > validationContexts = new ArrayList < > ( ) ; if ( messageElement != null ) { String messageType = messageElement . getAttribute ( "type" ) ; if ( ! StringUtils . hasText ( messageType ) ) { messageType = Citrus . DEFAULT_MESSAGE_TYPE ; } else { builder . addPropertyValue ( "messageType" , messageType ) ; } HeaderValidationContext headerValidationContext = new HeaderValidationContext ( ) ; validationContexts . add ( headerValidationContext ) ; String headerValidator = messageElement . getAttribute ( "header-validator" ) ; if ( StringUtils . hasText ( headerValidator ) ) { headerValidationContext . addHeaderValidator ( headerValidator ) ; } String headerValidatorExpression = messageElement . getAttribute ( "header-validators" ) ; if ( StringUtils . hasText ( headerValidatorExpression ) ) { Stream . of ( headerValidatorExpression . split ( "," ) ) . map ( String :: trim ) . forEach ( headerValidationContext :: addHeaderValidator ) ; } XmlMessageValidationContext xmlMessageValidationContext = getXmlMessageValidationContext ( messageElement ) ; validationContexts . add ( xmlMessageValidationContext ) ; XpathMessageValidationContext xPathMessageValidationContext = getXPathMessageValidationContext ( messageElement , xmlMessageValidationContext ) ; if ( ! xPathMessageValidationContext . getXpathExpressions ( ) . isEmpty ( ) ) { validationContexts . add ( xPathMessageValidationContext ) ; } JsonMessageValidationContext jsonMessageValidationContext = getJsonMessageValidationContext ( messageElement ) ; validationContexts . add ( jsonMessageValidationContext ) ; JsonPathMessageValidationContext jsonPathMessageValidationContext = getJsonPathMessageValidationContext ( messageElement ) ; if ( ! jsonPathMessageValidationContext . getJsonPathExpressions ( ) . isEmpty ( ) ) { validationContexts . add ( jsonPathMessageValidationContext ) ; } ScriptValidationContext scriptValidationContext = getScriptValidationContext ( messageElement , messageType ) ; if ( scriptValidationContext != null ) { validationContexts . add ( scriptValidationContext ) ; } ManagedList < RuntimeBeanReference > validators = new ManagedList < > ( ) ; String messageValidator = messageElement . getAttribute ( "validator" ) ; if ( StringUtils . hasText ( messageValidator ) ) { validators . add ( new RuntimeBeanReference ( messageValidator ) ) ; } String messageValidatorExpression = messageElement . getAttribute ( "validators" ) ; if ( StringUtils . hasText ( messageValidatorExpression ) ) { Stream . of ( messageValidatorExpression . split ( "," ) ) . map ( String :: trim ) . map ( RuntimeBeanReference :: new ) . forEach ( validators :: add ) ; } if ( ! validators . isEmpty ( ) ) { builder . addPropertyValue ( "validators" , validators ) ; } String dataDictionary = messageElement . getAttribute ( "data-dictionary" ) ; if ( StringUtils . hasText ( dataDictionary ) ) { builder . addPropertyReference ( "dataDictionary" , dataDictionary ) ; } } else { validationContexts . add ( new HeaderValidationContext ( ) ) ; } return validationContexts ; } | Parse message validation contexts . |
28,364 | protected List < VariableExtractor > getVariableExtractors ( Element element ) { List < VariableExtractor > variableExtractors = new ArrayList < > ( ) ; parseExtractHeaderElements ( element , variableExtractors ) ; Element extractElement = DomUtils . getChildElementByTagName ( element , "extract" ) ; if ( extractElement != null ) { Map < String , String > extractFromPath = new HashMap < > ( ) ; List < Element > messageValueElements = DomUtils . getChildElementsByTagName ( extractElement , "message" ) ; messageValueElements . addAll ( DomUtils . getChildElementsByTagName ( extractElement , "body" ) ) ; VariableExtractorParserUtil . parseMessageElement ( messageValueElements , extractFromPath ) ; if ( ! CollectionUtils . isEmpty ( extractFromPath ) ) { VariableExtractorParserUtil . addPayloadVariableExtractors ( element , variableExtractors , extractFromPath ) ; } } return variableExtractors ; } | Constructs a list of variable extractors . |
28,365 | private JsonMessageValidationContext getJsonMessageValidationContext ( Element messageElement ) { JsonMessageValidationContext context = new JsonMessageValidationContext ( ) ; if ( messageElement != null ) { Set < String > ignoreExpressions = new HashSet < String > ( ) ; List < ? > ignoreElements = DomUtils . getChildElementsByTagName ( messageElement , "ignore" ) ; for ( Iterator < ? > iter = ignoreElements . iterator ( ) ; iter . hasNext ( ) ; ) { Element ignoreValue = ( Element ) iter . next ( ) ; ignoreExpressions . add ( ignoreValue . getAttribute ( "path" ) ) ; } context . setIgnoreExpressions ( ignoreExpressions ) ; addSchemaInformationToValidationContext ( messageElement , context ) ; } return context ; } | Construct the basic Json message validation context . |
28,366 | private XmlMessageValidationContext getXmlMessageValidationContext ( Element messageElement ) { XmlMessageValidationContext context = new XmlMessageValidationContext ( ) ; if ( messageElement != null ) { addSchemaInformationToValidationContext ( messageElement , context ) ; Set < String > ignoreExpressions = new HashSet < String > ( ) ; List < ? > ignoreElements = DomUtils . getChildElementsByTagName ( messageElement , "ignore" ) ; for ( Iterator < ? > iter = ignoreElements . iterator ( ) ; iter . hasNext ( ) ; ) { Element ignoreValue = ( Element ) iter . next ( ) ; ignoreExpressions . add ( ignoreValue . getAttribute ( "path" ) ) ; } context . setIgnoreExpressions ( ignoreExpressions ) ; parseNamespaceValidationElements ( messageElement , context ) ; Map < String , String > namespaces = new HashMap < String , String > ( ) ; List < ? > namespaceElements = DomUtils . getChildElementsByTagName ( messageElement , "namespace" ) ; if ( namespaceElements . size ( ) > 0 ) { for ( Iterator < ? > iter = namespaceElements . iterator ( ) ; iter . hasNext ( ) ; ) { Element namespaceElement = ( Element ) iter . next ( ) ; namespaces . put ( namespaceElement . getAttribute ( "prefix" ) , namespaceElement . getAttribute ( "value" ) ) ; } context . setNamespaces ( namespaces ) ; } } return context ; } | Construct the basic Xml message validation context . |
28,367 | private void addSchemaInformationToValidationContext ( Element messageElement , SchemaValidationContext context ) { String schemaValidation = messageElement . getAttribute ( "schema-validation" ) ; if ( StringUtils . hasText ( schemaValidation ) ) { context . setSchemaValidation ( Boolean . valueOf ( schemaValidation ) ) ; } String schema = messageElement . getAttribute ( "schema" ) ; if ( StringUtils . hasText ( schema ) ) { context . setSchema ( schema ) ; } String schemaRepository = messageElement . getAttribute ( "schema-repository" ) ; if ( StringUtils . hasText ( schemaRepository ) ) { context . setSchemaRepository ( schemaRepository ) ; } } | Adds information about the validation of the message against a certain schema to the context |
28,368 | private XpathMessageValidationContext getXPathMessageValidationContext ( Element messageElement , XmlMessageValidationContext parentContext ) { XpathMessageValidationContext context = new XpathMessageValidationContext ( ) ; parseXPathValidationElements ( messageElement , context ) ; context . setControlNamespaces ( parentContext . getControlNamespaces ( ) ) ; context . setNamespaces ( parentContext . getNamespaces ( ) ) ; context . setIgnoreExpressions ( parentContext . getIgnoreExpressions ( ) ) ; context . setSchema ( parentContext . getSchema ( ) ) ; context . setSchemaRepository ( parentContext . getSchemaRepository ( ) ) ; context . setSchemaValidation ( parentContext . isSchemaValidationEnabled ( ) ) ; context . setDTDResource ( parentContext . getDTDResource ( ) ) ; return context ; } | Construct the XPath message validation context . |
28,369 | private JsonPathMessageValidationContext getJsonPathMessageValidationContext ( Element messageElement ) { JsonPathMessageValidationContext context = new JsonPathMessageValidationContext ( ) ; Map < String , Object > validateJsonPathExpressions = new HashMap < > ( ) ; List < ? > validateElements = DomUtils . getChildElementsByTagName ( messageElement , "validate" ) ; if ( validateElements . size ( ) > 0 ) { for ( Iterator < ? > iter = validateElements . iterator ( ) ; iter . hasNext ( ) ; ) { Element validateElement = ( Element ) iter . next ( ) ; extractJsonPathValidateExpressions ( validateElement , validateJsonPathExpressions ) ; } context . setJsonPathExpressions ( validateJsonPathExpressions ) ; } return context ; } | Construct the JSONPath message validation context . |
28,370 | private ScriptValidationContext getScriptValidationContext ( Element messageElement , String messageType ) { ScriptValidationContext context = null ; boolean done = false ; List < ? > validateElements = DomUtils . getChildElementsByTagName ( messageElement , "validate" ) ; if ( validateElements . size ( ) > 0 ) { for ( Iterator < ? > iter = validateElements . iterator ( ) ; iter . hasNext ( ) ; ) { Element validateElement = ( Element ) iter . next ( ) ; Element scriptElement = DomUtils . getChildElementByTagName ( validateElement , "script" ) ; if ( scriptElement != null ) { if ( ! done ) { done = true ; } else { throw new BeanCreationException ( "Found multiple validation script definitions - " + "only supporting a single validation script for message validation" ) ; } context = new ScriptValidationContext ( messageType ) ; String type = scriptElement . getAttribute ( "type" ) ; context . setScriptType ( type ) ; String filePath = scriptElement . getAttribute ( "file" ) ; if ( StringUtils . hasText ( filePath ) ) { context . setValidationScriptResourcePath ( filePath ) ; if ( scriptElement . hasAttribute ( "charset" ) ) { context . setValidationScriptResourceCharset ( scriptElement . getAttribute ( "charset" ) ) ; } } else { context . setValidationScript ( DomUtils . getTextValue ( scriptElement ) ) ; } } } } return context ; } | Construct the message validation context . |
28,371 | private void extractXPathValidateExpressions ( Element validateElement , Map < String , Object > validateXpathExpressions ) { String pathExpression = validateElement . getAttribute ( "path" ) ; if ( StringUtils . hasText ( pathExpression ) && ! JsonPathMessageValidationContext . isJsonPathExpression ( pathExpression ) ) { if ( validateElement . hasAttribute ( "result-type" ) ) { pathExpression = validateElement . getAttribute ( "result-type" ) + ":" + pathExpression ; } validateXpathExpressions . put ( pathExpression , validateElement . getAttribute ( "value" ) ) ; } List < ? > xpathElements = DomUtils . getChildElementsByTagName ( validateElement , "xpath" ) ; if ( xpathElements . size ( ) > 0 ) { for ( Iterator < ? > xpathIterator = xpathElements . iterator ( ) ; xpathIterator . hasNext ( ) ; ) { Element xpathElement = ( Element ) xpathIterator . next ( ) ; String expression = xpathElement . getAttribute ( "expression" ) ; if ( StringUtils . hasText ( expression ) ) { if ( xpathElement . hasAttribute ( "result-type" ) ) { expression = xpathElement . getAttribute ( "result-type" ) + ":" + expression ; } validateXpathExpressions . put ( expression , xpathElement . getAttribute ( "value" ) ) ; } } } } | Extracts xpath validation expressions and fills map with them |
28,372 | private void extractJsonPathValidateExpressions ( Element validateElement , Map < String , Object > validateJsonPathExpressions ) { String pathExpression = validateElement . getAttribute ( "path" ) ; if ( JsonPathMessageValidationContext . isJsonPathExpression ( pathExpression ) ) { validateJsonPathExpressions . put ( pathExpression , validateElement . getAttribute ( "value" ) ) ; } ValidateMessageParserUtil . parseJsonPathElements ( validateElement , validateJsonPathExpressions ) ; } | Extracts jsonPath validation expressions and fills map with them |
28,373 | protected void addImportedSchemas ( Schema schema ) throws WSDLException , IOException , TransformerException , TransformerFactoryConfigurationError { for ( Object imports : schema . getImports ( ) . values ( ) ) { for ( SchemaImport schemaImport : ( Vector < SchemaImport > ) imports ) { if ( ! importedSchemas . contains ( schemaImport . getNamespaceURI ( ) ) ) { importedSchemas . add ( schemaImport . getNamespaceURI ( ) ) ; Schema referencedSchema = schemaImport . getReferencedSchema ( ) ; if ( referencedSchema != null ) { ByteArrayOutputStream bos = new ByteArrayOutputStream ( ) ; Source source = new DOMSource ( referencedSchema . getElement ( ) ) ; Result result = new StreamResult ( bos ) ; TransformerFactory . newInstance ( ) . newTransformer ( ) . transform ( source , result ) ; Resource schemaResource = new ByteArrayResource ( bos . toByteArray ( ) ) ; addImportedSchemas ( referencedSchema ) ; schemaResources . add ( schemaResource ) ; } } } } } | Recursively add all imported schemas as schema resource . This is necessary when schema import are located in jar files . If they are not added immediately the reference to them is lost . |
28,374 | protected void addIncludedSchemas ( Schema schema ) throws WSDLException , IOException , TransformerException , TransformerFactoryConfigurationError { List < SchemaReference > includes = schema . getIncludes ( ) ; for ( SchemaReference schemaReference : includes ) { String schemaLocation ; URI locationURI = URI . create ( schemaReference . getSchemaLocationURI ( ) ) ; if ( locationURI . isAbsolute ( ) ) { schemaLocation = schemaReference . getSchemaLocationURI ( ) ; } else { schemaLocation = schema . getDocumentBaseURI ( ) . substring ( 0 , schema . getDocumentBaseURI ( ) . lastIndexOf ( '/' ) + 1 ) + schemaReference . getSchemaLocationURI ( ) ; } schemaResources . add ( new FileSystemResource ( schemaLocation ) ) ; } } | Recursively add all included schemas as schema resource . |
28,375 | public NamespaceContext buildContext ( Message receivedMessage , Map < String , String > namespaces ) { SimpleNamespaceContext simpleNamespaceContext = new SimpleNamespaceContext ( ) ; if ( namespaceMappings . size ( ) > 0 ) { simpleNamespaceContext . setBindings ( namespaceMappings ) ; } Map < String , String > dynamicBindings = XMLUtils . lookupNamespaces ( receivedMessage . getPayload ( String . class ) ) ; if ( ! CollectionUtils . isEmpty ( namespaces ) ) { for ( Entry < String , String > binding : dynamicBindings . entrySet ( ) ) { if ( ! namespaces . containsValue ( binding . getValue ( ) ) ) { simpleNamespaceContext . bindNamespaceUri ( binding . getKey ( ) , binding . getValue ( ) ) ; } } simpleNamespaceContext . setBindings ( namespaces ) ; } else { simpleNamespaceContext . setBindings ( dynamicBindings ) ; } return simpleNamespaceContext ; } | Construct a basic namespace context from the received message and explicit namespace mappings . |
28,376 | public void addMessageSelectorFactory ( MessageSelectorFactory < ? > factory ) { if ( factory instanceof BeanFactoryAware ) { ( ( BeanFactoryAware ) factory ) . setBeanFactory ( beanFactory ) ; } this . factories . add ( factory ) ; } | Add message selector factory to list of delegates . |
28,377 | public static void resolveValidationMatcher ( String fieldName , String fieldValue , String validationMatcherExpression , TestContext context ) { String expression = VariableUtils . cutOffVariablesPrefix ( cutOffValidationMatchersPrefix ( validationMatcherExpression ) ) ; if ( expression . equals ( "ignore" ) ) { expression += "()" ; } int bodyStart = expression . indexOf ( '(' ) ; if ( bodyStart < 0 ) { throw new CitrusRuntimeException ( "Illegal syntax for validation matcher expression - missing validation value in '()' function body" ) ; } String prefix = "" ; if ( expression . indexOf ( ':' ) > 0 && expression . indexOf ( ':' ) < bodyStart ) { prefix = expression . substring ( 0 , expression . indexOf ( ':' ) + 1 ) ; } String matcherValue = expression . substring ( bodyStart + 1 , expression . length ( ) - 1 ) ; String matcherName = expression . substring ( prefix . length ( ) , bodyStart ) ; ValidationMatcherLibrary library = context . getValidationMatcherRegistry ( ) . getLibraryForPrefix ( prefix ) ; ValidationMatcher validationMatcher = library . getValidationMatcher ( matcherName ) ; ControlExpressionParser controlExpressionParser = lookupControlExpressionParser ( validationMatcher ) ; List < String > params = controlExpressionParser . extractControlValues ( matcherValue , null ) ; List < String > replacedParams = replaceVariablesAndFunctionsInParameters ( params , context ) ; validationMatcher . validate ( fieldName , fieldValue , replacedParams , context ) ; } | This method resolves a custom validationMatcher to its respective result . |
28,378 | public static boolean isValidationMatcherExpression ( String expression ) { return expression . startsWith ( Citrus . VALIDATION_MATCHER_PREFIX ) && expression . endsWith ( Citrus . VALIDATION_MATCHER_SUFFIX ) ; } | Checks if expression is a validation matcher expression . |
28,379 | private static String cutOffValidationMatchersPrefix ( String expression ) { if ( expression . startsWith ( Citrus . VALIDATION_MATCHER_PREFIX ) && expression . endsWith ( Citrus . VALIDATION_MATCHER_SUFFIX ) ) { return expression . substring ( Citrus . VALIDATION_MATCHER_PREFIX . length ( ) , expression . length ( ) - Citrus . VALIDATION_MATCHER_SUFFIX . length ( ) ) ; } return expression ; } | Cut off validation matchers prefix and suffix . |
28,380 | public BeanInvocation sayHello ( String message ) { BeanInvocation invocation = new BeanInvocation ( ) ; try { invocation . setMethod ( HelloService . class . getMethod ( "sayHello" , String . class ) ) ; invocation . setArgs ( new Object [ ] { message } ) ; } catch ( NoSuchMethodException e ) { throw new CitrusRuntimeException ( "Failed to access remote service method" , e ) ; } return invocation ; } | Creates bean invocation for hello service call . |
28,381 | public void apply ( CitrusAppConfiguration configuration ) { setPackages ( configuration . getPackages ( ) ) ; setTestClasses ( configuration . getTestClasses ( ) ) ; setIncludes ( configuration . getIncludes ( ) ) ; addDefaultProperties ( configuration . getDefaultProperties ( ) ) ; } | Applies configuration with settable properties at runtime . |
28,382 | public static String getRandomString ( int numberOfLetters , char [ ] alphabet , boolean includeNumbers ) { StringBuilder builder = new StringBuilder ( ) ; int upperRange = alphabet . length - 1 ; builder . append ( alphabet [ generator . nextInt ( upperRange ) ] ) ; if ( includeNumbers ) { upperRange += NUMBERS . length ; } for ( int i = 1 ; i < numberOfLetters ; i ++ ) { int letterIndex = generator . nextInt ( upperRange ) ; if ( letterIndex > alphabet . length - 1 ) { builder . append ( NUMBERS [ letterIndex - alphabet . length ] ) ; } else { builder . append ( alphabet [ letterIndex ] ) ; } } return builder . toString ( ) ; } | Static random number generator aware string generating method . |
28,383 | public ValidationMatcher getValidationMatcher ( String validationMatcherName ) throws NoSuchValidationMatcherException { if ( ! members . containsKey ( validationMatcherName ) ) { throw new NoSuchValidationMatcherException ( "Can not find validation matcher " + validationMatcherName + " in library " + name + " (" + prefix + ")" ) ; } return members . get ( validationMatcherName ) ; } | Try to find validationMatcher in library by name . |
28,384 | public boolean knowsValidationMatcher ( String validationMatcherName ) { if ( validationMatcherName . contains ( ":" ) ) { String validationMatcherPrefix = validationMatcherName . substring ( 0 , validationMatcherName . indexOf ( ':' ) + 1 ) ; if ( ! validationMatcherPrefix . equals ( prefix ) ) { return false ; } return members . containsKey ( validationMatcherName . substring ( validationMatcherName . indexOf ( ':' ) + 1 , validationMatcherName . indexOf ( '(' ) ) ) ; } else { return members . containsKey ( validationMatcherName . substring ( 0 , validationMatcherName . indexOf ( '(' ) ) ) ; } } | Does this library know a validationMatcher with the given name . |
28,385 | private boolean containsNumericMatcher ( String matcherExpression ) { for ( String numericMatcher : numericMatchers ) { if ( matcherExpression . contains ( numericMatcher ) ) { return true ; } } return false ; } | Checks for numeric matcher presence in expression . |
28,386 | private WebSocketMessage < ? > receive ( WebSocketEndpointConfiguration config , long timeout ) { long timeLeft = timeout ; WebSocketMessage < ? > message = config . getHandler ( ) . getMessage ( ) ; String path = endpointConfiguration . getEndpointUri ( ) ; while ( message == null && timeLeft > 0 ) { timeLeft -= endpointConfiguration . getPollingInterval ( ) ; long sleep = timeLeft > 0 ? endpointConfiguration . getPollingInterval ( ) : endpointConfiguration . getPollingInterval ( ) + timeLeft ; if ( LOG . isDebugEnabled ( ) ) { String msg = "Waiting for message on '%s' - retrying in %s ms" ; LOG . debug ( String . format ( msg , path , ( sleep ) ) ) ; } try { Thread . sleep ( sleep ) ; } catch ( InterruptedException e ) { LOG . warn ( String . format ( "Thread interrupted while waiting for message on '%s'" , path ) , e ) ; } message = config . getHandler ( ) . getMessage ( ) ; } if ( message == null ) { throw new ActionTimeoutException ( String . format ( "Action timed out while receiving message on '%s'" , path ) ) ; } return message ; } | Receive web socket message by polling on web socket handler for incoming message . |
28,387 | private Stack < String > parseTargets ( ) { Stack < String > stack = new Stack < String > ( ) ; String [ ] targetTokens = targets . split ( "," ) ; for ( String targetToken : targetTokens ) { stack . add ( targetToken . trim ( ) ) ; } return stack ; } | Converts comma delimited string to stack . |
28,388 | private void loadBuildPropertyFile ( Project project , TestContext context ) { if ( StringUtils . hasText ( propertyFilePath ) ) { String propertyFileResource = context . replaceDynamicContentInString ( propertyFilePath ) ; log . info ( "Reading build property file: " + propertyFileResource ) ; Properties fileProperties ; try { fileProperties = PropertiesLoaderUtils . loadProperties ( new PathMatchingResourcePatternResolver ( ) . getResource ( propertyFileResource ) ) ; for ( Entry < Object , Object > entry : fileProperties . entrySet ( ) ) { String propertyValue = entry . getValue ( ) != null ? context . replaceDynamicContentInString ( entry . getValue ( ) . toString ( ) ) : "" ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Set build property from file resource: " + entry . getKey ( ) + "=" + propertyValue ) ; } project . setProperty ( entry . getKey ( ) . toString ( ) , propertyValue ) ; } } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read build property file" , e ) ; } } } | Loads build properties from file resource and adds them to ANT project . |
28,389 | public static String build ( String messageSelector , Map < String , Object > messageSelectorMap , TestContext context ) { if ( StringUtils . hasText ( messageSelector ) ) { return context . replaceDynamicContentInString ( messageSelector ) ; } else if ( ! CollectionUtils . isEmpty ( messageSelectorMap ) ) { return MessageSelectorBuilder . fromKeyValueMap ( context . resolveDynamicValuesInMap ( messageSelectorMap ) ) . build ( ) ; } return "" ; } | Build message selector from string expression or from key value map . Automatically replaces test variables . |
28,390 | public static MessageSelectorBuilder fromKeyValueMap ( Map < String , Object > valueMap ) { StringBuffer buf = new StringBuffer ( ) ; Iterator < Entry < String , Object > > iter = valueMap . entrySet ( ) . iterator ( ) ; if ( iter . hasNext ( ) ) { Entry < String , Object > entry = iter . next ( ) ; String key = entry . getKey ( ) ; String value = entry . getValue ( ) . toString ( ) ; buf . append ( key + " = '" + value + "'" ) ; } while ( iter . hasNext ( ) ) { Entry < String , Object > entry = iter . next ( ) ; String key = entry . getKey ( ) ; String value = entry . getValue ( ) . toString ( ) ; buf . append ( " AND " + key + " = '" + value + "'" ) ; } return new MessageSelectorBuilder ( buf . toString ( ) ) ; } | Static builder method using a key value map . |
28,391 | public Map < String , String > toKeyValueMap ( ) { Map < String , String > valueMap = new HashMap < String , String > ( ) ; String [ ] tokens ; if ( selectorString . contains ( " AND" ) ) { String [ ] chunks = selectorString . split ( " AND" ) ; for ( String chunk : chunks ) { tokens = escapeEqualsFromXpathNodeTest ( chunk ) . split ( "=" ) ; valueMap . put ( unescapeEqualsFromXpathNodeTest ( tokens [ 0 ] . trim ( ) ) , tokens [ 1 ] . trim ( ) . substring ( 1 , tokens [ 1 ] . trim ( ) . length ( ) - 1 ) ) ; } } else { tokens = escapeEqualsFromXpathNodeTest ( selectorString ) . split ( "=" ) ; valueMap . put ( unescapeEqualsFromXpathNodeTest ( tokens [ 0 ] . trim ( ) ) , tokens [ 1 ] . trim ( ) . substring ( 1 , tokens [ 1 ] . trim ( ) . length ( ) - 1 ) ) ; } return valueMap ; } | Constructs a key value map from selector string representation . |
28,392 | private void doAutoSleep ( ) { if ( autoSleep > 0 ) { log . info ( "Sleeping " + autoSleep + " milliseconds" ) ; try { Thread . sleep ( autoSleep ) ; } catch ( InterruptedException e ) { log . error ( "Error during doc generation" , e ) ; } log . info ( "Returning after " + autoSleep + " milliseconds" ) ; } } | Sleep amount of time in between iterations . |
28,393 | private void send ( Message message , String destinationName , TestContext context ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Sending JMS message to destination: '" + destinationName + "'" ) ; } endpointConfiguration . getJmsTemplate ( ) . send ( destinationName , session -> { javax . jms . Message jmsMessage = endpointConfiguration . getMessageConverter ( ) . createJmsMessage ( message , session , endpointConfiguration , context ) ; endpointConfiguration . getMessageConverter ( ) . convertOutbound ( jmsMessage , message , endpointConfiguration , context ) ; return jmsMessage ; } ) ; log . info ( "Message was sent to JMS destination: '" + destinationName + "'" ) ; } | Send message using destination name . |
28,394 | private void send ( Message message , Destination destination , TestContext context ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Sending JMS message to destination: '" + endpointConfiguration . getDestinationName ( destination ) + "'" ) ; } endpointConfiguration . getJmsTemplate ( ) . send ( destination , session -> { javax . jms . Message jmsMessage = endpointConfiguration . getMessageConverter ( ) . createJmsMessage ( message , session , endpointConfiguration , context ) ; endpointConfiguration . getMessageConverter ( ) . convertOutbound ( jmsMessage , message , endpointConfiguration , context ) ; return jmsMessage ; } ) ; log . info ( "Message was sent to JMS destination: '" + endpointConfiguration . getDestinationName ( destination ) + "'" ) ; } | Send message using destination . |
28,395 | protected void configureMessageController ( ApplicationContext context ) { if ( context . containsBean ( MESSAGE_CONTROLLER_BEAN_NAME ) ) { HttpMessageController messageController = context . getBean ( MESSAGE_CONTROLLER_BEAN_NAME , HttpMessageController . class ) ; EndpointAdapter endpointAdapter = httpServer . getEndpointAdapter ( ) ; HttpEndpointConfiguration endpointConfiguration = new HttpEndpointConfiguration ( ) ; endpointConfiguration . setMessageConverter ( httpServer . getMessageConverter ( ) ) ; endpointConfiguration . setHeaderMapper ( DefaultHttpHeaderMapper . inboundMapper ( ) ) ; endpointConfiguration . setHandleAttributeHeaders ( httpServer . isHandleAttributeHeaders ( ) ) ; endpointConfiguration . setHandleCookies ( httpServer . isHandleCookies ( ) ) ; endpointConfiguration . setDefaultStatusCode ( httpServer . getDefaultStatusCode ( ) ) ; messageController . setEndpointConfiguration ( endpointConfiguration ) ; if ( endpointAdapter != null ) { messageController . setEndpointAdapter ( endpointAdapter ) ; } } } | Post process message controller . |
28,396 | protected void configureMessageConverter ( ApplicationContext context ) { if ( context . containsBean ( MESSAGE_CONVERTER_BEAN_NAME ) ) { HttpMessageConverter messageConverter = context . getBean ( MESSAGE_CONVERTER_BEAN_NAME , HttpMessageConverter . class ) ; if ( messageConverter instanceof DelegatingHttpEntityMessageConverter ) { ( ( DelegatingHttpEntityMessageConverter ) messageConverter ) . setBinaryMediaTypes ( httpServer . getBinaryMediaTypes ( ) ) ; } } } | Post process message converter . |
28,397 | private List < HandlerInterceptor > adaptInterceptors ( List < Object > interceptors , ApplicationContext context ) { List < HandlerInterceptor > handlerInterceptors = new ArrayList < HandlerInterceptor > ( ) ; if ( context . containsBean ( LOGGING_INTERCEPTOR_BEAN_NAME ) ) { LoggingHandlerInterceptor loggingInterceptor = context . getBean ( LOGGING_INTERCEPTOR_BEAN_NAME , LoggingHandlerInterceptor . class ) ; handlerInterceptors . add ( loggingInterceptor ) ; } if ( interceptors != null ) { for ( Object interceptor : interceptors ) { if ( interceptor instanceof MappedInterceptor ) { handlerInterceptors . add ( new MappedInterceptorAdapter ( ( MappedInterceptor ) interceptor , new UrlPathHelper ( ) , new AntPathMatcher ( ) ) ) ; } else if ( interceptor instanceof HandlerInterceptor ) { handlerInterceptors . add ( ( HandlerInterceptor ) interceptor ) ; } else if ( interceptor instanceof WebRequestInterceptor ) { handlerInterceptors . add ( new WebRequestHandlerInterceptorAdapter ( ( WebRequestInterceptor ) interceptor ) ) ; } else { log . warn ( "Unsupported interceptor type: {}" , interceptor . getClass ( ) . getName ( ) ) ; } } } return handlerInterceptors ; } | Adapts object list to handler interceptors . |
28,398 | public TransformActionBuilder source ( Resource xmlResource , Charset charset ) { try { action . setXmlData ( FileUtils . readToString ( xmlResource , charset ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read xml resource" , e ) ; } return this ; } | Set the XML document as resource |
28,399 | public TransformActionBuilder xslt ( Resource xsltResource , Charset charset ) { try { action . setXsltData ( FileUtils . readToString ( xsltResource , charset ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read xstl resource" , e ) ; } return this ; } | Set the XSLT document as resource |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.