diff --git a/CHANGELOG.md b/CHANGELOG.md index fecd1d0fa..506b6076f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ All notable changes to AET will be documented in this file. - [PR-286](https://github.com/Cognifide/aet/pull/286) Shared Patterns - use latest patterns of given suite name ([#121](https://github.com/Cognifide/aet/issues/121)) - [PR-291](https://github.com/Cognifide/aet/pull/291) Updated nu.validator version from 15.6.29 to 17.11.1 - [PR-298](https://github.com/Cognifide/aet/pull/298) Filtering accessibility errors by markup CSS ([#214](https://github.com/Cognifide/aet/issues/214)) +- [PR-296](https://github.com/Cognifide/aet/pull/296) Status Code Comparator now checks range 400-600 by default, parameters validation added ## Version 2.1.6 diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesComparator.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesComparator.java index 8c89ee55f..f3cab996c 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesComparator.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesComparator.java @@ -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"; @@ -53,6 +55,7 @@ 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() { }.getType(); @@ -60,7 +63,7 @@ public class StatusCodesComparator implements ComparatorJob { private final ComparatorProperties properties; - private int filterRangeLowerBound; + private int filterRangeLowerBound = DEFAULT_FILTER_RANGE_LOWER_BOUND; private int filterRangeUpperBound = DEFAULT_FILTER_RANGE_UPPER_BOUND; diff --git a/core/jobs/src/main/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesFilter.java b/core/jobs/src/main/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesFilter.java index 13f40e1d1..2fd255e2f 100644 --- a/core/jobs/src/main/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesFilter.java +++ b/core/jobs/src/main/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesFilter.java @@ -42,19 +42,22 @@ private class StatusCodeFilterPredicate implements Predicate { @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; } } } diff --git a/core/jobs/src/test/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesComparatorTest.java b/core/jobs/src/test/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesComparatorTest.java index 110f12e69..8ce1c7236 100644 --- a/core/jobs/src/test/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesComparatorTest.java +++ b/core/jobs/src/test/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesComparatorTest.java @@ -16,22 +16,20 @@ package com.cognifide.aet.job.common.comparators.statuscodes; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import static org.mockito.Mockito.when; import com.cognifide.aet.communication.api.metadata.ComparatorStepResult; +import com.cognifide.aet.communication.api.metadata.ComparatorStepResult.Status; import com.cognifide.aet.job.api.comparator.ComparatorProperties; -import com.cognifide.aet.job.api.datafilter.DataFilterJob; import com.cognifide.aet.job.api.exceptions.ParametersException; import com.cognifide.aet.job.api.exceptions.ProcessingException; import com.cognifide.aet.job.common.ArtifactDAOMock; -import com.cognifide.aet.job.common.collectors.statuscodes.StatusCode; -import com.cognifide.aet.job.common.collectors.statuscodes.StatusCodesCollectorResult; import com.cognifide.aet.job.common.comparators.AbstractComparatorTest; -import com.cognifide.aet.job.common.comparators.source.SourceComparator; -import com.google.common.collect.Lists; import java.util.ArrayList; -import java.util.List; import java.util.Map; + +import com.google.common.collect.ImmutableMap; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -65,54 +63,165 @@ public class StatusCodesComparatorTest extends AbstractComparatorTest { private static final String FILTER_CODES_MULTIPLE_NAN = "NaN,NaN,NaN,NaN"; - private StatusCodesComparator tested; + private static final String FILTER_CODES_ONLY_SUCCESS = "200"; - @Mock - private Map params; + private static final String FILTER_RANGE_REMOVE_DEFAULT_RANGE = "1,1"; - @Mock - private StatusCodesCollectorResult dataResult; + private static final String FILTER_CODES_EXCLUDED = "500"; + + private StatusCodesComparator tested; @Mock private ComparatorProperties comparatorProperties; - private List statusCodes; - @Before public void setUp() { artifactDaoMock = new ArtifactDAOMock(StatusCodesComparator.class); - comparatorProperties = new ComparatorProperties(TEST_COMPANY, TEST_PROJECT, null, - "expected-data-200-result.json"); - tested = new StatusCodesComparator(artifactDaoMock, comparatorProperties, - new ArrayList()); - artifactDaoMock = new ArtifactDAOMock(SourceComparator.class); - initStatusCodes(); - when(dataResult.getStatusCodes()).thenReturn(statusCodes); + } - when(params.containsKey(PARAM_FILTER_RANGE)).thenReturn(false); - when(params.containsKey(PARAM_FILTER_CODES)).thenReturn(false); + @Test + public void compareTest_expectPassed() throws ProcessingException { + tested = createNewStatusCodesComparator("expected-data-200-result.json"); + + result = tested.compare(); + assertEquals(ComparatorStepResult.Status.PASSED, result.getStatus()); } @Test - public void compareTest() throws ProcessingException { + public void compareTest_expectFailed() throws ProcessingException, ParametersException { + tested = createNewStatusCodesComparator("expected-data-200-result.json"); + + Map params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_ONLY_SUCCESS); + tested.setParameters(params); + result = tested.compare(); assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus()); } @Test - public void compareTest_filterRange() throws ProcessingException { - // filter only by range - when(params.containsKey(PARAM_FILTER_RANGE)).thenReturn(true); - when(params.get(PARAM_FILTER_RANGE)).thenReturn(FILTER_RANGE); + public void compareTest_filterRange_expectPassed() + throws ProcessingException, ParametersException { + tested = createNewStatusCodesComparator("not-existing-page-404-result.json"); + + Map params = ImmutableMap + .of(PARAM_FILTER_RANGE, FILTER_RANGE_REMOVE_DEFAULT_RANGE); + tested.setParameters(params); + + result = tested.compare(); + assertEquals(ComparatorStepResult.Status.PASSED, result.getStatus()); + } + + @Test + public void compareTest_filterRange_expectFailed() + throws ProcessingException, ParametersException { + tested = createNewStatusCodesComparator("not-existing-page-404-result.json"); + + Map params = ImmutableMap + .of(PARAM_FILTER_RANGE, FILTER_RANGE); + tested.setParameters(params); + result = tested.compare(); assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus()); } @Test - public void compareTest_filterCodes() throws ProcessingException { - // filter only by codes - when(params.containsKey(PARAM_FILTER_CODES)).thenReturn(true); - when(params.get(PARAM_FILTER_CODES)).thenReturn(FILTER_CODES_MULTIPLE); + public void compareTest_filterCodes_expectPassed() + throws ProcessingException, ParametersException { + tested = createNewStatusCodesComparator("not-existing-page-404-result.json"); + + Map params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_ONLY_SUCCESS, + PARAM_FILTER_RANGE, FILTER_RANGE_REMOVE_DEFAULT_RANGE); + tested.setParameters(params); + + result = tested.compare(); + assertEquals(ComparatorStepResult.Status.PASSED, result.getStatus()); + } + + @Test + public void compareTest_filterCodesMultipleCodes_expectFailed() + throws ProcessingException, ParametersException { + tested = createNewStatusCodesComparator("not-existing-page-404-result.json"); + + Map params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_MULTIPLE, + PARAM_FILTER_RANGE, FILTER_RANGE_REMOVE_DEFAULT_RANGE); + tested.setParameters(params); + + result = tested.compare(); + assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus()); + } + + @Test + public void compareTest_filterCodesAndFilterRange_expectFailed() + throws ParametersException, ProcessingException { + tested = createNewStatusCodesComparator("a-lot-of-errors-with-exclude-result.json"); + Map params; + + params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_RANGE); + tested.setParameters(params); + + result = tested.compare(); + assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus()); + + params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_MULTIPLE, + PARAM_FILTER_RANGE, FILTER_RANGE_REMOVE_DEFAULT_RANGE); + tested.setParameters(params); + + result = tested.compare(); + assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus()); + + params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_MULTIPLE, + PARAM_FILTER_RANGE, FILTER_RANGE); + tested.setParameters(params); + + result = tested.compare(); + assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus()); + } + + @Test + public void compareTest_filterCodesAndFilterRange_expectPassed() + throws ParametersException, ProcessingException { + tested = createNewStatusCodesComparator("a-lot-of-errors-with-exclude-result.json"); + + Map params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_SINGLE, + PARAM_FILTER_RANGE, FILTER_RANGE_REMOVE_DEFAULT_RANGE); + tested.setParameters(params); + + result = tested.compare(); + assertEquals(Status.PASSED, result.getStatus()); + } + + @Test + public void compareTest_testExclude_expectPassed() + throws ParametersException, ProcessingException { + tested = createNewStatusCodesComparator("a-lot-of-errors-with-exclude-result.json"); + + Map params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_EXCLUDED, + PARAM_FILTER_RANGE, FILTER_RANGE_REMOVE_DEFAULT_RANGE); + tested.setParameters(params); + + result = tested.compare(); + assertEquals(ComparatorStepResult.Status.PASSED, result.getStatus()); + } + + @Test + public void compareTest_defaultRange_expectPassed() throws ProcessingException { + tested = createNewStatusCodesComparator("default-range-399-601-errors-result.json"); + + result = tested.compare(); + assertEquals(ComparatorStepResult.Status.PASSED, result.getStatus()); + } + + @Test + public void compareTest_defaultRange_expectFailed() throws ProcessingException { + tested = createNewStatusCodesComparator("default-range-400-600-errors-result.json"); result = tested.compare(); assertEquals(ComparatorStepResult.Status.FAILED, result.getStatus()); @@ -120,130 +229,99 @@ public void compareTest_filterCodes() throws ProcessingException { @Test public void setParameters() throws ParametersException { - when(params.containsKey(PARAM_FILTER_RANGE)).thenReturn(true); - when(params.get(PARAM_FILTER_RANGE)).thenReturn(FILTER_RANGE); - when(params.containsKey(PARAM_FILTER_CODES)).thenReturn(true); - when(params.get(PARAM_FILTER_CODES)).thenReturn(FILTER_CODES_SINGLE); + tested = createNewStatusCodesComparator("expected-data-200-result.json"); - // no parameters errors expected - unable to assert anything + Map params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_SINGLE, + PARAM_FILTER_RANGE, FILTER_RANGE); tested.setParameters(params); + // parameters were set successfully } @Test public void setParameters_filterRange() throws ParametersException { - when(params.containsKey(PARAM_FILTER_RANGE)).thenReturn(true); - when(params.get(PARAM_FILTER_RANGE)).thenReturn(FILTER_RANGE); + tested = createNewStatusCodesComparator("expected-data-200-result.json"); - // no parameters errors expected - unable to assert anything + Map params = ImmutableMap + .of(PARAM_FILTER_RANGE, FILTER_RANGE); tested.setParameters(params); + // parameters were set successfully } @Test(expected = ParametersException.class) public void setParameters_filterRangeInvalid() throws ParametersException { - when(params.containsKey(PARAM_FILTER_RANGE)).thenReturn(true); - when(params.get(PARAM_FILTER_RANGE)).thenReturn(FILTER_RANGE_INVALID); + tested = createNewStatusCodesComparator("expected-data-200-result.json"); - // parameters exception expected - unable to assert anything + Map params = ImmutableMap + .of(PARAM_FILTER_RANGE, FILTER_RANGE_INVALID); tested.setParameters(params); + fail("parameters exception expected"); } @Test(expected = ParametersException.class) public void setParameters_filterRangeNotANumber() throws ParametersException { - when(params.containsKey(PARAM_FILTER_RANGE)).thenReturn(true); - when(params.get(PARAM_FILTER_RANGE)).thenReturn(FILTER_RANGE_NAN); + tested = createNewStatusCodesComparator("expected-data-200-result.json"); - // parameters exception expected - unable to assert anything + Map params = ImmutableMap + .of(PARAM_FILTER_RANGE, FILTER_RANGE_NAN); tested.setParameters(params); + fail("parameters exception expected"); } @Test(expected = ParametersException.class) public void setParameters_filterRangeUpperBoundLessThanLowerBound() throws ParametersException { - when(params.containsKey(PARAM_FILTER_RANGE)).thenReturn(true); - when(params.get(PARAM_FILTER_RANGE)).thenReturn(FILTER_RANGE_UPPER_LESS_THAN_LOWER); + tested = createNewStatusCodesComparator("expected-data-200-result.json"); - // parameters exception expected - unable to assert anything + Map params = ImmutableMap + .of(PARAM_FILTER_RANGE, FILTER_RANGE_UPPER_LESS_THAN_LOWER); tested.setParameters(params); + fail("parameters exception expected"); } @Test public void setParameters_filterCodes() throws ParametersException { - when(params.containsKey(PARAM_FILTER_CODES)).thenReturn(true); - when(params.get(PARAM_FILTER_CODES)).thenReturn(FILTER_CODES_SINGLE); + tested = createNewStatusCodesComparator("expected-data-200-result.json"); - // parameters exception expected - unable to assert anything + Map params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_SINGLE); tested.setParameters(params); + // parameters were set successfully } @Test public void setParameters_filterCodesMultipleValues() throws ParametersException { - when(params.containsKey(PARAM_FILTER_CODES)).thenReturn(true); - when(params.get(PARAM_FILTER_CODES)).thenReturn(FILTER_CODES_MULTIPLE); + tested = createNewStatusCodesComparator("expected-data-200-result.json"); - // no parameters errors expected - unable to assert anything + Map params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_MULTIPLE); tested.setParameters(params); + // parameters were set successfully } @Test(expected = ParametersException.class) public void setParameters_filterCodesNotANumber() throws ParametersException { - when(params.containsKey(PARAM_FILTER_CODES)).thenReturn(true); - when(params.get(PARAM_FILTER_CODES)).thenReturn(FILTER_CODES_SINGLE_NAN); + tested = createNewStatusCodesComparator("expected-data-200-result.json"); - // parameters exception expected - unable to assert anything + Map params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_SINGLE_NAN); tested.setParameters(params); + fail("parameters exception expected"); } @Test(expected = ParametersException.class) public void setParameters_filterCodesMultipleValuesNotANumber() throws ParametersException { - when(params.containsKey(PARAM_FILTER_CODES)).thenReturn(true); - when(params.get(PARAM_FILTER_CODES)).thenReturn(FILTER_CODES_MULTIPLE_NAN); + tested = createNewStatusCodesComparator("expected-data-200-result.json"); - // parameters exception expected - unable to assert anything + Map params = ImmutableMap + .of(PARAM_FILTER_CODES, FILTER_CODES_MULTIPLE_NAN); tested.setParameters(params); + fail("parameters exception expected"); } - private void initStatusCodes() { - statusCodes = new StatusCodesBuilder().add(404, 303, 500, 501, 302, 200, 400, 201) - .add(404, "http://www.example.com/image.png").build(); + private StatusCodesComparator createNewStatusCodesComparator(String pathToJson) { + comparatorProperties = new ComparatorProperties(TEST_COMPANY, TEST_PROJECT, null, + pathToJson); + return new StatusCodesComparator(artifactDaoMock, comparatorProperties, new ArrayList<>()); } - private static class StatusCodesBuilder { - - private static final String DEFAULT_URL = "http://www.example.com"; - - private final List codes; - - private StatusCodesBuilder() { - this.codes = Lists.newArrayList(); - } - - public StatusCodesBuilder add(int code) { - codes.add(new StatusCode(code, DEFAULT_URL)); - return this; - } - - ; - - public StatusCodesBuilder add(Integer... httpCodes) { - for (Integer httpCode : httpCodes) { - codes.add(new StatusCode(httpCode, DEFAULT_URL)); - } - return this; - } - - ; - - public StatusCodesBuilder add(int code, String url) { - codes.add(new StatusCode(code, url)); - return this; - } - - ; - - public List build() { - return codes; - } - - ; - - } } diff --git a/core/jobs/src/test/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesFilterTest.java b/core/jobs/src/test/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesFilterTest.java index cafc9df97..21f01eb56 100644 --- a/core/jobs/src/test/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesFilterTest.java +++ b/core/jobs/src/test/java/com/cognifide/aet/job/common/comparators/statuscodes/StatusCodesFilterTest.java @@ -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)); @@ -102,8 +102,8 @@ 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"}) - public void testFilter_boundsWithfilterCodes(String filterCodesParam, int lowerBound, + @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) { tested = getTested(lowerBound, upperBound, prepareFilterCodes(filterCodesParam)); diff --git a/core/jobs/src/test/resources/mock/StatusCodesComparator/a-lot-of-errors-with-exclude-result.json b/core/jobs/src/test/resources/mock/StatusCodesComparator/a-lot-of-errors-with-exclude-result.json new file mode 100644 index 000000000..0d97a1fc9 --- /dev/null +++ b/core/jobs/src/test/resources/mock/StatusCodesComparator/a-lot-of-errors-with-exclude-result.json @@ -0,0 +1,58 @@ +{ + "statusCodes": [ + { + "code": 404, + "url": "http://aet-vagrant/sample-site/sanity/comparators/statuscodes/noneexistingPage404.jsp", + "excluded": false + }, + { + "code": 0, + "url": "http://aet-vagrant/favicon.ico", + "excluded": false + }, + { + "code": 303, + "url": "https://www.google.com/", + "excluded": false + }, + { + "code": 500, + "url": "https://www.wikipedia.org/", + "excluded": true + }, + { + "code": 200, + "url": "", + "excluded": false + } + ], + "filteredStatusCodes": [ + { + "code": 404, + "url": "http://aet-vagrant/sample-site/sanity/comparators/statuscodes/noneexistingPage404.jsp", + "excluded": false + }, + { + "code": 0, + "url": "http://aet-vagrant/favicon.ico", + "excluded": false + }, + { + "code": 303, + "url": "https://www.google.com/", + "excluded": false + }, + { + "code": 200, + "url": "www.wikipedia.org", + "excluded": false + } + ], + "excludedStatusCodes": [ + { + "code": 500, + "url": "https://www.wikipedia.org/", + "excluded": true + } + ] +} \ No newline at end of file diff --git a/core/jobs/src/test/resources/mock/StatusCodesComparator/default-range-399-601-errors-result.json b/core/jobs/src/test/resources/mock/StatusCodesComparator/default-range-399-601-errors-result.json new file mode 100644 index 000000000..2db6c4503 --- /dev/null +++ b/core/jobs/src/test/resources/mock/StatusCodesComparator/default-range-399-601-errors-result.json @@ -0,0 +1,27 @@ +{ + "statusCodes": [ + { + "code": 399, + "url": "http://aet-vagrant/sample-site/sanity/comparators/statuscodes/noneexistingPage404.jsp", + "excluded": false + }, + { + "code": 601, + "url": "https://www.google.com/", + "excluded": false + } + ], + "filteredStatusCodes": [ + { + "code": 399, + "url": "http://aet-vagrant/sample-site/sanity/comparators/statuscodes/noneexistingPage404.jsp", + "excluded": false + }, + { + "code": 601, + "url": "https://www.google.com/", + "excluded": false + } + ], + "excludedStatusCodes": [] +} \ No newline at end of file diff --git a/core/jobs/src/test/resources/mock/StatusCodesComparator/default-range-400-600-errors-result.json b/core/jobs/src/test/resources/mock/StatusCodesComparator/default-range-400-600-errors-result.json new file mode 100644 index 000000000..a83f721c5 --- /dev/null +++ b/core/jobs/src/test/resources/mock/StatusCodesComparator/default-range-400-600-errors-result.json @@ -0,0 +1,27 @@ +{ + "statusCodes": [ + { + "code": 400, + "url": "http://aet-vagrant/sample-site/sanity/comparators/statuscodes/noneexistingPage404.jsp", + "excluded": false + }, + { + "code": 600, + "url": "https://www.google.com/", + "excluded": false + } + ], + "filteredStatusCodes": [ + { + "code": 400, + "url": "http://aet-vagrant/sample-site/sanity/comparators/statuscodes/noneexistingPage404.jsp", + "excluded": false + }, + { + "code": 600, + "url": "https://www.google.com/", + "excluded": false + } + ], + "excludedStatusCodes": [] +} \ No newline at end of file diff --git a/core/jobs/src/test/resources/mock/StatusCodesComparator/not-existing-page-404-result.json b/core/jobs/src/test/resources/mock/StatusCodesComparator/not-existing-page-404-result.json new file mode 100644 index 000000000..da0f287ec --- /dev/null +++ b/core/jobs/src/test/resources/mock/StatusCodesComparator/not-existing-page-404-result.json @@ -0,0 +1,22 @@ +{ + "statusCodes": [ + { + "code": 404, + "url": "http://aet-vagrant/sample-site/sanity/comparators/statuscodes/noneexistingPage404.jsp", + "excluded": false + }, + { + "code": 0, + "url": "http://aet-vagrant/favicon.ico", + "excluded": false + } + ], + "filteredStatusCodes": [ + { + "code": 404, + "url": "http://aet-vagrant/sample-site/sanity/comparators/statuscodes/noneexistingPage404.jsp", + "excluded": false + } + ], + "excludedStatusCodes": [] +} \ No newline at end of file diff --git a/documentation/src/main/wiki/StatusCodesComparator.md b/documentation/src/main/wiki/StatusCodesComparator.md index 46f3d788b..cdf129dca 100644 --- a/documentation/src/main/wiki/StatusCodesComparator.md +++ b/documentation/src/main/wiki/StatusCodesComparator.md @@ -12,9 +12,13 @@ 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 | -| `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 | +| `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 | Used to show excluded status codes on report (see *Status Codes Data Filters*). | no | + +If you provide both `filterRange` and `filterCodes`, it will be used as logical sum. It means that: + - `` is equivalent to `` + - `` won't check `401-403` codes. ##### Example Usage diff --git a/documentation/src/main/wiki/StatusCodesDataFilters.md b/documentation/src/main/wiki/StatusCodesDataFilters.md index 7da38ef58..252527e20 100644 --- a/documentation/src/main/wiki/StatusCodesDataFilters.md +++ b/documentation/src/main/wiki/StatusCodesDataFilters.md @@ -1,5 +1,9 @@ #### Status Codes Data Filters +There might be a need to ignore some of the collected status codes. We can exclude them so that they no longer affect our test case. + +Data filters will be applied only for codes contained in logic sum of the `filterRange` and the `filterCodes`. If the `filterRange` isn't provided, default range will be used. + ##### Exclude Filter Exclude Filter removes from reports Status Codes results that match specified parameters. @@ -12,14 +16,14 @@ Resource name: status-codes | Parameter | Value | Description | Mandatory | | --------- | ----- | ----------- | --------- | -| `url` | String url | Exact url to be removed from results. | At least one of parameter is required. | -| `pattern` | String regex pattern| Regex pattern that urls should match to be removed from results. | | +| `url` | String url | Exact url to be excluded from results. | At least one of parameter is required. | +| `pattern` | String regex pattern| Regex pattern that urls should match to be excluded from results. | | If both parameters are provided then result is removed when it matches at least one of the parameters. ###### Example Usage -In this sample match results with url http://www.cognifide.com/_cog_opt_js_f359581ea4bd3379b4c25591838a5dd8.js or url that matches pattern **^.\*js$** will be ignored (not included in report). +In this sample result with url http://www.external.com/_optional.js or urls that match pattern **^.\*js$** will be excluded. ```xml @@ -35,7 +39,7 @@ In this sample match results with url http://www.cognifide.com/_cog_opt_js_f3595 ... - + ... @@ -49,31 +53,20 @@ In this sample match results with url http://www.cognifide.com/_cog_opt_js_f3595 ``` -There can be more than one `exclude` tags in `status-codes` comparator. They are processed in turns. Example below is equivalent to defined above: +There can be more than one `exclude` tags in `status-codes` comparator. They are processed in turns. Example below is equivalent to previous one: ```xml - + ``` -In this case both results with url http://www.cognifide.com/_cog_opt_js_f359581ea4bd3379b4c25591838a5dd8.js and urls that match pattern **^.\*js$** (ending with js) will not be displayed on reports. - -**Exclude** and **include** modifiers can be both applied to **status-codes comparator**. They are processed in turns. Example: - -```xml - - - - -``` - -In this case, at first all urls that do not match **^.\*js$** pattern are removed. Then url http://www.cognifide.com/_cog_opt_js_f359581ea4bd3379b4c25591838a5dd8.js is removed. Therefore only urls ending with `js` except http://www.cognifide.com/_cog_opt_js_f359581ea4bd3379b4c25591838a5dd8.js will be included in reports. +In this case both results with url http://www.external.com/_optional.js and urls that match pattern **^.\*js$** (ending with `js`) will not be displayed on reports. ##### Include Filter -Include Filter removes from reports Status Codes results that **do not** match specified parameters. +Include Filter excludes from reports Status Codes results that **do not** match specified parameters. Name: **include** @@ -83,14 +76,14 @@ Resource name: status-codes | Parameter | Value | Description | Mandatory | | --------- | ----- | ----------- | --------- | -| `url` | String url | Exact url to be included in reports. Results that do not match will be removed. | At least one of parameter is required. | -| `pattern` | String regex pattern | Regex pattern that urls should match to be included in reports. Results that do not match will be removed. | | +| `url` | String url | Exact url to be included in reports. Results that do not match will be excluded. | At least one of parameter is required. | +| `pattern` | String regex pattern | Regex pattern that urls should match to be included in reports. Results that do not match will be excluded. | | If both parameters are provided then result is only included in the report when it matches both of the parameters. ###### Example Usage -In example below **only** result with url http://www.cognifide.com/_cog_opt_js_f359581ea4bd3379b4c25591838a5dd8.js will be included in report. +In example below **only** result with url http://www.cognifide.com/main.js will be included in report. ```xml @@ -106,7 +99,7 @@ In example below **only** result with url http://www.cognifide.com/_cog_opt_js_f ... - + ... @@ -125,21 +118,23 @@ There can be more than one `include` tags in `status-codes` comparator. They are ```xml - + ``` -In this case only http://www.cognifide.com/_cog_opt_js_f359581ea4bd3379b4c25591838a5dd8.js url will be included on reports: first all results that do not match **^.\*js$** pattern (ending with `js`) are removed. Then within that result all urls different that "http://www.cognifide.com/_cog_opt_js_f359581ea4bd3379b4c25591838a5dd8.js" are removed. +In this case only http://www.cognifide.com/main.js url will be included on reports: first all results that do not match **^.\*js$** pattern (ending with `js`) are excluded. Then within that result all urls different from "http://www.cognifide.com/main.js" are excluded. In example above, first `` can be omitted and result will be the same. +##### Include and Exclude + **Include** and **exclude** modifiers can be both applied to **status-codes comparator**. They are processed in turns. Example: ```xml - + ``` -In this case only first all urls that do not match **^.\*js$** pattern are removed. Then url http://www.cognifide.com/_cog_opt_js_f359581ea4bd3379b4c25591838a5dd8.js is removed. Therefore only urls ending with `js` except http://www.cognifide.com/_cog_opt_js_f359581ea4bd3379b4c25591838a5dd8.js will be included in reports. +In example above we include URLs that match **^.\*js$**, so any other URL will be excluded. Then we exclude http://www.external.com/_optional.js. Therefore only urls ending with `js` except http://www.external.com/_optional.js will be included in reports. diff --git a/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java b/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java index 9ef03e614..3d41f365c 100644 --- a/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java +++ b/integration-tests/sanity-functional/src/test/java/com/cognifide/aet/sanity/functional/HomePageTilesTest.java @@ -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; diff --git a/integration-tests/sanity-functional/src/test/resources/features/filtering.feature b/integration-tests/sanity-functional/src/test/resources/features/filtering.feature index f10a12479..9b4143318 100644 --- a/integration-tests/sanity-functional/src/test/resources/features/filtering.feature +++ b/integration-tests/sanity-functional/src/test/resources/features/filtering.feature @@ -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 + And Statistics text contains "21 ( 9 / 0 / 12 / 0 )" Scenario: Filtering Tests Results: w3c-html5 Given I have opened sample tests report page diff --git a/integration-tests/test-suite/partials/status-codes.xml b/integration-tests/test-suite/partials/status-codes.xml index baba9af97..235dd54dd 100644 --- a/integration-tests/test-suite/partials/status-codes.xml +++ b/integration-tests/test-suite/partials/status-codes.xml @@ -32,11 +32,24 @@ - + + + + + + + + + + + + + + @@ -255,7 +268,7 @@ - + @@ -304,7 +317,7 @@ - +