/** * {@inheritDoc} */ @Override public boolean evaluate(InvocationSequenceData invocSequence, ICachedDataService cachedDataService) { return evaluate(invocSequence, cachedDataService, 0); }
/** * Evaluates the string array against the snippet in the {@link StringMatchingExpression} * instance. * * @param stringValue * string to check * @return boolean evaluation result */ private boolean evaluateString(String stringValue) { switch (getMatchingType()) { case CONTAINS: return stringValue.contains(getSnippet()); case ENDS_WITH: return stringValue.endsWith(getSnippet()); case STARTS_WITH: return stringValue.startsWith(getSnippet()); case EQUALS: return stringValue.equals(getSnippet()); case REGEX: return stringValue.matches(getSnippet()); default: return false; } }
/** * * {@inheritDoc} */ @Override protected boolean isValidExpression(StringMatchingExpression expression) { return expression.getStringValueSource() instanceof HttpServerPortValueSource; } }
@Test public void searchInDepthMatching() { StringMatchingExpression strMatchingExpression = new StringMatchingExpression(PatternMatchingType.CONTAINS, "level_1_2"); strMatchingExpression.setStringValueSource(stringValueSource); strMatchingExpression.setSearchNodeInTrace(true); strMatchingExpression.setMaxSearchDepth(-1); boolean evaluationResult = strMatchingExpression.evaluate(root, cachedDataService); assertThat(evaluationResult, is(true)); }
@Test public void matchEmptyApplication() { StringMatchingExpression stringMatchingExpression = new StringMatchingExpression(PatternMatchingType.CONTAINS, "root"); stringMatchingExpression.setStringValueSource(stringValueSource); stringMatchingExpression.setSearchNodeInTrace(false); StringMatchingExpression stringMatchingExpression_2 = new StringMatchingExpression(PatternMatchingType.CONTAINS, "nothing"); stringMatchingExpression_2.setStringValueSource(stringValueSource); stringMatchingExpression_2.setSearchNodeInTrace(false); applicationDefinition.setMatchingRuleExpression(stringMatchingExpression_2); applicationDefinition_empty.setMatchingRuleExpression(stringMatchingExpression); processor.process(root, entityManager); assertThat(root.getApplicationId(), equalTo(application_empty.getId())); assertThat(root.getBusinessTransactionId(), equalTo(businessTx_unknown.getId())); }
/** * Recursive evaluation in the invocation sequence structure if search in trace is activated. * * @param invocSequence * {@link InvocationSequenceData} forming the evaluation context * @param cachedDataService * {@link ICachedDataService} instance for retrieval of method names etc. * @param depth * current search depth in the invocation sequence tree structure * @return Returns evaluation result. */ private boolean evaluate(InvocationSequenceData invocSequence, ICachedDataService cachedDataService, int depth) { String[] strArray = getStringValueSource().getStringValues(invocSequence, cachedDataService); if (ArrayUtils.isNotEmpty(strArray)) { for (String element : strArray) { if ((null != element) && evaluateString(element)) { return true; } } } if (isSearchNodeInTrace() && ((getMaxSearchDepth() < 0) || (depth < getMaxSearchDepth()))) { for (InvocationSequenceData childNode : invocSequence.getNestedSequences()) { if (evaluate(childNode, cachedDataService, depth + 1)) { return true; } } } return false; }
StringMatchingExpression expression = new StringMatchingExpression(PatternMatchingType.EQUALS, ""); expression.setStringValueSource(new HttpParameterValueSource("")); break; case HTTP_URL: expression.setStringValueSource(new HttpUrlValueSource()); break; case HTTP_SCHEME: expression.setStringValueSource(new HttpSchemeValueSource()); break; case HTTP_SERVER_NAME: expression.setStringValueSource(new HttpServerNameValueSource()); break; case HTTP_SERVER_PORT: expression.setStringValueSource(new HttpServerPortValueSource()); break; case HTTP_URI: expression.setStringValueSource(new HttpUriValueSource()); break; case HTTP_QUERY_STRING: expression.setStringValueSource(new HttpQueryStringValueSource()); break; case IP: expression.setStringValueSource(new HostValueSource()); break; case METHOD_SIGNATURE: expression.setStringValueSource(new MethodSignatureValueSource()); break; case METHOD_PARAMETER:
/** * {@inheritDoc} */ @Override protected void executeSpecificInitialization(StringMatchingExpression expression) { if (expression.isSearchNodeInTrace() && useSearchInDepthComposite) { searchInTraceCheckBox.setSelection(true); depthSpinner.setSelection(expression.getMaxSearchDepth()); depthSpinner.setEnabled(true); } }
AbstractValidationManager<AbstractExpression> upstreamValidationManager) { super(expression, ruleType, description, useSearchInTrace, editable, upstreamValidationManager); if (null == expression.getStringValueSource()) { throw new IllegalArgumentException("String value source of the expression must not be null!"); this.stringValueSource = (T) expression.getStringValueSource(); } else { throw new IllegalArgumentException("Invalid String Matching Expression type!"); expression.setMatchingType(PatternMatchingType.EQUALS); this.sourceName = sourceLabel;
/** * Validates the contents of the passed {@link StringMatchingExpression} without the need to * create corresponding editing controls. * * @param expression * {@link StringMatchingExpression} to validate * @param sourceName * the name of the string snippet source * @return a set of {@link ValidationState} instances. */ public static Set<ValidationState> validate(StringMatchingExpression expression, String sourceName) { Set<ValidationState> resultSet = new HashSet<>(); if (StringUtils.isBlank(expression.getSnippet())) { resultSet.add(new ValidationState(STRING_SNIPPET_VALIDATOR_ID, false, sourceName + " must not be empty!")); } return resultSet; }
@Test public void searchInDepthLimitedMatching() { StringMatchingExpression strMatchingExpression = new StringMatchingExpression(PatternMatchingType.CONTAINS, "level_2_1"); strMatchingExpression.setStringValueSource(stringValueSource); strMatchingExpression.setSearchNodeInTrace(true); strMatchingExpression.setMaxSearchDepth(1); boolean evaluationResult = strMatchingExpression.evaluate(root, cachedDataService); assertThat(evaluationResult, is(false)); }
@Test public void businessContextChanged() throws InterruptedException { StringMatchingExpression stringMatchingExpression = new StringMatchingExpression(PatternMatchingType.CONTAINS, "root"); stringMatchingExpression.setStringValueSource(stringValueSource); stringMatchingExpression.setSearchNodeInTrace(false); StringMatchingExpression stringMatchingExpression_2 = new StringMatchingExpression(PatternMatchingType.CONTAINS, "node"); stringMatchingExpression_2.setStringValueSource(stringValueSource); stringMatchingExpression_2.setSearchNodeInTrace(false); applicationDefinition.setMatchingRuleExpression(stringMatchingExpression); businessTxDefinition_1.setMatchingRuleExpression(stringMatchingExpression_2); processor.onApplicationEvent(event); assertThat(root.getApplicationId(), equalTo(application.getId())); assertThat(root.getBusinessTransactionId(), equalTo(businessTx_1.getId())); }
/** * {@inheritDoc} */ @Override protected void executeSpecificInitialization(StringMatchingExpression expression) { super.executeSpecificInitialization(expression); int index = 0; for (String opt : stringValueSource.getOptions()) { if (opt.equals(expression.getSnippet())) { break; } index++; } if (index < stringValueSource.getOptions().length) { valueComboBox.select(index); } } }
@Test public void multiValueMatching() { StringMatchingExpression strMatchingExpression = new StringMatchingExpression(PatternMatchingType.CONTAINS, "multiple"); strMatchingExpression.setStringValueSource(stringValueSource); strMatchingExpression.setSearchNodeInTrace(true); strMatchingExpression.setMaxSearchDepth(-1); boolean evaluationResult = strMatchingExpression.evaluate(root, cachedDataService); assertThat(evaluationResult, is(true)); } }
@Test public void matchDefaultBT() { StringMatchingExpression stringMatchingExpression = new StringMatchingExpression(PatternMatchingType.CONTAINS, "root"); stringMatchingExpression.setStringValueSource(stringValueSource); stringMatchingExpression.setSearchNodeInTrace(false); StringMatchingExpression stringMatchingExpression_2 = new StringMatchingExpression(PatternMatchingType.CONTAINS, "nothing"); stringMatchingExpression_2.setStringValueSource(stringValueSource); stringMatchingExpression_2.setSearchNodeInTrace(false); applicationDefinition.setMatchingRuleExpression(stringMatchingExpression); applicationDefinition_empty.setMatchingRuleExpression(stringMatchingExpression_2); businessTxDefinition_1.setMatchingRuleExpression(stringMatchingExpression_2); businessTxDefinition_2.setMatchingRuleExpression(stringMatchingExpression_2); processor.process(root, entityManager); assertThat(root.getApplicationId(), equalTo(application.getId())); assertThat(root.getBusinessTransactionId(), equalTo(businessTx_unknown.getId())); }
/** * * {@inheritDoc} */ @Override protected boolean isValidExpression(StringMatchingExpression expression) { return expression.getStringValueSource() instanceof HttpQueryStringValueSource; } }
/** * * {@inheritDoc} */ @Override protected void executeSpecificInitialization(StringMatchingExpression expression) { if (isValidExpression(expression)) { super.executeSpecificInitialization(expression); for (int i = 0; i < PatternMatchingType.values().length; i++) { if (PatternMatchingType.values()[i].equals(expression.getMatchingType())) { patternMatchingTypeComboBox.select(i); } } stringSnippetText.setText(expression.getSnippet()); } }
@Test public void simpleStringMatching() { StringMatchingExpression strMatchingExpression = new StringMatchingExpression(PatternMatchingType.CONTAINS, "root"); strMatchingExpression.setStringValueSource(stringValueSource); strMatchingExpression.setSearchNodeInTrace(false); boolean evaluationResult = strMatchingExpression.evaluate(root, cachedDataService); assertThat(evaluationResult, is(true)); }
@Test public void matchDefaultAppAndBT() { StringMatchingExpression stringMatchingExpression = new StringMatchingExpression(PatternMatchingType.CONTAINS, "nothing"); stringMatchingExpression.setStringValueSource(stringValueSource); stringMatchingExpression.setSearchNodeInTrace(false); StringMatchingExpression stringMatchingExpression_2 = new StringMatchingExpression(PatternMatchingType.CONTAINS, "nothing"); stringMatchingExpression_2.setStringValueSource(stringValueSource); stringMatchingExpression_2.setSearchNodeInTrace(false); applicationDefinition.setMatchingRuleExpression(stringMatchingExpression); applicationDefinition_empty.setMatchingRuleExpression(stringMatchingExpression_2); businessTxDefinition_1.setMatchingRuleExpression(stringMatchingExpression_2); businessTxDefinition_2.setMatchingRuleExpression(stringMatchingExpression_2); processor.process(root, entityManager); assertThat(root.getApplicationId(), equalTo(application_unknown.getId())); assertThat(root.getBusinessTransactionId(), equalTo(businessTx_unknown.getId())); }
/** * {@inheritDoc} */ @Override protected boolean isValidExpression(StringMatchingExpression expression) { return expression.getStringValueSource() instanceof MethodParameterValueSource; }