idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
28,000 | protected Message createControlMessage ( TestContext context , String messageType ) { if ( dataDictionary != null ) { messageBuilder . setDataDictionary ( dataDictionary ) ; } return messageBuilder . buildMessageContent ( context , messageType , MessageDirection . INBOUND ) ; } | Create control message that is expected . |
28,001 | public ReceiveMessageAction setValidators ( List < MessageValidator < ? extends ValidationContext > > validators ) { this . validators . clear ( ) ; this . validators . addAll ( validators ) ; return this ; } | Set list of message validators . |
28,002 | private DockerCommand createCommand ( Class < ? extends DockerCommand > commandType ) { try { return commandType . newInstance ( ) ; } catch ( InstantiationException | IllegalAccessException e ) { throw new BeanCreationException ( "Failed to create Docker command of type: " + commandType , e ) ; } } | Creates new Docker command instance of given type . |
28,003 | private void fillParams ( final Map < String , String [ ] > params , final String queryString , Charset charset ) { if ( StringUtils . hasText ( queryString ) ) { final StringTokenizer tokenizer = new StringTokenizer ( queryString , "&" ) ; while ( tokenizer . hasMoreTokens ( ) ) { final String [ ] nameValuePair = tokenizer . nextToken ( ) . split ( "=" ) ; try { params . put ( URLDecoder . decode ( nameValuePair [ 0 ] , charset . name ( ) ) , new String [ ] { URLDecoder . decode ( nameValuePair [ 1 ] , charset . name ( ) ) } ) ; } catch ( final UnsupportedEncodingException e ) { throw new CitrusRuntimeException ( String . format ( "Failed to decode query param value '%s=%s'" , nameValuePair [ 0 ] , nameValuePair [ 1 ] ) , e ) ; } } } } | Adds parameter name value paris extracted from given query string . |
28,004 | protected void addDependencies ( Archive < ? > archive ) { String version = getConfiguration ( ) . getCitrusVersion ( ) ; CitrusArchiveBuilder archiveBuilder ; if ( version != null ) { archiveBuilder = CitrusArchiveBuilder . version ( version ) ; } else { archiveBuilder = CitrusArchiveBuilder . latestVersion ( ) ; } if ( archive instanceof EnterpriseArchive ) { EnterpriseArchive ear = ( EnterpriseArchive ) archive ; ear . addAsModules ( archiveBuilder . all ( ) . build ( ) ) ; } else if ( archive instanceof WebArchive ) { WebArchive war = ( WebArchive ) archive ; war . addAsLibraries ( archiveBuilder . all ( ) . build ( ) ) ; } } | Adds Citrus archive dependencies and all transitive dependencies to archive . |
28,005 | private void initMessage ( HttpMessage message ) { StaticMessageContentBuilder staticMessageContentBuilder = StaticMessageContentBuilder . withMessage ( message ) ; staticMessageContentBuilder . setMessageHeaders ( message . getHeaders ( ) ) ; getAction ( ) . setMessageBuilder ( new HttpMessageContentBuilder ( message , staticMessageContentBuilder ) ) ; } | Initialize message builder . |
28,006 | public ExecutePLSQLBuilder sqlResource ( Resource sqlResource , Charset charset ) { try { action . setScript ( FileUtils . readToString ( sqlResource , charset ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to read sql resource" , e ) ; } return this ; } | Setter for external file resource containing the SQL statements to execute . |
28,007 | public List < MessageConstructionInterceptor > getMessageConstructionInterceptors ( ) { return messageConstructionInterceptors . stream ( ) . filter ( interceptor -> ! ( interceptor instanceof DataDictionary ) || ( ( DataDictionary ) interceptor ) . isGlobalScope ( ) ) . collect ( Collectors . toList ( ) ) ; } | Gets the messageConstructionInterceptors . |
28,008 | public WaitActionConditionBuilder execution ( ) { ActionCondition condition = new ActionCondition ( ) ; container . setCondition ( condition ) ; containers . push ( container ) ; return new WaitActionConditionBuilder ( container , condition , this ) ; } | The test action condition to wait for during execution . |
28,009 | public Wait buildAndRun ( ) { if ( designer != null ) { designer . action ( this ) ; } else if ( runner != null ) { runner . run ( super . build ( ) ) ; } return super . build ( ) ; } | Finishes action build process . |
28,010 | protected void validate ( WebElement element , SeleniumBrowser browser , TestContext context ) { validateElementProperty ( "tag-name" , tagName , element . getTagName ( ) , context ) ; validateElementProperty ( "text" , text , element . getText ( ) , context ) ; Assert . isTrue ( displayed == element . isDisplayed ( ) , String . format ( "Selenium web element validation failed, " + "property 'displayed' expected '%s', but was '%s'" , displayed , element . isDisplayed ( ) ) ) ; Assert . isTrue ( enabled == element . isEnabled ( ) , String . format ( "Selenium web element validation failed, " + "property 'enabled' expected '%s', but was '%s'" , enabled , element . isEnabled ( ) ) ) ; for ( Map . Entry < String , String > attributeEntry : attributes . entrySet ( ) ) { validateElementProperty ( String . format ( "attribute '%s'" , attributeEntry . getKey ( ) ) , attributeEntry . getValue ( ) , element . getAttribute ( attributeEntry . getKey ( ) ) , context ) ; } for ( Map . Entry < String , String > styleEntry : styles . entrySet ( ) ) { validateElementProperty ( String . format ( "css style '%s'" , styleEntry . getKey ( ) ) , styleEntry . getValue ( ) , element . getCssValue ( styleEntry . getKey ( ) ) , context ) ; } } | Validates found web element with expected content . |
28,011 | private void validateElementProperty ( String propertyName , String controlValue , String resultValue , TestContext context ) { if ( StringUtils . hasText ( controlValue ) ) { String control = context . replaceDynamicContentInString ( controlValue ) ; if ( ValidationMatcherUtils . isValidationMatcherExpression ( control ) ) { ValidationMatcherUtils . resolveValidationMatcher ( "payload" , resultValue , control , context ) ; } else { Assert . isTrue ( control . equals ( resultValue ) , String . format ( "Selenium web element validation failed, %s expected '%s', but was '%s'" , propertyName , control , resultValue ) ) ; } } } | Validates web element property value with validation matcher support . |
28,012 | protected void execute ( WebElement element , SeleniumBrowser browser , TestContext context ) { if ( StringUtils . hasText ( element . getTagName ( ) ) ) { context . setVariable ( element . getTagName ( ) , element ) ; } } | Subclasses may override this method in order to add element actions . |
28,013 | protected By createBy ( TestContext context ) { if ( by != null ) { return by ; } switch ( property ) { case "id" : return By . id ( context . replaceDynamicContentInString ( propertyValue ) ) ; case "class-name" : return By . className ( context . replaceDynamicContentInString ( propertyValue ) ) ; case "link-text" : return By . linkText ( context . replaceDynamicContentInString ( propertyValue ) ) ; case "css-selector" : return By . cssSelector ( context . replaceDynamicContentInString ( propertyValue ) ) ; case "name" : return By . name ( context . replaceDynamicContentInString ( propertyValue ) ) ; case "tag-name" : return By . tagName ( context . replaceDynamicContentInString ( propertyValue ) ) ; case "xpath" : return By . xpath ( context . replaceDynamicContentInString ( propertyValue ) ) ; } throw new CitrusRuntimeException ( "Unknown selector type: " + property ) ; } | Create by selector from type information . |
28,014 | private boolean checkCondition ( TestContext context ) { if ( conditionExpression != null ) { return conditionExpression . evaluate ( context ) ; } String conditionString = context . replaceDynamicContentInString ( condition ) ; if ( ValidationMatcherUtils . isValidationMatcherExpression ( conditionString ) ) { try { ValidationMatcherUtils . resolveValidationMatcher ( "iteratingCondition" , "" , conditionString , context ) ; return true ; } catch ( AssertionError e ) { return false ; } } return BooleanExpressionParser . evaluate ( conditionString ) ; } | Evaluates condition expression and returns boolean representation . |
28,015 | public void beforeDeploy ( @ Observes ( precedence = CitrusExtensionConstants . INSTANCE_PRECEDENCE ) BeforeDeploy event ) { try { if ( ! event . getDeployment ( ) . testable ( ) ) { log . info ( "Producing Citrus framework instance" ) ; citrusInstance . set ( Citrus . newInstance ( configurationInstance . get ( ) . getConfigurationClass ( ) ) ) ; } } catch ( Exception e ) { log . error ( CitrusExtensionConstants . CITRUS_EXTENSION_ERROR , e ) ; throw e ; } } | Before deploy executed before deployment on client . |
28,016 | public static List < String > createStatementsFromFileResource ( Resource sqlResource , LastScriptLineDecorator lineDecorator ) { BufferedReader reader = null ; StringBuffer buffer ; List < String > stmts = new ArrayList < > ( ) ; try { if ( log . isDebugEnabled ( ) ) { log . debug ( "Create statements from SQL file: " + sqlResource . getFile ( ) . getAbsolutePath ( ) ) ; } reader = new BufferedReader ( new InputStreamReader ( sqlResource . getInputStream ( ) ) ) ; buffer = new StringBuffer ( ) ; String line ; while ( reader . ready ( ) ) { line = reader . readLine ( ) ; if ( line != null && ! line . trim ( ) . startsWith ( SQL_COMMENT ) && line . trim ( ) . length ( ) > 0 ) { if ( line . trim ( ) . endsWith ( getStatementEndingCharacter ( lineDecorator ) ) ) { if ( lineDecorator != null ) { buffer . append ( lineDecorator . decorate ( line ) ) ; } else { buffer . append ( line ) ; } String stmt = buffer . toString ( ) . trim ( ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Found statement: " + stmt ) ; } stmts . add ( stmt ) ; buffer . setLength ( 0 ) ; buffer = new StringBuffer ( ) ; } else { buffer . append ( line ) ; buffer . append ( "\n" ) ; } } } } catch ( IOException e ) { throw new CitrusRuntimeException ( "Resource could not be found - filename: " + sqlResource , e ) ; } finally { if ( reader != null ) { try { reader . close ( ) ; } catch ( IOException e ) { log . warn ( "Warning: Error while closing reader instance" , e ) ; } } } return stmts ; } | Reads SQL statements from external file resource . File resource can hold several multi - line statements and comments . |
28,017 | public Object buildMessagePayload ( TestContext context , String messageType ) { this . getMessageInterceptors ( ) . add ( gzipMessageConstructionInterceptor ) ; this . getMessageInterceptors ( ) . add ( binaryMessageConstructionInterceptor ) ; return getPayloadContent ( context , messageType ) ; } | Build the control message from payload file resource or String data . |
28,018 | private void purgeEndpoint ( Endpoint endpoint , TestContext context ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Try to purge message endpoint " + endpoint . getName ( ) ) ; } int messagesPurged = 0 ; Consumer messageConsumer = endpoint . createConsumer ( ) ; Message message ; do { try { String selector = MessageSelectorBuilder . build ( messageSelector , messageSelectorMap , context ) ; if ( StringUtils . hasText ( selector ) && messageConsumer instanceof SelectiveConsumer ) { message = ( receiveTimeout >= 0 ) ? ( ( SelectiveConsumer ) messageConsumer ) . receive ( selector , context , receiveTimeout ) : ( ( SelectiveConsumer ) messageConsumer ) . receive ( selector , context ) ; } else { message = ( receiveTimeout >= 0 ) ? messageConsumer . receive ( context , receiveTimeout ) : messageConsumer . receive ( context ) ; } } catch ( ActionTimeoutException e ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Stop purging due to timeout - " + e . getMessage ( ) ) ; } break ; } if ( message != null ) { log . debug ( "Removed message from endpoint " + endpoint . getName ( ) ) ; messagesPurged ++ ; try { Thread . sleep ( sleepTime ) ; } catch ( InterruptedException e ) { log . warn ( "Interrupted during wait" , e ) ; } } } while ( message != null ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Purged " + messagesPurged + " messages from endpoint" ) ; } } | Purges all messages from a message endpoint . Prerequisite is that endpoint operates on a destination that queues messages . |
28,019 | protected Endpoint resolveEndpointName ( String endpointName ) { try { return beanFactory . getBean ( endpointName , Endpoint . class ) ; } catch ( BeansException e ) { throw new CitrusRuntimeException ( String . format ( "Unable to resolve endpoint for name '%s'" , endpointName ) , e ) ; } } | Resolve the endpoint by name . |
28,020 | public SftpClientBuilder sessionConfigs ( Map < String , String > sessionConfigs ) { endpoint . getEndpointConfiguration ( ) . setSessionConfigs ( sessionConfigs ) ; return this ; } | Sets the sessionConfigs property . |
28,021 | public void saveReplyMessageChannel ( Message receivedMessage , TestContext context ) { MessageChannel replyChannel = null ; if ( receivedMessage . getHeader ( org . springframework . messaging . MessageHeaders . REPLY_CHANNEL ) instanceof MessageChannel ) { replyChannel = ( MessageChannel ) receivedMessage . getHeader ( org . springframework . messaging . MessageHeaders . REPLY_CHANNEL ) ; } else if ( StringUtils . hasText ( ( String ) receivedMessage . getHeader ( org . springframework . messaging . MessageHeaders . REPLY_CHANNEL ) ) ) { replyChannel = resolveChannelName ( receivedMessage . getHeader ( org . springframework . messaging . MessageHeaders . REPLY_CHANNEL ) . toString ( ) , context ) ; } if ( replyChannel != null ) { String correlationKeyName = endpointConfiguration . getCorrelator ( ) . getCorrelationKeyName ( getName ( ) ) ; String correlationKey = endpointConfiguration . getCorrelator ( ) . getCorrelationKey ( receivedMessage ) ; correlationManager . saveCorrelationKey ( correlationKeyName , correlationKey , context ) ; correlationManager . store ( correlationKey , replyChannel ) ; } else { log . warn ( "Unable to retrieve reply message channel for message \n" + receivedMessage + "\n - no reply channel found in message headers!" ) ; } } | Store reply message channel . |
28,022 | public static boolean isElementIgnored ( final Node received , Set < String > ignoreExpressions , NamespaceContext namespaceContext ) { if ( CollectionUtils . isEmpty ( ignoreExpressions ) ) { return false ; } if ( ignoreExpressions . contains ( XMLUtils . getNodesPathName ( received ) ) ) { return true ; } for ( String expression : ignoreExpressions ) { if ( received == XMLUtils . findNodeByName ( received . getOwnerDocument ( ) , expression ) ) { return true ; } } for ( String expression : ignoreExpressions ) { if ( XPathUtils . isXPathExpression ( expression ) ) { NodeList foundNodes = XPathUtils . evaluateAsNodeList ( received . getOwnerDocument ( ) , expression , namespaceContext ) ; if ( foundNodes != null ) { for ( int i = 0 ; i < foundNodes . getLength ( ) ; i ++ ) { if ( foundNodes . item ( i ) != null && foundNodes . item ( i ) . isSameNode ( received ) ) { return true ; } } } } } return false ; } | Checks whether the node is ignored by node path expression or xpath expression . |
28,023 | public static boolean isAttributeIgnored ( Node receivedElement , Node receivedAttribute , Node sourceAttribute , Set < String > ignoreMessageElements , NamespaceContext namespaceContext ) { if ( isAttributeIgnored ( receivedElement , receivedAttribute , ignoreMessageElements , namespaceContext ) ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Attribute '" + receivedAttribute . getLocalName ( ) + "' is on ignore list - skipped value validation" ) ; } return true ; } else if ( ( StringUtils . hasText ( sourceAttribute . getNodeValue ( ) ) && sourceAttribute . getNodeValue ( ) . trim ( ) . equals ( Citrus . IGNORE_PLACEHOLDER ) ) ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Attribute: '" + receivedAttribute . getLocalName ( ) + "' is ignored by placeholder '" + Citrus . IGNORE_PLACEHOLDER + "'" ) ; } return true ; } return false ; } | Checks whether the current attribute is ignored either by global ignore placeholder in source attribute value or by xpath ignore expressions . |
28,024 | private static boolean isAttributeIgnored ( Node receivedElement , Node receivedAttribute , Set < String > ignoreMessageElements , NamespaceContext namespaceContext ) { if ( CollectionUtils . isEmpty ( ignoreMessageElements ) ) { return false ; } if ( ignoreMessageElements . contains ( XMLUtils . getNodesPathName ( receivedElement ) + "." + receivedAttribute . getNodeName ( ) ) ) { return true ; } for ( String expression : ignoreMessageElements ) { Node foundAttributeNode = XMLUtils . findNodeByName ( receivedElement . getOwnerDocument ( ) , expression ) ; if ( foundAttributeNode != null && receivedAttribute . isSameNode ( foundAttributeNode ) ) { return true ; } } for ( String expression : ignoreMessageElements ) { if ( XPathUtils . isXPathExpression ( expression ) ) { Node foundAttributeNode = XPathUtils . evaluateAsNode ( receivedElement . getOwnerDocument ( ) , expression , namespaceContext ) ; if ( foundAttributeNode != null && foundAttributeNode . isSameNode ( receivedAttribute ) ) { return true ; } } } return false ; } | Checks whether the current attribute is ignored . |
28,025 | public PurgeJmsQueuesBuilder withApplicationContext ( ApplicationContext applicationContext ) { if ( applicationContext . containsBean ( "connectionFactory" ) ) { connectionFactory ( applicationContext . getBean ( "connectionFactory" , ConnectionFactory . class ) ) ; } return this ; } | Sets the Spring bean factory for using endpoint names . |
28,026 | public String getServerUrl ( ) { if ( StringUtils . hasText ( this . serverUrl ) ) { return serverUrl ; } else { return "service:jmx:" + protocol + ":///jndi/" + protocol + "://" + host + ":" + port + ( binding != null ? "/" + binding : "" ) ; } } | Gets the value of the serverUrl property . |
28,027 | public SoapClientResponseActionBuilder receive ( ) { SoapClientResponseActionBuilder soapClientResponseActionBuilder ; if ( soapClient != null ) { soapClientResponseActionBuilder = new SoapClientResponseActionBuilder ( action , soapClient ) ; } else { soapClientResponseActionBuilder = new SoapClientResponseActionBuilder ( action , soapClientUri ) ; } soapClientResponseActionBuilder . withApplicationContext ( applicationContext ) ; return soapClientResponseActionBuilder ; } | Generic response builder for expecting response messages on client . |
28,028 | public ConditionalBuilder when ( Object value , Matcher expression ) { action . setConditionExpression ( new HamcrestConditionExpression ( expression , value ) ) ; return this ; } | Condition which allows execution if evaluates to true . |
28,029 | public SoapFault locale ( String locale ) { LocaleEditor localeEditor = new LocaleEditor ( ) ; localeEditor . setAsText ( locale ) ; this . locale = ( Locale ) localeEditor . getValue ( ) ; return this ; } | Sets the locale used in SOAP fault . |
28,030 | public static SoapFault from ( org . springframework . ws . soap . SoapFault fault ) { QNameEditor qNameEditor = new QNameEditor ( ) ; qNameEditor . setValue ( fault . getFaultCode ( ) ) ; SoapFault soapFault = new SoapFault ( ) . faultCode ( qNameEditor . getAsText ( ) ) . faultActor ( fault . getFaultActorOrRole ( ) ) . faultString ( fault . getFaultStringOrReason ( ) ) ; if ( fault . getFaultDetail ( ) != null ) { Iterator < SoapFaultDetailElement > details = fault . getFaultDetail ( ) . getDetailEntries ( ) ; while ( details . hasNext ( ) ) { SoapFaultDetailElement soapFaultDetailElement = details . next ( ) ; soapFault . addFaultDetail ( extractFaultDetail ( soapFaultDetailElement ) ) ; } } return soapFault ; } | Builder method from Spring WS SOAP fault object . |
28,031 | private static String extractFaultDetail ( SoapFaultDetailElement detail ) { StringResult detailResult = new StringResult ( ) ; try { TransformerFactory transformerFactory = TransformerFactory . newInstance ( ) ; Transformer transformer = transformerFactory . newTransformer ( ) ; transformer . setOutputProperty ( OutputKeys . OMIT_XML_DECLARATION , "yes" ) ; transformer . transform ( detail . getSource ( ) , detailResult ) ; } catch ( TransformerException e ) { throw new CitrusRuntimeException ( e ) ; } return detailResult . toString ( ) ; } | Extracts fault detail string from soap fault detail instance . Transforms detail source into string and takes care . |
28,032 | public void extractVariables ( Message message , TestContext context ) { if ( CollectionUtils . isEmpty ( xPathExpressions ) ) { return ; } if ( log . isDebugEnabled ( ) ) { log . debug ( "Reading XML elements with XPath" ) ; } NamespaceContext nsContext = context . getNamespaceContextBuilder ( ) . buildContext ( message , namespaces ) ; for ( Entry < String , String > entry : xPathExpressions . entrySet ( ) ) { String pathExpression = context . replaceDynamicContentInString ( entry . getKey ( ) ) ; String variableName = entry . getValue ( ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Evaluating XPath expression: " + pathExpression ) ; } Document doc = XMLUtils . parseMessagePayload ( message . getPayload ( String . class ) ) ; if ( XPathUtils . isXPathExpression ( pathExpression ) ) { XPathExpressionResult resultType = XPathExpressionResult . fromString ( pathExpression , XPathExpressionResult . STRING ) ; pathExpression = XPathExpressionResult . cutOffPrefix ( pathExpression ) ; Object value = XPathUtils . evaluate ( doc , pathExpression , nsContext , resultType ) ; if ( value == null ) { throw new CitrusRuntimeException ( "Not able to find value for expression: " + pathExpression ) ; } if ( value instanceof List ) { value = StringUtils . arrayToCommaDelimitedString ( ( ( List ) value ) . toArray ( new String [ ( ( List ) value ) . size ( ) ] ) ) ; } context . setVariable ( variableName , value ) ; } else { Node node = XMLUtils . findNodeByName ( doc , pathExpression ) ; if ( node == null ) { throw new UnknownElementException ( "No element found for expression" + pathExpression ) ; } if ( node . getNodeType ( ) == Node . ELEMENT_NODE ) { if ( node . getFirstChild ( ) != null ) { context . setVariable ( xPathExpressions . get ( pathExpression ) , node . getFirstChild ( ) . getNodeValue ( ) ) ; } else { context . setVariable ( xPathExpressions . get ( pathExpression ) , "" ) ; } } else { context . setVariable ( xPathExpressions . get ( pathExpression ) , node . getNodeValue ( ) ) ; } } } } | Extract variables using Xpath expressions . |
28,033 | public String getFailureStackAsString ( ) { StringBuilder builder = new StringBuilder ( ) ; for ( FailureStackElement failureStackElement : getFailureStack ( ) ) { builder . append ( "\n\t" ) ; builder . append ( failureStackElement . getStackMessage ( ) ) ; } return builder . toString ( ) ; } | Get formatted string representation of failure stack information . |
28,034 | public Stack < FailureStackElement > getFailureStack ( ) { Stack < FailureStackElement > stack = new Stack < FailureStackElement > ( ) ; for ( FailureStackElement failureStackElement : failureStack ) { stack . push ( failureStackElement ) ; } return stack ; } | Gets the custom failure stack with line number information where the testcase failed . |
28,035 | private Condition parseHttpCondition ( Element element ) { HttpCondition condition = new HttpCondition ( ) ; condition . setUrl ( element . getAttribute ( "url" ) ) ; String method = element . getAttribute ( "method" ) ; if ( StringUtils . hasText ( method ) ) { condition . setMethod ( method ) ; } String statusCode = element . getAttribute ( "status" ) ; if ( StringUtils . hasText ( statusCode ) ) { condition . setHttpResponseCode ( statusCode ) ; } String timeout = element . getAttribute ( "timeout" ) ; if ( StringUtils . hasText ( timeout ) ) { condition . setTimeout ( timeout ) ; } return condition ; } | Parse Http request condition . |
28,036 | private Condition parseMessageCondition ( Element element ) { MessageCondition condition = new MessageCondition ( ) ; condition . setMessageName ( element . getAttribute ( "name" ) ) ; return condition ; } | Parse message store condition . |
28,037 | private BeanDefinition parseActionCondition ( Element element , ParserContext parserContext ) { Map < String , BeanDefinitionParser > actionRegistry = TestActionRegistry . getRegisteredActionParser ( ) ; Element action = DOMUtil . getFirstChildElement ( element ) ; if ( action != null ) { BeanDefinitionParser parser = actionRegistry . get ( action . getTagName ( ) ) ; if ( parser != null ) { return parser . parse ( action , parserContext ) ; } else { return parserContext . getReaderContext ( ) . getNamespaceHandlerResolver ( ) . resolve ( action . getNamespaceURI ( ) ) . parse ( action , parserContext ) ; } } throw new BeanCreationException ( "Invalid wait for action condition - action not set properly" ) ; } | Parse test action condition . |
28,038 | private Condition parseFileCondition ( Element element ) { FileCondition condition = new FileCondition ( ) ; condition . setFilePath ( element . getAttribute ( "path" ) ) ; return condition ; } | Parse file existence condition . |
28,039 | private void addDispatcherServlet ( ) { ServletHolder servletHolder = new ServletHolder ( new CitrusMessageDispatcherServlet ( this ) ) ; servletHolder . setName ( getServletName ( ) ) ; servletHolder . setInitParameter ( "contextConfigLocation" , contextConfigLocation ) ; servletHandler . addServlet ( servletHolder ) ; ServletMapping servletMapping = new ServletMapping ( ) ; servletMapping . setServletName ( getServletName ( ) ) ; servletMapping . setPathSpec ( servletMappingPath ) ; servletHandler . addServletMapping ( servletMapping ) ; } | Adds Citrus message dispatcher servlet . |
28,040 | public Connector [ ] getConnectors ( ) { if ( connectors != null ) { return Arrays . copyOf ( connectors , connectors . length ) ; } else { return new Connector [ ] { } ; } } | Gets the connectors . |
28,041 | public String getValidationScript ( TestContext context ) { try { if ( validationScriptResourcePath != null ) { return context . replaceDynamicContentInString ( FileUtils . readToString ( FileUtils . getFileResource ( validationScriptResourcePath , context ) , Charset . forName ( context . replaceDynamicContentInString ( validationScriptResourceCharset ) ) ) ) ; } else if ( validationScript != null ) { return context . replaceDynamicContentInString ( validationScript ) ; } else { return "" ; } } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to load validation script resource" , e ) ; } } | Constructs the actual validation script either from data or external resource . |
28,042 | public void setBinaryMediaTypes ( List < MediaType > binaryMediaTypes ) { requestMessageConverters . stream ( ) . filter ( converter -> converter instanceof ByteArrayHttpMessageConverter ) . map ( ByteArrayHttpMessageConverter . class :: cast ) . forEach ( converter -> converter . setSupportedMediaTypes ( binaryMediaTypes ) ) ; responseMessageConverters . stream ( ) . filter ( converter -> converter instanceof ByteArrayHttpMessageConverter ) . map ( ByteArrayHttpMessageConverter . class :: cast ) . forEach ( converter -> converter . setSupportedMediaTypes ( binaryMediaTypes ) ) ; } | Sets the binaryMediaTypes . |
28,043 | public void doWithMessage ( WebServiceMessage requestMessage ) throws IOException , TransformerException { endpointConfiguration . getMessageConverter ( ) . convertOutbound ( requestMessage , message , endpointConfiguration , context ) ; } | Callback method called before request message is sent . |
28,044 | private void copyCookies ( final Message message ) { if ( message instanceof HttpMessage ) { this . cookies . putAll ( ( ( HttpMessage ) message ) . getCookiesMap ( ) ) ; } } | Sets the cookies extracted from the given message as far as it is a HttpMessage |
28,045 | public HttpMessage status ( final HttpStatus statusCode ) { statusCode ( statusCode . value ( ) ) ; reasonPhrase ( statusCode . name ( ) ) ; return this ; } | Sets the Http response status code . |
28,046 | public HttpMessage uri ( final String requestUri ) { setHeader ( DynamicEndpointUriResolver . ENDPOINT_URI_HEADER_NAME , requestUri ) ; setHeader ( HttpMessageHeaders . HTTP_REQUEST_URI , requestUri ) ; return this ; } | Sets the Http request request uri header . |
28,047 | public HttpMessage queryParam ( final String name , final String value ) { if ( ! StringUtils . hasText ( name ) ) { throw new CitrusRuntimeException ( "Invalid query param name - must not be empty!" ) ; } this . addQueryParam ( name , value ) ; final String queryParamString = queryParams . entrySet ( ) . stream ( ) . map ( this :: outputQueryParam ) . collect ( Collectors . joining ( "," ) ) ; header ( HttpMessageHeaders . HTTP_QUERY_PARAMS , queryParamString ) ; header ( DynamicEndpointUriResolver . QUERY_PARAM_HEADER_NAME , queryParamString ) ; return this ; } | Sets a new Http request query param . |
28,048 | public HttpMessage path ( final String path ) { header ( HttpMessageHeaders . HTTP_REQUEST_URI , path ) ; header ( DynamicEndpointUriResolver . REQUEST_PATH_HEADER_NAME , path ) ; return this ; } | Sets request path that is dynamically added to base uri . |
28,049 | public HttpMethod getRequestMethod ( ) { final Object method = getHeader ( HttpMessageHeaders . HTTP_REQUEST_METHOD ) ; if ( method != null ) { return HttpMethod . valueOf ( method . toString ( ) ) ; } return null ; } | Gets the Http request method . |
28,050 | public String getUri ( ) { final Object requestUri = getHeader ( HttpMessageHeaders . HTTP_REQUEST_URI ) ; if ( requestUri != null ) { return requestUri . toString ( ) ; } return null ; } | Gets the Http request request uri . |
28,051 | public String getContextPath ( ) { final Object contextPath = getHeader ( HttpMessageHeaders . HTTP_CONTEXT_PATH ) ; if ( contextPath != null ) { return contextPath . toString ( ) ; } return null ; } | Gets the Http request context path . |
28,052 | public String getContentType ( ) { final Object contentType = getHeader ( HttpMessageHeaders . HTTP_CONTENT_TYPE ) ; if ( contentType != null ) { return contentType . toString ( ) ; } return null ; } | Gets the Http content type header . |
28,053 | public String getAccept ( ) { final Object accept = getHeader ( "Accept" ) ; if ( accept != null ) { return accept . toString ( ) ; } return null ; } | Gets the accept header . |
28,054 | public String getQueryParamString ( ) { return Optional . ofNullable ( getHeader ( HttpMessageHeaders . HTTP_QUERY_PARAMS ) ) . map ( Object :: toString ) . orElse ( "" ) ; } | Gets the Http request query param string . |
28,055 | public HttpStatus getStatusCode ( ) { final Object statusCode = getHeader ( HttpMessageHeaders . HTTP_STATUS_CODE ) ; if ( statusCode != null ) { if ( statusCode instanceof HttpStatus ) { return ( HttpStatus ) statusCode ; } else if ( statusCode instanceof Integer ) { return HttpStatus . valueOf ( ( Integer ) statusCode ) ; } else { return HttpStatus . valueOf ( Integer . valueOf ( statusCode . toString ( ) ) ) ; } } return null ; } | Gets the Http response status code . |
28,056 | public String getReasonPhrase ( ) { final Object reasonPhrase = getHeader ( HttpMessageHeaders . HTTP_REASON_PHRASE ) ; if ( reasonPhrase != null ) { return reasonPhrase . toString ( ) ; } return null ; } | Gets the Http response reason phrase . |
28,057 | public String getVersion ( ) { final Object version = getHeader ( HttpMessageHeaders . HTTP_VERSION ) ; if ( version != null ) { return version . toString ( ) ; } return null ; } | Gets the Http version . |
28,058 | public String getPath ( ) { final Object path = getHeader ( DynamicEndpointUriResolver . REQUEST_PATH_HEADER_NAME ) ; if ( path != null ) { return path . toString ( ) ; } return null ; } | Gets the request path after the context path . |
28,059 | public void setCookies ( final Cookie [ ] cookies ) { this . cookies . clear ( ) ; if ( cookies != null ) { for ( final Cookie cookie : cookies ) { cookie ( cookie ) ; } } } | Sets the cookies . |
28,060 | public HttpMessage cookie ( final Cookie cookie ) { this . cookies . put ( cookie . getName ( ) , cookie ) ; setHeader ( HttpMessageHeaders . HTTP_COOKIE_PREFIX + cookie . getName ( ) , cookieConverter . getCookieString ( cookie ) ) ; return this ; } | Adds new cookie to this http message . |
28,061 | public static HttpMessage fromRequestData ( final String requestData ) { try ( final BufferedReader reader = new BufferedReader ( new StringReader ( requestData ) ) ) { final HttpMessage request = new HttpMessage ( ) ; final String [ ] requestLine = reader . readLine ( ) . split ( "\\s" ) ; if ( requestLine . length > 0 ) { request . method ( HttpMethod . valueOf ( requestLine [ 0 ] ) ) ; } if ( requestLine . length > 1 ) { request . uri ( requestLine [ 1 ] ) ; } if ( requestLine . length > 2 ) { request . version ( requestLine [ 2 ] ) ; } return parseHttpMessage ( reader , request ) ; } catch ( final IOException e ) { throw new CitrusRuntimeException ( "Failed to parse Http raw request data" , e ) ; } } | Reads request from complete request dump . |
28,062 | public static HttpMessage fromResponseData ( final String responseData ) { try ( final BufferedReader reader = new BufferedReader ( new StringReader ( responseData ) ) ) { final HttpMessage response = new HttpMessage ( ) ; final String [ ] statusLine = reader . readLine ( ) . split ( "\\s" ) ; if ( statusLine . length > 0 ) { response . version ( statusLine [ 0 ] ) ; } if ( statusLine . length > 1 ) { response . status ( HttpStatus . valueOf ( Integer . valueOf ( statusLine [ 1 ] ) ) ) ; } return parseHttpMessage ( reader , response ) ; } catch ( final IOException e ) { throw new CitrusRuntimeException ( "Failed to parse Http raw response data" , e ) ; } } | Reads response from complete response dump . |
28,063 | public void loadPropertiesAsVariables ( ) { BufferedReader reader = null ; try { if ( propertyFilesSet ( ) ) { for ( String propertyFilePath : propertyFiles ) { Resource propertyFile = new PathMatchingResourcePatternResolver ( ) . getResource ( propertyFilePath . trim ( ) ) ; log . debug ( "Reading property file " + propertyFile . getFilename ( ) ) ; reader = new BufferedReader ( new InputStreamReader ( propertyFile . getInputStream ( ) ) ) ; TestContext context = new TestContext ( ) ; context . setFunctionRegistry ( functionRegistry ) ; context . setGlobalVariables ( globalVariables ) ; String propertyExpression ; while ( ( propertyExpression = reader . readLine ( ) ) != null ) { log . debug ( "Property line [ {} ]" , propertyExpression ) ; propertyExpression = propertyExpression . trim ( ) ; if ( ! isPropertyLine ( propertyExpression ) ) { continue ; } String key = propertyExpression . substring ( 0 , propertyExpression . indexOf ( '=' ) ) . trim ( ) ; String value = propertyExpression . substring ( propertyExpression . indexOf ( '=' ) + 1 ) . trim ( ) ; log . debug ( "Property value replace dynamic content [ {} ]" , value ) ; value = context . replaceDynamicContentInString ( value ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Loading property: " + key + "=" + value + " into default variables" ) ; } if ( log . isDebugEnabled ( ) && globalVariables . getVariables ( ) . containsKey ( key ) ) { log . debug ( "Overwriting property " + key + " old value:" + globalVariables . getVariables ( ) . get ( key ) + " new value:" + value ) ; } globalVariables . getVariables ( ) . put ( key , value ) ; context . setVariable ( key , globalVariables . getVariables ( ) . get ( key ) ) ; } log . info ( "Loaded property file " + propertyFile . getFilename ( ) ) ; } } } catch ( IOException e ) { throw new CitrusRuntimeException ( "Error while loading property file" , e ) ; } finally { if ( reader != null ) { try { reader . close ( ) ; } catch ( IOException e ) { log . warn ( "Unable to close property file reader" , e ) ; } } } } | Load the properties as variables . |
28,064 | private int invokeUrl ( TestContext context ) { URL contextUrl = getUrl ( context ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( String . format ( "Probing Http request url '%s'" , contextUrl . toExternalForm ( ) ) ) ; } int responseCode = - 1 ; HttpURLConnection httpURLConnection = null ; try { httpURLConnection = openConnection ( contextUrl ) ; httpURLConnection . setConnectTimeout ( getTimeout ( context ) ) ; httpURLConnection . setRequestMethod ( context . resolveDynamicValue ( method ) ) ; responseCode = httpURLConnection . getResponseCode ( ) ; } catch ( IOException e ) { log . warn ( String . format ( "Could not access Http url '%s' - %s" , contextUrl . toExternalForm ( ) , e . getMessage ( ) ) ) ; } finally { if ( httpURLConnection != null ) { httpURLConnection . disconnect ( ) ; } } return responseCode ; } | Invokes Http request URL and returns response code . |
28,065 | private URL getUrl ( TestContext context ) { try { return new URL ( context . replaceDynamicContentInString ( this . url ) ) ; } catch ( MalformedURLException e ) { throw new CitrusRuntimeException ( "Invalid request url" , e ) ; } } | Gets the request url with test variable support . |
28,066 | private SoapFault constructControlFault ( TestContext context ) { SoapFault controlFault = new SoapFault ( ) ; if ( StringUtils . hasText ( faultActor ) ) { controlFault . faultActor ( context . replaceDynamicContentInString ( faultActor ) ) ; } controlFault . faultCode ( context . replaceDynamicContentInString ( faultCode ) ) ; controlFault . faultString ( context . replaceDynamicContentInString ( faultString ) ) ; for ( String faultDetail : faultDetails ) { controlFault . addFaultDetail ( context . replaceDynamicContentInString ( faultDetail ) ) ; } try { for ( String faultDetailPath : faultDetailResourcePaths ) { String resourcePath = context . replaceDynamicContentInString ( faultDetailPath ) ; controlFault . addFaultDetail ( context . replaceDynamicContentInString ( FileUtils . readToString ( FileUtils . getFileResource ( resourcePath , context ) , FileUtils . getCharset ( resourcePath ) ) ) ) ; } } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to create SOAP fault detail from file resource" , e ) ; } return controlFault ; } | Constructs the control soap fault holding all expected fault information like faultCode faultString and faultDetail . |
28,067 | private KubernetesCommand < ? > getCommandByName ( String commandName ) { if ( ! StringUtils . hasText ( commandName ) ) { throw new CitrusRuntimeException ( "Missing command name property" ) ; } switch ( commandName ) { case "info" : return new Info ( ) ; case "list-events" : return new ListEvents ( ) ; case "list-endpoints" : return new ListEndpoints ( ) ; case "create-pod" : return new CreatePod ( ) ; case "get-pod" : return new GetPod ( ) ; case "delete-pod" : return new DeletePod ( ) ; case "list-pods" : return new ListPods ( ) ; case "watch-pods" : return new WatchPods ( ) ; case "list-namespaces" : return new ListNamespaces ( ) ; case "watch-namespaces" : return new WatchNamespaces ( ) ; case "list-nodes" : return new ListNodes ( ) ; case "watch-nodes" : return new WatchNodes ( ) ; case "list-replication-controllers" : return new ListReplicationControllers ( ) ; case "watch-replication-controllers" : return new WatchReplicationControllers ( ) ; case "create-service" : return new CreateService ( ) ; case "get-service" : return new GetService ( ) ; case "delete-service" : return new DeleteService ( ) ; case "list-services" : return new ListServices ( ) ; case "watch-services" : return new WatchServices ( ) ; default : throw new CitrusRuntimeException ( "Unknown kubernetes command: " + commandName ) ; } } | Creates a new kubernetes command message model object from message headers . |
28,068 | private Map < String , Object > createMessageHeaders ( KubernetesCommand < ? > command ) { Map < String , Object > headers = new HashMap < String , Object > ( ) ; headers . put ( KubernetesMessageHeaders . COMMAND , command . getName ( ) ) ; for ( Map . Entry < String , Object > entry : command . getParameters ( ) . entrySet ( ) ) { headers . put ( entry . getKey ( ) , entry . getValue ( ) ) ; } return headers ; } | Reads basic command information and converts to message headers . |
28,069 | private Volume [ ] getVolumes ( TestContext context ) { String [ ] volumes = StringUtils . commaDelimitedListToStringArray ( getParameter ( "volumes" , context ) ) ; Volume [ ] volumeSpecs = new Volume [ volumes . length ] ; for ( int i = 0 ; i < volumes . length ; i ++ ) { volumeSpecs [ i ] = new Volume ( volumes [ i ] ) ; } return volumeSpecs ; } | Gets the volume specs from comma delimited string . |
28,070 | private Capability [ ] getCapabilities ( String addDrop , TestContext context ) { String [ ] capabilities = StringUtils . commaDelimitedListToStringArray ( getParameter ( addDrop , context ) ) ; Capability [ ] capAdd = new Capability [ capabilities . length ] ; for ( int i = 0 ; i < capabilities . length ; i ++ ) { capAdd [ i ] = Capability . valueOf ( capabilities [ i ] ) ; } return capAdd ; } | Gets the capabilities added . |
28,071 | private ExposedPort [ ] getExposedPorts ( String portSpecs , TestContext context ) { String [ ] ports = StringUtils . commaDelimitedListToStringArray ( portSpecs ) ; ExposedPort [ ] exposedPorts = new ExposedPort [ ports . length ] ; for ( int i = 0 ; i < ports . length ; i ++ ) { String portSpec = context . replaceDynamicContentInString ( ports [ i ] ) ; if ( portSpec . startsWith ( "udp:" ) ) { exposedPorts [ i ] = ExposedPort . udp ( Integer . valueOf ( portSpec . substring ( "udp:" . length ( ) ) ) ) ; } else if ( portSpec . startsWith ( "tcp:" ) ) { exposedPorts [ i ] = ExposedPort . tcp ( Integer . valueOf ( portSpec . substring ( "tcp:" . length ( ) ) ) ) ; } else { exposedPorts [ i ] = ExposedPort . tcp ( Integer . valueOf ( portSpec ) ) ; } } return exposedPorts ; } | Construct set of exposed ports from comma delimited list of ports . |
28,072 | private Ports getPortBindings ( String portSpecs , ExposedPort [ ] exposedPorts , TestContext context ) { String [ ] ports = StringUtils . commaDelimitedListToStringArray ( portSpecs ) ; Ports portsBindings = new Ports ( ) ; for ( String portSpec : ports ) { String [ ] binding = context . replaceDynamicContentInString ( portSpec ) . split ( ":" ) ; if ( binding . length == 2 ) { Integer hostPort = Integer . valueOf ( binding [ 0 ] ) ; Integer port = Integer . valueOf ( binding [ 1 ] ) ; portsBindings . bind ( Stream . of ( exposedPorts ) . filter ( exposed -> port . equals ( exposed . getPort ( ) ) ) . findAny ( ) . orElse ( ExposedPort . tcp ( port ) ) , Ports . Binding . bindPort ( hostPort ) ) ; } } Stream . of ( exposedPorts ) . filter ( exposed -> ! portsBindings . getBindings ( ) . keySet ( ) . contains ( exposed ) ) . forEach ( exposed -> portsBindings . bind ( exposed , Ports . Binding . empty ( ) ) ) ; return portsBindings ; } | Construct set of port bindings from comma delimited list of ports . |
28,073 | private void buildOutMessage ( Exchange exchange , Message message ) { org . apache . camel . Message reply = exchange . getOut ( ) ; for ( Map . Entry < String , Object > header : message . getHeaders ( ) . entrySet ( ) ) { if ( ! header . getKey ( ) . startsWith ( MessageHeaders . PREFIX ) ) { reply . setHeader ( header . getKey ( ) , header . getValue ( ) ) ; } } if ( message . getHeader ( CitrusCamelMessageHeaders . EXCHANGE_EXCEPTION ) != null ) { String exceptionClass = message . getHeader ( CitrusCamelMessageHeaders . EXCHANGE_EXCEPTION ) . toString ( ) ; String exceptionMsg = null ; if ( message . getHeader ( CitrusCamelMessageHeaders . EXCHANGE_EXCEPTION_MESSAGE ) != null ) { exceptionMsg = message . getHeader ( CitrusCamelMessageHeaders . EXCHANGE_EXCEPTION_MESSAGE ) . toString ( ) ; } try { Class < ? > exception = Class . forName ( exceptionClass ) ; if ( exceptionMsg != null ) { exchange . setException ( ( Throwable ) exception . getConstructor ( String . class ) . newInstance ( exceptionMsg ) ) ; } else { exchange . setException ( ( Throwable ) exception . newInstance ( ) ) ; } } catch ( RuntimeException e ) { log . warn ( "Unable to create proper exception instance for exchange!" , e ) ; } catch ( Exception e ) { log . warn ( "Unable to create proper exception instance for exchange!" , e ) ; } } reply . setBody ( message . getPayload ( ) ) ; } | Builds response and sets it as out message on given Camel exchange . |
28,074 | protected Message createMessage ( TestContext context , String messageType ) { if ( dataDictionary != null ) { messageBuilder . setDataDictionary ( dataDictionary ) ; } return messageBuilder . buildMessageContent ( context , messageType , MessageDirection . OUTBOUND ) ; } | Create message to be sent . |
28,075 | private MBeanServerConnection getNetworkConnection ( ) { try { JMXServiceURL url = new JMXServiceURL ( getEndpointConfiguration ( ) . getServerUrl ( ) ) ; String [ ] creds = { getEndpointConfiguration ( ) . getUsername ( ) , getEndpointConfiguration ( ) . getPassword ( ) } ; JMXConnector networkConnector = JMXConnectorFactory . connect ( url , Collections . singletonMap ( JMXConnector . CREDENTIALS , creds ) ) ; connectionId = networkConnector . getConnectionId ( ) ; networkConnector . addConnectionNotificationListener ( this , null , null ) ; return networkConnector . getMBeanServerConnection ( ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to connect to network MBean server" , e ) ; } } | Establish network connection to remote mBean server . |
28,076 | private boolean connectionLost ( JMXConnectionNotification connectionNotification ) { return connectionNotification . getType ( ) . equals ( JMXConnectionNotification . NOTIFS_LOST ) || connectionNotification . getType ( ) . equals ( JMXConnectionNotification . CLOSED ) || connectionNotification . getType ( ) . equals ( JMXConnectionNotification . FAILED ) ; } | Finds connection lost type notifications . |
28,077 | public void scheduleReconnect ( ) { Runnable startRunnable = new Runnable ( ) { public void run ( ) { try { MBeanServerConnection serverConnection = getNetworkConnection ( ) ; if ( notificationListener != null ) { serverConnection . addNotificationListener ( objectName , notificationListener , getEndpointConfiguration ( ) . getNotificationFilter ( ) , getEndpointConfiguration ( ) . getNotificationHandback ( ) ) ; } } catch ( Exception e ) { log . warn ( "Failed to reconnect to JMX MBean server. {}" , e . getMessage ( ) ) ; scheduleReconnect ( ) ; } } } ; log . info ( "Reconnecting to MBean server {} in {} milliseconds." , getEndpointConfiguration ( ) . getServerUrl ( ) , getEndpointConfiguration ( ) . getDelayOnReconnect ( ) ) ; scheduledExecutor . schedule ( startRunnable , getEndpointConfiguration ( ) . getDelayOnReconnect ( ) , TimeUnit . MILLISECONDS ) ; } | Schedules an attempt to re - initialize a lost connection after the reconnect delay |
28,078 | private void addNotificationListener ( ObjectName objectName , final String correlationKey , MBeanServerConnection serverConnection ) { try { notificationListener = new NotificationListener ( ) { public void handleNotification ( Notification notification , Object handback ) { correlationManager . store ( correlationKey , new DefaultMessage ( notification . getMessage ( ) ) ) ; } } ; serverConnection . addNotificationListener ( objectName , notificationListener , getEndpointConfiguration ( ) . getNotificationFilter ( ) , getEndpointConfiguration ( ) . getNotificationHandback ( ) ) ; } catch ( InstanceNotFoundException e ) { throw new CitrusRuntimeException ( "Failed to find object name instance" , e ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to add notification listener" , e ) ; } } | Add notification listener for response messages . |
28,079 | public AntRunBuilder targets ( String ... targets ) { action . setTargets ( StringUtils . collectionToCommaDelimitedString ( Arrays . asList ( targets ) ) ) ; return this ; } | Multiple build target names to call . |
28,080 | public AntRunBuilder property ( String name , Object value ) { action . getProperties ( ) . put ( name , value ) ; return this ; } | Adds a build property by name and value . |
28,081 | private CitrusWebSocketHandler getWebSocketClientHandler ( String url ) { CitrusWebSocketHandler handler = new CitrusWebSocketHandler ( ) ; if ( webSocketHttpHeaders == null ) { webSocketHttpHeaders = new WebSocketHttpHeaders ( ) ; webSocketHttpHeaders . setSecWebSocketExtensions ( Collections . singletonList ( new StandardToWebSocketExtensionAdapter ( new JsrExtension ( new PerMessageDeflateExtension ( ) . getName ( ) ) ) ) ) ; } ListenableFuture < WebSocketSession > future = client . doHandshake ( handler , webSocketHttpHeaders , UriComponentsBuilder . fromUriString ( url ) . buildAndExpand ( ) . encode ( ) . toUri ( ) ) ; try { future . get ( ) ; } catch ( Exception e ) { String errMsg = String . format ( "Failed to connect to Web Socket server - '%s'" , url ) ; LOG . error ( errMsg ) ; throw new CitrusRuntimeException ( errMsg ) ; } return handler ; } | Creates new client web socket handler by opening a new socket connection to server . |
28,082 | public static void main ( String [ ] args ) { CitrusApp citrusApp = new CitrusApp ( args ) ; if ( citrusApp . configuration . getTimeToLive ( ) > 0 ) { CompletableFuture . runAsync ( ( ) -> { try { new CompletableFuture < Void > ( ) . get ( citrusApp . configuration . getTimeToLive ( ) , TimeUnit . MILLISECONDS ) ; } catch ( InterruptedException | ExecutionException | TimeoutException e ) { log . info ( String . format ( "Shutdown Citrus application after %s ms" , citrusApp . configuration . getTimeToLive ( ) ) ) ; citrusApp . stop ( ) ; } } ) ; } if ( citrusApp . configuration . isSkipTests ( ) ) { if ( citrusApp . configuration . getConfigClass ( ) != null ) { Citrus . newInstance ( citrusApp . configuration . getConfigClass ( ) ) ; } else { Citrus . newInstance ( ) ; } setDefaultProperties ( citrusApp . configuration ) ; } else { try { citrusApp . run ( ) ; } finally { if ( citrusApp . configuration . getTimeToLive ( ) == 0 ) { citrusApp . stop ( ) ; } } } if ( citrusApp . configuration . isSystemExit ( ) ) { if ( citrusApp . waitForCompletion ( ) ) { System . exit ( 0 ) ; } else { System . exit ( - 1 ) ; } } else { citrusApp . waitForCompletion ( ) ; } } | Main method with command line arguments . |
28,083 | public void run ( ) { if ( isCompleted ( ) ) { log . info ( "Not executing tests as application state is completed!" ) ; return ; } log . info ( String . format ( "Running Citrus %s" , Citrus . getVersion ( ) ) ) ; setDefaultProperties ( configuration ) ; if ( ClassUtils . isPresent ( "org.testng.annotations.Test" , getClass ( ) . getClassLoader ( ) ) ) { new TestNGEngine ( configuration ) . run ( ) ; } else if ( ClassUtils . isPresent ( "org.junit.Test" , getClass ( ) . getClassLoader ( ) ) ) { new JUnit4TestEngine ( configuration ) . run ( ) ; } } | Run application with prepared Citrus instance . |
28,084 | private void stop ( ) { complete ( ) ; Citrus citrus = Citrus . CitrusInstanceManager . getSingleton ( ) ; if ( citrus != null ) { log . info ( "Closing Citrus and its application context" ) ; citrus . close ( ) ; } } | Stop application by setting completed state and stop application context . |
28,085 | private static void setDefaultProperties ( CitrusAppConfiguration configuration ) { for ( Map . Entry < String , String > entry : configuration . getDefaultProperties ( ) . entrySet ( ) ) { log . debug ( String . format ( "Setting application property %s=%s" , entry . getKey ( ) , entry . getValue ( ) ) ) ; System . setProperty ( entry . getKey ( ) , Optional . ofNullable ( entry . getValue ( ) ) . orElse ( "" ) ) ; } } | Reads default properties in configuration and sets them as system properties . |
28,086 | protected void executeStatements ( TestContext context ) { for ( String stmt : statements ) { try { final String toExecute = context . replaceDynamicContentInString ( stmt . trim ( ) ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Executing PLSQL statement: " + toExecute ) ; } getJdbcTemplate ( ) . execute ( toExecute ) ; log . info ( "PLSQL statement execution successful" ) ; } catch ( DataAccessException e ) { if ( ignoreErrors ) { log . warn ( "Ignoring error while executing PLSQL statement: " + e . getMessage ( ) ) ; continue ; } else { throw new CitrusRuntimeException ( "Failed to execute PLSQL statement" , e ) ; } } } } | Run all PLSQL statements . |
28,087 | private List < String > createStatementsFromScript ( TestContext context ) { List < String > stmts = new ArrayList < > ( ) ; script = context . replaceDynamicContentInString ( script ) ; if ( log . isDebugEnabled ( ) ) { log . debug ( "Found inline PLSQL script " + script ) ; } StringTokenizer tok = new StringTokenizer ( script , PLSQL_STMT_ENDING ) ; while ( tok . hasMoreTokens ( ) ) { String next = tok . nextToken ( ) . trim ( ) ; if ( StringUtils . hasText ( next ) ) { stmts . add ( next ) ; } } return stmts ; } | Create SQL statements from inline script . |
28,088 | public static RmiServiceInvocation create ( Object remoteTarget , Method method , Object [ ] args ) { RmiServiceInvocation serviceInvocation = new RmiServiceInvocation ( ) ; if ( Proxy . isProxyClass ( remoteTarget . getClass ( ) ) ) { serviceInvocation . setRemote ( method . getDeclaringClass ( ) . getName ( ) ) ; } else { serviceInvocation . setRemote ( remoteTarget . getClass ( ) . getName ( ) ) ; } serviceInvocation . setMethod ( method . getName ( ) ) ; if ( args != null ) { serviceInvocation . setArgs ( new RmiServiceInvocation . Args ( ) ) ; for ( Object arg : args ) { MethodArg methodArg = new MethodArg ( ) ; methodArg . setValueObject ( arg ) ; if ( Map . class . isAssignableFrom ( arg . getClass ( ) ) ) { methodArg . setType ( Map . class . getName ( ) ) ; } else if ( List . class . isAssignableFrom ( arg . getClass ( ) ) ) { methodArg . setType ( List . class . getName ( ) ) ; } else { methodArg . setType ( arg . getClass ( ) . getName ( ) ) ; } serviceInvocation . getArgs ( ) . getArgs ( ) . add ( methodArg ) ; } } return serviceInvocation ; } | Static create method from target object and method definition . |
28,089 | public Class [ ] getArgTypes ( ) { List < Class > types = new ArrayList < > ( ) ; if ( args != null ) { for ( MethodArg arg : args . getArgs ( ) ) { try { types . add ( Class . forName ( arg . getType ( ) ) ) ; } catch ( ClassNotFoundException e ) { throw new CitrusRuntimeException ( "Failed to access method argument type" , e ) ; } } } return types . toArray ( new Class [ types . size ( ) ] ) ; } | Gets the argument types from list of args . |
28,090 | public Object [ ] getArgValues ( ApplicationContext applicationContext ) { List < Object > argValues = new ArrayList < > ( ) ; try { if ( args != null ) { for ( MethodArg methodArg : args . getArgs ( ) ) { Class argType = Class . forName ( methodArg . getType ( ) ) ; Object value = null ; if ( methodArg . getValueObject ( ) != null ) { value = methodArg . getValueObject ( ) ; } else if ( methodArg . getValue ( ) != null ) { value = methodArg . getValue ( ) ; } else if ( StringUtils . hasText ( methodArg . getRef ( ) ) && applicationContext != null ) { value = applicationContext . getBean ( methodArg . getRef ( ) ) ; } if ( value == null ) { argValues . add ( null ) ; } else if ( argType . isInstance ( value ) || argType . isAssignableFrom ( value . getClass ( ) ) ) { argValues . add ( argType . cast ( value ) ) ; } else if ( Map . class . equals ( argType ) ) { String mapString = value . toString ( ) ; Properties props = new Properties ( ) ; try { props . load ( new StringReader ( mapString . substring ( 1 , mapString . length ( ) - 1 ) . replace ( ", " , "\n" ) ) ) ; } catch ( IOException e ) { throw new CitrusRuntimeException ( "Failed to reconstruct method argument of type map" , e ) ; } Map < String , String > map = new LinkedHashMap < > ( ) ; for ( Map . Entry < Object , Object > entry : props . entrySet ( ) ) { map . put ( entry . getKey ( ) . toString ( ) , entry . getValue ( ) . toString ( ) ) ; } argValues . add ( map ) ; } else { try { argValues . add ( new SimpleTypeConverter ( ) . convertIfNecessary ( value , argType ) ) ; } catch ( ConversionNotSupportedException e ) { if ( String . class . equals ( argType ) ) { argValues . add ( value . toString ( ) ) ; } throw e ; } } } } } catch ( ClassNotFoundException e ) { throw new CitrusRuntimeException ( "Failed to construct method arg objects" , e ) ; } return argValues . toArray ( new Object [ argValues . size ( ) ] ) ; } | Gets method args as objects . Automatically converts simple types and ready referenced beans . |
28,091 | private BeanDefinitionBuilder parseSqlAction ( Element element ) { BeanDefinitionBuilder beanDefinition = BeanDefinitionBuilder . rootBeanDefinition ( ExecuteSQLAction . class ) ; String ignoreErrors = element . getAttribute ( "ignore-errors" ) ; if ( ignoreErrors != null && ignoreErrors . equals ( "true" ) ) { beanDefinition . addPropertyValue ( "ignoreErrors" , true ) ; } return beanDefinition ; } | Parses SQL action just executing a set of statements . |
28,092 | private BeanDefinitionBuilder parseSqlQueryAction ( Element element , Element scriptValidationElement , List < Element > validateElements , List < Element > extractElements ) { BeanDefinitionBuilder beanDefinition = BeanDefinitionBuilder . rootBeanDefinition ( ExecuteSQLQueryAction . class ) ; if ( scriptValidationElement != null ) { beanDefinition . addPropertyValue ( "scriptValidationContext" , getScriptValidationContext ( scriptValidationElement ) ) ; } Map < String , List < String > > controlResultSet = new HashMap < String , List < String > > ( ) ; for ( Iterator < ? > iter = validateElements . iterator ( ) ; iter . hasNext ( ) ; ) { Element validateElement = ( Element ) iter . next ( ) ; Element valueListElement = DomUtils . getChildElementByTagName ( validateElement , "values" ) ; if ( valueListElement != null ) { List < String > valueList = new ArrayList < String > ( ) ; List < ? > valueElements = DomUtils . getChildElementsByTagName ( valueListElement , "value" ) ; for ( Iterator < ? > valueElementsIt = valueElements . iterator ( ) ; valueElementsIt . hasNext ( ) ; ) { Element valueElement = ( Element ) valueElementsIt . next ( ) ; valueList . add ( DomUtils . getTextValue ( valueElement ) ) ; } controlResultSet . put ( validateElement . getAttribute ( "column" ) , valueList ) ; } else if ( validateElement . hasAttribute ( "value" ) ) { controlResultSet . put ( validateElement . getAttribute ( "column" ) , Collections . singletonList ( validateElement . getAttribute ( "value" ) ) ) ; } else { throw new BeanCreationException ( element . getLocalName ( ) , "Neither value attribute nor value list is set for column validation: " + validateElement . getAttribute ( "column" ) ) ; } } beanDefinition . addPropertyValue ( "controlResultSet" , controlResultSet ) ; Map < String , String > extractVariables = new HashMap < String , String > ( ) ; for ( Iterator < ? > iter = extractElements . iterator ( ) ; iter . hasNext ( ) ; ) { Element validate = ( Element ) iter . next ( ) ; extractVariables . put ( validate . getAttribute ( "column" ) , validate . getAttribute ( "variable" ) ) ; } beanDefinition . addPropertyValue ( "extractVariables" , extractVariables ) ; return beanDefinition ; } | Parses SQL query action with result set validation elements . |
28,093 | private ScriptValidationContext getScriptValidationContext ( Element scriptElement ) { String type = scriptElement . getAttribute ( "type" ) ; ScriptValidationContext validationContext = new ScriptValidationContext ( type ) ; String filePath = scriptElement . getAttribute ( "file" ) ; if ( StringUtils . hasText ( filePath ) ) { validationContext . setValidationScriptResourcePath ( filePath ) ; } else { validationContext . setValidationScript ( DomUtils . getTextValue ( scriptElement ) ) ; } return validationContext ; } | Constructs the script validation context . |
28,094 | public void stop ( ) { try { if ( CollectionUtils . isEmpty ( consumer . subscription ( ) ) ) { consumer . unsubscribe ( ) ; } } finally { consumer . close ( Duration . ofMillis ( 10 * 1000L ) ) ; } } | Stop message listener container . |
28,095 | private org . apache . kafka . clients . consumer . KafkaConsumer < Object , Object > createConsumer ( ) { Map < String , Object > consumerProps = new HashMap < > ( ) ; consumerProps . put ( ConsumerConfig . CLIENT_ID_CONFIG , Optional . ofNullable ( endpointConfiguration . getClientId ( ) ) . orElse ( KafkaMessageHeaders . KAFKA_PREFIX + "consumer_" + UUID . randomUUID ( ) . toString ( ) ) ) ; consumerProps . put ( ConsumerConfig . GROUP_ID_CONFIG , endpointConfiguration . getConsumerGroup ( ) ) ; consumerProps . put ( ConsumerConfig . BOOTSTRAP_SERVERS_CONFIG , Optional . ofNullable ( endpointConfiguration . getServer ( ) ) . orElse ( "localhost:9092" ) ) ; consumerProps . put ( ConsumerConfig . MAX_POLL_RECORDS_CONFIG , 1 ) ; consumerProps . put ( ConsumerConfig . ENABLE_AUTO_COMMIT_CONFIG , endpointConfiguration . isAutoCommit ( ) ) ; consumerProps . put ( ConsumerConfig . AUTO_COMMIT_INTERVAL_MS_CONFIG , endpointConfiguration . getAutoCommitInterval ( ) ) ; consumerProps . put ( ConsumerConfig . AUTO_OFFSET_RESET_CONFIG , endpointConfiguration . getOffsetReset ( ) ) ; consumerProps . put ( ConsumerConfig . KEY_DESERIALIZER_CLASS_CONFIG , endpointConfiguration . getKeyDeserializer ( ) ) ; consumerProps . put ( ConsumerConfig . VALUE_DESERIALIZER_CLASS_CONFIG , endpointConfiguration . getValueDeserializer ( ) ) ; consumerProps . putAll ( endpointConfiguration . getConsumerProperties ( ) ) ; return new org . apache . kafka . clients . consumer . KafkaConsumer < > ( consumerProps ) ; } | Create new Kafka consumer with given endpoint configuration . |
28,096 | public void setConsumer ( org . apache . kafka . clients . consumer . KafkaConsumer < Object , Object > consumer ) { this . consumer = consumer ; } | Sets the consumer . |
28,097 | public TemplateBuilder load ( ApplicationContext applicationContext ) { Template rootTemplate = applicationContext . getBean ( action . getName ( ) , Template . class ) ; action . setGlobalContext ( rootTemplate . isGlobalContext ( ) ) ; action . setActor ( rootTemplate . getActor ( ) ) ; action . setActions ( rootTemplate . getActions ( ) ) ; action . setParameter ( rootTemplate . getParameter ( ) ) ; return this ; } | Loads template bean from Spring bean application context and sets attributes . |
28,098 | protected MessageChannel getDestinationChannel ( TestContext context ) { if ( endpointConfiguration . getChannel ( ) != null ) { return endpointConfiguration . getChannel ( ) ; } else if ( StringUtils . hasText ( endpointConfiguration . getChannelName ( ) ) ) { return resolveChannelName ( endpointConfiguration . getChannelName ( ) , context ) ; } else { throw new CitrusRuntimeException ( "Neither channel name nor channel object is set - " + "please specify destination channel" ) ; } } | Get the destination channel depending on settings in this message sender . Either a direct channel object is set or a channel name which will be resolved to a channel . |
28,099 | protected String getDestinationChannelName ( ) { if ( endpointConfiguration . getChannel ( ) != null ) { return endpointConfiguration . getChannel ( ) . toString ( ) ; } else if ( StringUtils . hasText ( endpointConfiguration . getChannelName ( ) ) ) { return endpointConfiguration . getChannelName ( ) ; } else { throw new CitrusRuntimeException ( "Neither channel name nor channel object is set - " + "please specify destination channel" ) ; } } | Gets the channel name depending on what is set in this message sender . Either channel name is set directly or channel object is consulted for channel name . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.