Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation if status codes comparators parameters were provided #296

Merged
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b04bcf4
added lower bound for filterrange
plutasnyy Jul 31, 2018
a02d7b0
changed unit tests to be correct with logic or in status code filter
plutasnyy Jul 31, 2018
b168089
changed logical expresion in status codes filter
plutasnyy Jul 31, 2018
08a7011
added in documentation information about status code comparator
plutasnyy Jul 31, 2018
e34670c
changed status-codes suites to work properly with changed logical exp…
plutasnyy Jul 31, 2018
3215cd2
Merge branch 'master' into validation_if_statusCodesComparators_param…
plutasnyy Aug 1, 2018
21a4cae
updated changelog and documentation
plutasnyy Aug 1, 2018
66a0f83
Merge remote-tracking branch 'origin/master' into validation_if_statu…
plutasnyy Aug 3, 2018
382696c
updated tests
plutasnyy Aug 3, 2018
ae809bc
unit test formatting
wiiitek Aug 5, 2018
640ed48
updated documentation
plutasnyy Aug 6, 2018
fa61147
removed unused mock
plutasnyy Aug 6, 2018
ecee6ff
updated tests
plutasnyy Aug 6, 2018
2048de5
Merge branch 'master' into validation_if_statusCodesComparators_param…
plutasnyy Aug 6, 2018
618d9fe
changed urls
plutasnyy Aug 6, 2018
e45fa42
fixed typo in documentation
plutasnyy Aug 6, 2018
55a4c30
updated documentation
plutasnyy Aug 6, 2018
79a1fbb
more refactoring for unit test
wiiitek Aug 7, 2018
4cbc564
changelog updated
wiiitek Aug 7, 2018
fc7b234
documentation updates
wiiitek Aug 7, 2018
d3c23f9
Merge pull request #305 from Cognifide/unit-test-refactor
plutasnyy Aug 7, 2018
eb43b1f
Merge branch 'master' into validation_if_statusCodesComparators_param…
tkaik Aug 9, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ All notable changes to AET will be documented in this file.
## Unreleased
**List of changes that are finished but not yet released in any final version.**

- [PR-296](https://github.com/Cognifide/aet/pull/296) The behavior of StatusCodesComparator was changed
Copy link
Contributor

@malaskowski malaskowski Aug 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add more information here?
E.g.

Status Code Comparator check now range 400-600 by default, parameters validation added

- [PR-289](https://github.com/Cognifide/aet/pull/289) User now stays on the same tab while navigating between URLs
- [PR-271](https://github.com/Cognifide/aet/pull/271) Added possibility to override name parameter from the aet client
- [PR-268](https://github.com/Cognifide/aet/pull/268) Bobcat upgrade to version 1.4.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public class StatusCodesComparator implements ComparatorJob {

private static final Logger LOGGER = LoggerFactory.getLogger(StatusCodesComparator.class);

private static final int DEFAULT_FILTER_RANGE_LOWER_BOUND = 400;

private static final int DEFAULT_FILTER_RANGE_UPPER_BOUND = 600;

public static final String COMPARATOR_TYPE = "status-codes";
Expand All @@ -53,14 +55,15 @@ public class StatusCodesComparator implements ComparatorJob {
private static final String PARAM_DELIMITER = ",";

private static final String PARAM_SHOW_EXCLUDED = "showExcluded";

private static final Type RESULT_TYPE = new TypeToken<StatusCodesCollectorResult>() {
}.getType();

private final ArtifactsDAO artifactsDAO;

private final ComparatorProperties properties;

private int filterRangeLowerBound;
private int filterRangeLowerBound = DEFAULT_FILTER_RANGE_LOWER_BOUND;

private int filterRangeUpperBound = DEFAULT_FILTER_RANGE_UPPER_BOUND;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,22 @@ private class StatusCodeFilterPredicate implements Predicate<StatusCode> {

@Override
public boolean apply(StatusCode statusCode) {
if (statusCode.getCode() < lowerBound) {
return false;
}
if (statusCode.getCode() > upperBound) {
return false;
}
if (!filterCodes.isEmpty() && !filterCodes.contains(statusCode.getCode())) {
return false;
}

if (statusCode.getCode() < 0) {
return false;
}
return true;
if (isCodeInRange(statusCode) || isCodeInFilterCodes(statusCode)) {
return true;
}
return false;
}

private boolean isCodeInFilterCodes(StatusCode statusCode) {
return !filterCodes.isEmpty() && filterCodes.contains(statusCode.getCode());
}

private boolean isCodeInRange(StatusCode statusCode) {
return statusCode.getCode() >= lowerBound && statusCode.getCode() <= upperBound;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void setUp() {
@Test
Copy link
Contributor

@wiiitek wiiitek Aug 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some issues with this test. Could we resolve them in this pull request?
It looks like dataResult mock is never used (or am I wrong?).
Also: it looks strange when whe change from failed to passed. Why is that?

Currently we are not testing much here. It might be a good time to improve this test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some tests. The change from failed to passed is the result of changed logic expression when we have both filterCodes and filterRange - before, we had AND between range and codes, now we have OR ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! That is great! I had some more ideas (pull request #305). Maybe you would like to get some of them into your feature branch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely! Thank you so much for your help :D

public void compareTest() throws ProcessingException {
result = tested.compare();
assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus());
assertEquals(ComparatorStepResult.Status.PASSED, result.getStatus());
}

@Test
Expand All @@ -105,7 +105,7 @@ public void compareTest_filterRange() throws ProcessingException {
when(params.containsKey(PARAM_FILTER_RANGE)).thenReturn(true);
when(params.get(PARAM_FILTER_RANGE)).thenReturn(FILTER_RANGE);
result = tested.compare();
assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus());
assertEquals(ComparatorStepResult.Status.PASSED, result.getStatus());
}

@Test
Expand All @@ -115,7 +115,7 @@ public void compareTest_filterCodes() throws ProcessingException {
when(params.get(PARAM_FILTER_CODES)).thenReturn(FILTER_CODES_MULTIPLE);

result = tested.compare();
assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus());
assertEquals(ComparatorStepResult.Status.PASSED, result.getStatus());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void testFilter_bounds(int lowerBound, int upperBound, int expectedSize)
assertThat(result.size(), is(expectedSize));
}

@TestWith({"100;200;201,3", "400;401;499,3", "404,3"})
@TestWith({"100;200;201,18", "400;401;499,18", "404,18"})
public void testFilter_filterCodes(String filterCodesParam, int expectedSize) {
tested = getTested(0, 600, prepareFilterCodes(filterCodesParam));

Expand All @@ -102,7 +102,7 @@ public void testFilter_filterCodes(String filterCodesParam, int expectedSize) {
assertThat(result.size(), is(expectedSize));
}

@TestWith({"100;200;201,100,200,2", "400;401;499,100,400,1"})
@TestWith({"100;200;201,100,200,5", "400;401;499,100,400,12"})
public void testFilter_boundsWithfilterCodes(String filterCodesParam, int lowerBound,
int upperBound,
int expectedSize) {
Expand Down
8 changes: 6 additions & 2 deletions documentation/src/main/wiki/StatusCodesComparator.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ Resource name: status-codes

| Parameter | Value | Example | Description | Mandatory |
| --------- | ----- | ------- | ----------- | --------- |
| `filterRange` | x,y | 400,500 | Defines range of status codes that should be processed | yes, if `filterCodes` is not present |
| `filterCodes` | x,y,z | 400,401,404 | List of status codes that should be processed | yes, if `filterRange` is not present |
| `filterRange` | x,y (default: `400,600`) | 400,500 | Defines range of status codes that should be processed | no |
| `filterCodes` | x,y,z | 400,401,404 | List of status codes that should be processed | no |
| `showExcluded` | boolean (default: `true`) | true | Flag that says if excluded codes (see [[Status Codes Data Filters | StatusCodesDataFilters]]) should be displayed in report. By default set to `true`. | no |

If you provide both `filterRange` and `filterCodes`, it will be used as logical sum. It means that:
- `<status-codes filterRange="400,500" filterCodes="501,502" />` is equivalent to `<status-codes filterRange="400,502" />`
- `<status-codes filterRange="300,400" filterCodes="404" />` won't check `401-403` codes.

##### Example Usage

```xml
Expand Down
2 changes: 2 additions & 0 deletions documentation/src/main/wiki/StatusCodesDataFilters.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#### Status Codes Data Filters

Data filters will be apply only for codes contained in the `filterange`. If the `filterRange` isn't provided, default range will be used.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix the filterange typo.
What about codes contained in the filterCodes parameter - will data filters be applied for them?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated


##### Exclude Filter

Exclude Filter removes from reports Status Codes results that match specified parameters.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
@Modules(GuiceModule.class)
public class HomePageTilesTest {

private static final int TESTS = 113;
private static final int TESTS = 114;

private static final int EXPECTED_TESTS_SUCCESS = 66;

private static final int EXPECTED_TESTS_WARN = 5;

private static final int EXPECTED_TESTS_FAIL = 42;
private static final int EXPECTED_TESTS_FAIL = 43;

@Inject
private ReportHomePage page;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ Feature: Tests Results Filtering
Scenario: Filtering Tests Results: status-codes
Given I have opened sample tests report page
When I search for tests containing "status"
Then There are 20 tiles visible
And Statistics text contains "20 ( 8 / 0 / 12 / 0 )"
Then There are 21 tiles visible
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your welcome ;)

And Statistics text contains "21 ( 9 / 0 / 12 / 0 )"

Scenario: Filtering Tests Results: w3c-html5
Given I have opened sample tests report page
Expand Down
19 changes: 16 additions & 3 deletions integration-tests/test-suite/partials/status-codes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,24 @@
</compare>
<urls>
<url href="comparators/statuscodes/failed.jsp"/>
<url href="comparators/statuscodes/success.jsp"/>
<url href="comparators/statuscodes/noneexistingPage.jsp"/>
</urls>
</test>

<test name="F-comparator-StatusCodes-200-success" useProxy="rest">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have new test added here.
Please update also our integration tests (functional).

<collect>
<open/>
<status-codes/>
<sleep duration="3000"/>
</collect>
<compare>
<status-codes filterCodes="200" showExcluded="true"/>
</compare>
<urls>
<url href="comparators/statuscodes/success.jsp"/>
</urls>
</test>

<test name="S-comparator-StatusCodes-filter-300-505" useProxy="rest">
<collect>
<open/>
Expand Down Expand Up @@ -255,7 +268,7 @@
<sleep duration="3000"/>
</collect>
<compare>
<status-codes showExcluded="true">
<status-codes filterCodes="200,404" showExcluded="true">
<exclude url="/sample-site/NonExistingResourceFile.png"/>
</status-codes>
</compare>
Expand Down Expand Up @@ -304,7 +317,7 @@
<sleep duration="3000"/>
</collect>
<compare>
<status-codes showExcluded="true">
<status-codes filterCodes="200" showExcluded="true">
<include pattern="^.*css$"/>
</status-codes>
</compare>
Expand Down