/** * Validates the contents of the passed {@link StringMatchingExpression} without the need to * create corresponding editing controls. * * @param expression * {@link StringMatchingExpression} to validate * @return a set of {@link ValidationState} instances. */ public static Set<ValidationState> validate(StringMatchingExpression expression) { Set<ValidationState> resultSet = new HashSet<>(); HttpParameterValueSource httpParameterValueSource = (HttpParameterValueSource) expression.getStringValueSource(); if (StringUtils.isBlank(httpParameterValueSource.getParameterName())) { resultSet.add(new ValidationState(PARAMETER_NAME_VALIDATOR_ID, false, PARAMETER_NAME_VALIDATION_ERROR_MESSAGE)); } resultSet.addAll(AbstractStringMatchingRuleEditingElement.validate(expression, SOURCE_NAME)); return resultSet; }
@Test public void noRequiredHttpParameter() { Mockito.doReturn(httpTimerData).when(invocationSeuence).getTimerData(); Map<String, String[]> parameterMap = new HashMap<>(); parameterMap.put(PARAMETER_NAME_1, new String[] { VALUE_A, VALUE_B }); Mockito.doReturn(parameterMap).when(httpTimerData).getParameters(); valueSource.setParameterName(PARAMETER_NAME_2); String[] values = valueSource.getStringValues(invocationSeuence, cachedDataService); assertThat(values, is(notNullValue())); assertThat(values.length, is(equalTo(0))); } }
switch (sourceType) { case HTTP_PARAMETER: return new HttpParameterValueSource(parameterNameText.getText()); case HTTP_URL: return new HttpUrlValueSource();
expression.setStringValueSource(new HttpParameterValueSource("")); break; case HTTP_URL:
@Test public void noHttpData() { Mockito.doReturn(new TimerData()).when(invocationSeuence).getTimerData(); valueSource.setParameterName(PARAMETER_NAME_2); String[] values = valueSource.getStringValues(invocationSeuence, cachedDataService); assertThat(values, is(notNullValue())); assertThat(values.length, is(equalTo(0))); }
/** * * {@inheritDoc} */ @Override protected void executeSpecificInitialization(StringMatchingExpression expression) { if (isValidExpression(expression)) { super.executeSpecificInitialization(expression); parameterNameText.setText(getStringValueSource().getParameterName()); } }
@Test public void noHttpParameter() { Mockito.doReturn(httpTimerData).when(invocationSeuence).getTimerData(); Mockito.doReturn(new HashMap<>()).when(httpTimerData).getParameters(); valueSource.setParameterName(PARAMETER_NAME_2); String[] values = valueSource.getStringValues(invocationSeuence, cachedDataService); assertThat(values, is(notNullValue())); assertThat(values.length, is(equalTo(0))); }
/** * {@inheritDoc} */ @Override public String[] getStringValues(InvocationSequenceData invocSequence, ICachedDataService cachedDataService) { if (InvocationSequenceDataHelper.hasHttpTimerData(invocSequence)) { HttpTimerData httpData = (HttpTimerData) invocSequence.getTimerData(); if (null != httpData.getParameters()) { String[] result = httpData.getParameters().get(this.getParameterName()); return null == result ? new String[0] : result; } } return new String[0]; }
@Test public void retrieveSecondParameter() { Mockito.doReturn(httpTimerData).when(invocationSeuence).getTimerData(); Map<String, String[]> parameterMap = new HashMap<>(); parameterMap.put(PARAMETER_NAME_1, new String[] { VALUE_A, VALUE_B }); parameterMap.put(PARAMETER_NAME_2, new String[] { VALUE_C, VALUE_D }); Mockito.doReturn(parameterMap).when(httpTimerData).getParameters(); valueSource.setParameterName(PARAMETER_NAME_2); String[] values = valueSource.getStringValues(invocationSeuence, cachedDataService); assertThat(values, hasItemInArray(VALUE_C)); assertThat(values, hasItemInArray(VALUE_D)); assertThat(values, not(hasItemInArray(VALUE_A))); assertThat(values, not(hasItemInArray(VALUE_B))); }
case HTTP_PARAMETER: createHttpParameterControls(); String parameterName = ((HttpParameterValueSource) nameExtractionExpression.getStringValueSource()).getParameterName(); if (null == parameterName) { parameterName = "";
@Test public void retrieveFirstParameter() { Mockito.doReturn(httpTimerData).when(invocationSeuence).getTimerData(); Map<String, String[]> parameterMap = new HashMap<>(); parameterMap.put(PARAMETER_NAME_1, new String[] { VALUE_A, VALUE_B }); parameterMap.put(PARAMETER_NAME_2, new String[] { VALUE_C, VALUE_D }); Mockito.doReturn(parameterMap).when(httpTimerData).getParameters(); valueSource.setParameterName(PARAMETER_NAME_1); String[] values = valueSource.getStringValues(invocationSeuence, cachedDataService); assertThat(values, hasItemInArray(VALUE_A)); assertThat(values, hasItemInArray(VALUE_B)); assertThat(values, not(hasItemInArray(VALUE_C))); assertThat(values, not(hasItemInArray(VALUE_D))); }