From 7fb62899c334c7ca096d8ec34111ce0c8b1ed7c7 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Fri, 22 Sep 2017 19:19:03 +0200 Subject: [PATCH 1/6] /series/add: allow to specify image URL. --- NEWS.txt | 1 + src/main/config/findbugs-filter.xml | 9 + .../web/config/ControllersConfig.java | 7 + .../ru/mystamps/web/config/MvcConfig.java | 9 + .../mystamps/web/config/ServicesConfig.java | 5 + .../web/controller/SeriesController.java | 69 ++++++- .../web/controller/TestController.java | 61 ++++++ .../web/controller/dto/AddSeriesForm.java | 75 ++++++- .../interceptor/ByteArrayMultipartFile.java | 86 ++++++++ .../interceptor/DownloadImageInterceptor.java | 145 +++++++++++++ .../controller/interceptor/package-info.java | 5 + .../web/service/DownloaderService.java | 24 +++ .../HttpURLConnectionDownloaderService.java | 194 ++++++++++++++++++ .../web/service/dto/DownloadResult.java | 57 +++++ .../beanvalidation/HasImageOrImageUrl.java | 36 ++++ .../RequireImageOrImageUrl.java | 46 +++++ .../RequireImageOrImageUrlValidator.java | 64 ++++++ .../support/spring/security/Authority.java | 1 + .../security/CustomUserDetailsService.java | 1 + .../support/spring/security/HasAuthority.java | 1 + .../spring/security/StringAuthority.java | 1 + .../ru/mystamps/i18n/Messages.properties | 1 + .../ru/mystamps/i18n/Messages_ru.properties | 1 + .../i18n/ValidationMessages.properties | 8 + .../i18n/ValidationMessages_ru.properties | 8 + src/main/scripts/ci/check-build-and-verify.sh | 2 +- src/main/webapp/WEB-INF/views/series/add.html | 28 ++- .../web/service/SeriesServiceImplTest.groovy | 3 + .../web/tests/page/AddSeriesPage.java | 2 +- .../series/creation/logic.robot | 17 +- .../series/creation/validation-user.robot | 40 ++++ .../series/creation/validation.robot | 48 ++++- 32 files changed, 1035 insertions(+), 20 deletions(-) create mode 100644 src/main/java/ru/mystamps/web/controller/TestController.java create mode 100644 src/main/java/ru/mystamps/web/controller/interceptor/ByteArrayMultipartFile.java create mode 100644 src/main/java/ru/mystamps/web/controller/interceptor/DownloadImageInterceptor.java create mode 100644 src/main/java/ru/mystamps/web/controller/interceptor/package-info.java create mode 100644 src/main/java/ru/mystamps/web/service/DownloaderService.java create mode 100644 src/main/java/ru/mystamps/web/service/HttpURLConnectionDownloaderService.java create mode 100644 src/main/java/ru/mystamps/web/service/dto/DownloadResult.java create mode 100644 src/main/java/ru/mystamps/web/support/beanvalidation/HasImageOrImageUrl.java create mode 100644 src/main/java/ru/mystamps/web/support/beanvalidation/RequireImageOrImageUrl.java create mode 100644 src/main/java/ru/mystamps/web/support/beanvalidation/RequireImageOrImageUrlValidator.java create mode 100644 src/test/robotframework/series/creation/validation-user.robot diff --git a/NEWS.txt b/NEWS.txt index f17e8ed6e9..d79a5c6712 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -15,6 +15,7 @@ - (functionality) name of category/country in Russian now are optional fields - (functionality) preview now is generated after uploading an image - (functionality) add interface for adding buyers and sellers +- (functionality) add capability to specify image URL (as alternative to providing a file) 0.3 - (functionality) implemented possibility to user to add series to his collection diff --git a/src/main/config/findbugs-filter.xml b/src/main/config/findbugs-filter.xml index c938e71341..783587134b 100644 --- a/src/main/config/findbugs-filter.xml +++ b/src/main/config/findbugs-filter.xml @@ -8,6 +8,15 @@ + + + + +
- + Later you will be able to add additional images @@ -242,6 +249,23 @@

+
+ +
+ + +
+
+
 Specify date of release diff --git a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy index 35987a2c17..d79da53573 100644 --- a/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy +++ b/src/test/groovy/ru/mystamps/web/service/SeriesServiceImplTest.groovy @@ -55,6 +55,7 @@ class SeriesServiceImplTest extends Specification { private AddImageForm imageForm private Integer userId + @SuppressWarnings('UnnecessaryGetter') def setup() { form = new AddSeriesForm() form.setQuantity(2) @@ -76,6 +77,8 @@ class SeriesServiceImplTest extends Specification { yvertCatalogService, gibbonsCatalogService ) + + multipartFile.getOriginalFilename() >> '/path/to/test/file.ext' } // diff --git a/src/test/java/ru/mystamps/web/tests/page/AddSeriesPage.java b/src/test/java/ru/mystamps/web/tests/page/AddSeriesPage.java index db889568bc..f4313a3e3e 100644 --- a/src/test/java/ru/mystamps/web/tests/page/AddSeriesPage.java +++ b/src/test/java/ru/mystamps/web/tests/page/AddSeriesPage.java @@ -79,7 +79,7 @@ public AddSeriesPage(WebDriver driver) { inputField("gibbonsNumbers"), inputField("gibbonsPrice"), textareaField("comment").accessibleByAll(false), - required(uploadFileField("image")) + uploadFileField("image") ) .and() .with(submitButton(tr("t_add"))) diff --git a/src/test/robotframework/series/creation/logic.robot b/src/test/robotframework/series/creation/logic.robot index 6fab0575bf..e508035ce9 100644 --- a/src/test/robotframework/series/creation/logic.robot +++ b/src/test/robotframework/series/creation/logic.robot @@ -8,8 +8,8 @@ Test Setup Before Test Force Tags series logic *** Test Cases *** -Create series by filling only required fields - [Documentation] Verify creation of series by filling only mandatory fields +Create series by filling only required fields and providing an image + [Documentation] Verify creation of series by filling only mandatory fields (with image) Select From List By Label id=category Sport Input Text id=quantity 2 Choose File id=image ${MAIN_RESOURCE_DIR}${/}test.png @@ -21,6 +21,19 @@ Create series by filling only required fields Element Text Should Be id=perforated Yes Page Should Contain Image id=series-image-1 +Create series by filling only required fields and providing a URL to image + [Documentation] Verify creation of series by filling only mandatory fields (with an image URL) + Select From List By Label id=category Sport + Input Text id=quantity 1 + Input Text id=image-url ${SITE_URL}/image/1 + Submit Form id=add-series-form + ${location}= Get Location + Should Match Regexp ${location} /series/\\d+ + Element Text Should Be id=category_name Sport + Element Text Should Be id=quantity 1 + Element Text Should Be id=perforated Yes + Page Should Contain Image id=series-image-1 + Create series by filling all fields [Documentation] Verify creation of series by filling all fields [Tags] unstable diff --git a/src/test/robotframework/series/creation/validation-user.robot b/src/test/robotframework/series/creation/validation-user.robot new file mode 100644 index 0000000000..cb0dacf656 --- /dev/null +++ b/src/test/robotframework/series/creation/validation-user.robot @@ -0,0 +1,40 @@ +*** Settings *** +Documentation Verify series creation validation scenarios from a user +Library Selenium2Library +Suite Setup Before Test Suite +Suite Teardown After Test Suite +Force Tags series validation + +*** Test Cases *** +Create series with empty required fields + [Documentation] Verify validation of mandatory fields + Submit Form id=add-series-form + Element Text Should Be id=category.errors Value must not be empty + Element Text Should Be id=quantity.errors Value must not be empty + Element Text Should Be id=image.errors Value must not be empty + Page Should Not Contain Element id=image-url.errors + +*** Keywords *** +Before Test Suite + [Documentation] Login as a user and go to create series page + Open Browser ${SITE_URL} ${BROWSER} + Register Keyword To Run On Failure Log Source + Log In As login=coder password=test + Go To ${SITE_URL}/series/add + +After Test Suite + [Documentation] Log out and close browser + Log Out + Close Browser + +Log In As + [Documentation] Log in as a user + [Arguments] ${login} ${password} + Go To ${SITE_URL}/account/auth + Input Text id=login ${login} + Input Password id=password ${password} + Submit Form id=auth-account-form + +Log Out + [Documentation] Log out current user + Submit Form id=logout-form diff --git a/src/test/robotframework/series/creation/validation.robot b/src/test/robotframework/series/creation/validation.robot index 35cf7e3631..11def12cea 100644 --- a/src/test/robotframework/series/creation/validation.robot +++ b/src/test/robotframework/series/creation/validation.robot @@ -1,5 +1,5 @@ *** Settings *** -Documentation Verify series creation validation scenarios +Documentation Verify series creation validation scenarios from admin Library Selenium2Library Resource ../../auth.steps.robot Suite Setup Before Test Suite @@ -7,6 +7,14 @@ Suite Teardown After Test Suite Force Tags series validation *** Test Cases *** +Create series with empty required fields + [Documentation] Verify validation of mandatory fields + Submit Form id=add-series-form + Element Text Should Be id=category.errors Value must not be empty + Element Text Should Be id=quantity.errors Value must not be empty + Element Text Should Be id=image.errors Image or image URL must be specified + Element Text Should Be id=image-url.errors Image or image URL must be specified + Create series with non-numeric quantity [Documentation] Verify validation of non-numeric quantity Input Text id=quantity NaN @@ -31,6 +39,44 @@ Create series with empty image Submit Form id=add-series-form Element Text Should Be id=image.errors File must not be empty +Create series with both image and an image URL + [Documentation] Verify validation of an image and an image URL provided at the same time + Choose File id=image ${MAIN_RESOURCE_DIR}${/}test.png + Input Text id=image-url ${SITE_URL}/image/1 + Submit Form id=add-series-form + Element Text Should Be id=image.errors Image or image URL must be specified + Element Text Should Be id=image-url.errors Image or image URL must be specified + +Create series with image URL with invalid response + [Documentation] Verify validation of invalid response from a server + Input Text id=image-url ${SITE_URL}/test/invalid/response-400 + Submit Form id=add-series-form + Element Text Should Be id=image-url.errors Could not download file + +Create series with image URL to a file that does not exist + [Documentation] Verify validation of URL to non existing file + Input Text id=image-url ${SITE_URL}/test/invalid/response-404 + Submit Form id=add-series-form + Element Text Should Be id=image-url.errors File not found + +Create series with image URL that causes a redirect + [Documentation] Verify validation of URL with redirect + Input Text id=image-url ${SITE_URL}/test/invalid/response-301 + Submit Form id=add-series-form + Element Text Should Be id=image-url.errors URL must not redirect to another address + +Create series with image URL to an empty file + [Documentation] Verify validation of URL to an empty file + Input Text id=image-url ${SITE_URL}/test/invalid/empty-jpeg-file + Submit Form id=add-series-form + Element Text Should Be id=image-url.errors File must not be empty + +Create series with image URL to not an image file + [Documentation] Verify validation of URL to a file of unsupported type + Input Text id=image-url ${SITE_URL}/test/invalid/not-image-file + Submit Form id=add-series-form + Element Text Should Be id=image-url.errors Invalid file type + Catalog numbers should reject invalid values [Documentation] Verify that fields with catalog numbers reject invalid values [Tags] unstable From 376b9bbbe8f74b76c9ce8ddbc8081022a655ff7f Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 30 Sep 2017 19:07:16 +0200 Subject: [PATCH 2/6] /series/{id}: add label and use a standard markup for image upload field. Required for adding a field for specifying image URL later. No functional changes. --- .../webapp/WEB-INF/views/series/info.html | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index ed93d23118..008847a153 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -86,21 +86,30 @@
-
+
-
- - +
+ +
+ + +
-
- +
+
+ +
From eac6eb89a8438779a0b316936a81db44bda4b097 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 1 Oct 2017 00:30:44 +0200 Subject: [PATCH 3/6] NullableImageUrl: introduce the interface for zeroing image url field. Required for adding a field for specifying image URL later. No functional changes. --- .../web/controller/SeriesController.java | 5 ++-- .../web/controller/dto/AddSeriesForm.java | 2 +- .../web/controller/dto/NullableImageUrl.java | 29 +++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 src/main/java/ru/mystamps/web/controller/dto/NullableImageUrl.java diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index 7793ef01b9..8fc2112a72 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -63,6 +63,7 @@ import ru.mystamps.web.controller.dto.AddImageForm; import ru.mystamps.web.controller.dto.AddSeriesForm; import ru.mystamps.web.controller.dto.AddSeriesSalesForm; +import ru.mystamps.web.controller.dto.NullableImageUrl; import ru.mystamps.web.controller.interceptor.DownloadImageInterceptor; import ru.mystamps.web.dao.dto.EntityWithIdDto; import ru.mystamps.web.dao.dto.LinkEntityDto; @@ -499,7 +500,7 @@ private void addSeriesSalesFormToModel(Model model) { } private static void loadErrorsFromDownloadInterceptor( - AddSeriesForm form, + NullableImageUrl form, BindingResult result, HttpServletRequest request) { @@ -525,7 +526,7 @@ private static void loadErrorsFromDownloadInterceptor( "image", "ru.mystamps.web.support.beanvalidation.NotEmptyFilename.message" ); - form.setImageUrl(null); + form.nullifyImageUrl(); break; default: result.rejectValue( diff --git a/src/main/java/ru/mystamps/web/controller/dto/AddSeriesForm.java b/src/main/java/ru/mystamps/web/controller/dto/AddSeriesForm.java index e46239a64f..843d8b35f8 100644 --- a/src/main/java/ru/mystamps/web/controller/dto/AddSeriesForm.java +++ b/src/main/java/ru/mystamps/web/controller/dto/AddSeriesForm.java @@ -75,7 +75,7 @@ ) }) @ReleaseDateIsNotInFuture(groups = AddSeriesForm.ReleaseDate3Checks.class) -public class AddSeriesForm implements AddSeriesDto, HasImageOrImageUrl { +public class AddSeriesForm implements AddSeriesDto, HasImageOrImageUrl, NullableImageUrl { // FIXME: change type to plain Integer @NotNull diff --git a/src/main/java/ru/mystamps/web/controller/dto/NullableImageUrl.java b/src/main/java/ru/mystamps/web/controller/dto/NullableImageUrl.java new file mode 100644 index 0000000000..f2c3e9eb22 --- /dev/null +++ b/src/main/java/ru/mystamps/web/controller/dto/NullableImageUrl.java @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2009-2017 Slava Semushin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package ru.mystamps.web.controller.dto; + +/** + * Interface of the form that has image URL field and supports its zeroed. + */ +public interface NullableImageUrl { + void setImageUrl(String url); + + default void nullifyImageUrl() { + setImageUrl(null); + } +} From 9ab9fb5ffee1c6dcb476e674b0fafc2443bd8b6c Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sat, 30 Sep 2017 19:11:57 +0200 Subject: [PATCH 4/6] /series/info: implement --- .../ru/mystamps/web/config/MvcConfig.java | 2 +- .../web/controller/SeriesController.java | 39 +++++++- .../web/controller/dto/AddImageForm.java | 89 +++++++++++++++---- .../webapp/WEB-INF/views/series/info.html | 23 ++++- 4 files changed, 133 insertions(+), 20 deletions(-) diff --git a/src/main/java/ru/mystamps/web/config/MvcConfig.java b/src/main/java/ru/mystamps/web/config/MvcConfig.java index 794c38d0d6..219562c661 100755 --- a/src/main/java/ru/mystamps/web/config/MvcConfig.java +++ b/src/main/java/ru/mystamps/web/config/MvcConfig.java @@ -130,7 +130,7 @@ public void addInterceptors(InterceptorRegistry registry) { registry .addInterceptor(getDownloadImageInterceptor()) - .addPathPatterns(Url.ADD_SERIES_PAGE); + .addPathPatterns(Url.ADD_SERIES_PAGE, Url.ADD_IMAGE_SERIES_PAGE); } @Override diff --git a/src/main/java/ru/mystamps/web/controller/SeriesController.java b/src/main/java/ru/mystamps/web/controller/SeriesController.java index 8fc2112a72..69fa09680a 100644 --- a/src/main/java/ru/mystamps/web/controller/SeriesController.java +++ b/src/main/java/ru/mystamps/web/controller/SeriesController.java @@ -266,14 +266,47 @@ public String showInfo( return "series/info"; } - @PostMapping(Url.ADD_IMAGE_SERIES_PAGE) + @SuppressWarnings("checkstyle:parameternumber") + @PostMapping(path = Url.ADD_IMAGE_SERIES_PAGE, params = "imageUrl") + public String processImageWithImageUrl( + @Validated({ + AddImageForm.ImageUrlChecks.class, + AddImageForm.ImageChecks.class + }) AddImageForm form, + BindingResult result, + @PathVariable("id") Integer seriesId, + Model model, + @CurrentUser Integer currentUserId, + Locale userLocale, + HttpServletRequest request, + HttpServletResponse response) + throws IOException { + + return processImage( + form, + result, + seriesId, + model, + currentUserId, + userLocale, + request, + response + ); + } + + @SuppressWarnings("checkstyle:parameternumber") + @PostMapping(path = Url.ADD_IMAGE_SERIES_PAGE, params = "!imageUrl") public String processImage( - @Valid AddImageForm form, + @Validated({ + AddImageForm.RequireImageCheck.class, + AddImageForm.ImageChecks.class }) + AddImageForm form, BindingResult result, @PathVariable("id") Integer seriesId, Model model, @CurrentUser Integer currentUserId, Locale userLocale, + HttpServletRequest request, HttpServletResponse response) throws IOException { @@ -289,6 +322,8 @@ public String processImage( return null; } + loadErrorsFromDownloadInterceptor(form, result, request); + boolean maxQuantityOfImagesExceeded = !isAdmin() && !isAllowedToAddingImages(series); model.addAttribute("maxQuantityOfImagesExceeded", maxQuantityOfImagesExceeded); diff --git a/src/main/java/ru/mystamps/web/controller/dto/AddImageForm.java b/src/main/java/ru/mystamps/web/controller/dto/AddImageForm.java index 2f19f097df..1d2ee85e08 100644 --- a/src/main/java/ru/mystamps/web/controller/dto/AddImageForm.java +++ b/src/main/java/ru/mystamps/web/controller/dto/AddImageForm.java @@ -18,7 +18,10 @@ package ru.mystamps.web.controller.dto; import javax.validation.GroupSequence; -import javax.validation.constraints.NotNull; + +import org.apache.commons.lang3.StringUtils; + +import org.hibernate.validator.constraints.URL; import org.springframework.web.multipart.MultipartFile; @@ -26,31 +29,85 @@ import lombok.Setter; import ru.mystamps.web.service.dto.AddImageDto; +import ru.mystamps.web.support.beanvalidation.HasImageOrImageUrl; import ru.mystamps.web.support.beanvalidation.ImageFile; import ru.mystamps.web.support.beanvalidation.MaxFileSize; import ru.mystamps.web.support.beanvalidation.MaxFileSize.Unit; import ru.mystamps.web.support.beanvalidation.NotEmptyFile; import ru.mystamps.web.support.beanvalidation.NotEmptyFilename; +import ru.mystamps.web.support.beanvalidation.RequireImageOrImageUrl; import static ru.mystamps.web.validation.ValidationRules.MAX_IMAGE_SIZE; @Getter @Setter -@GroupSequence({ - AddImageForm.class, - Group.Level1.class, - Group.Level2.class, - Group.Level3.class, - Group.Level4.class, - Group.Level5.class -}) -public class AddImageForm implements AddImageDto { - - @NotNull(groups = Group.Level1.class) - @NotEmptyFilename(groups = Group.Level2.class) - @NotEmptyFile(groups = Group.Level3.class) - @MaxFileSize(value = MAX_IMAGE_SIZE, unit = Unit.Kbytes, groups = Group.Level4.class) - @ImageFile(groups = Group.Level5.class) +@RequireImageOrImageUrl(groups = AddImageForm.ImageUrl1Checks.class) +public class AddImageForm implements AddImageDto, HasImageOrImageUrl, NullableImageUrl { + + // Name of this field should match with the value of + // DownloadImageInterceptor.UPLOADED_IMAGE_FIELD_NAME. + @NotEmptyFilename(groups = RequireImageCheck.class) + @NotEmptyFile(groups = Group.Level1.class) + @MaxFileSize(value = MAX_IMAGE_SIZE, unit = Unit.Kbytes, groups = Group.Level2.class) + @ImageFile(groups = Group.Level2.class) private MultipartFile image; + // Name of this field must match with the value of DownloadImageInterceptor.URL_PARAMETER_NAME. + @URL(groups = ImageUrl2Checks.class) + private String imageUrl; + + // This field holds a file that was downloaded from imageUrl. + // Name of this field must match with the value of + // DownloadImageInterceptor.DOWNLOADED_IMAGE_FIELD_NAME. + @NotEmptyFile(groups = Group.Level1.class) + @MaxFileSize(value = MAX_IMAGE_SIZE, unit = Unit.Kbytes, groups = Group.Level2.class) + @ImageFile(groups = Group.Level2.class) + private MultipartFile downloadedImage; + + @Override + public MultipartFile getImage() { + if (hasImage()) { + return image; + } + + return downloadedImage; + } + + // This method has to be implemented to satisfy HasImageOrImageUrl requirements. + // The latter is being used by RequireImageOrImageUrl validator. + @Override + public boolean hasImage() { + return image != null && StringUtils.isNotEmpty(image.getOriginalFilename()); + } + + // This method has to be implemented to satisfy HasImageOrImageUrl requirements. + // The latter is being used by RequireImageOrImageUrl validator. + @Override + public boolean hasImageUrl() { + return StringUtils.isNotEmpty(imageUrl); + } + + public interface RequireImageCheck { + } + + @GroupSequence({ + ImageUrl1Checks.class, + ImageUrl2Checks.class, + }) + public interface ImageUrlChecks { + } + + public interface ImageUrl1Checks { + } + + public interface ImageUrl2Checks { + } + + @GroupSequence({ + Group.Level1.class, + Group.Level2.class + }) + public interface ImageChecks { + } + } diff --git a/src/main/webapp/WEB-INF/views/series/info.html b/src/main/webapp/WEB-INF/views/series/info.html index 008847a153..99b139edec 100644 --- a/src/main/webapp/WEB-INF/views/series/info.html +++ b/src/main/webapp/WEB-INF/views/series/info.html @@ -100,12 +100,33 @@
- +
+
+ +
+ + +
+
From 6b1a552c6720f79d8c369ccf872a98900cf9efe5 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Sun, 1 Oct 2017 16:20:17 +0200 Subject: [PATCH 5/6] /series/info: add tests --- .../series/add-image/logic.robot | 12 ++++- .../series/add-image/validation.robot | 45 +++++++++++++++++-- 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/src/test/robotframework/series/add-image/logic.robot b/src/test/robotframework/series/add-image/logic.robot index 21d27a12de..89ffe85aca 100644 --- a/src/test/robotframework/series/add-image/logic.robot +++ b/src/test/robotframework/series/add-image/logic.robot @@ -8,14 +8,22 @@ Test Setup Before Test Force Tags series add-image logic *** Test Cases *** -Add additional image - [Documentation] Verify adding an additional image to a series +Add additional image by providing a file + [Documentation] Verify uploading an additional image to a series Page Should Not Contain Image id=series-image-2 Choose File id=image ${MAIN_RESOURCE_DIR}${/}test.png Submit Form id=add-image-form Location Should Be ${SITE_URL}/series/1 Page Should Contain Image id=series-image-2 +Add additional image by providing a URL to image + [Documentation] Verify downloading an additional image to a series + Page Should Not Contain Image id=series-image-3 + Input Text id=image-url ${SITE_URL}/image/1 + Submit Form id=add-image-form + Location Should Be ${SITE_URL}/series/1 + Page Should Contain Image id=series-image-3 + *** Keywords *** Before Test Suite [Documentation] Open browser, register fail hook and login as admin diff --git a/src/test/robotframework/series/add-image/validation.robot b/src/test/robotframework/series/add-image/validation.robot index 1c4eda722d..5aa4ab7294 100644 --- a/src/test/robotframework/series/add-image/validation.robot +++ b/src/test/robotframework/series/add-image/validation.robot @@ -7,10 +7,11 @@ Suite Teardown After Test Suite Force Tags series add-image validation *** Test Cases *** -Add image but without filling a required field - [Documentation] Verify validation of a required field +Add image with empty required fields + [Documentation] Verify validation of mandatory fields Submit Form id=add-image-form - Element Text Should Be id=image.errors Value must not be empty + Element Text Should Be id=image.errors Image or image URL must be specified + Element Text Should Be id=image-url.errors Image or image URL must be specified Add image with empty file [Documentation] Verify validation of an empty file @@ -18,6 +19,44 @@ Add image with empty file Submit Form id=add-image-form Element Text Should Be id=image.errors File must not be empty +Add image with both image and an image URL + [Documentation] Verify validation of an image and an image URL provided at the same time + Choose File id=image ${MAIN_RESOURCE_DIR}${/}test.png + Input Text id=image-url ${SITE_URL}/image/1 + Submit Form id=add-image-form + Element Text Should Be id=image.errors Image or image URL must be specified + Element Text Should Be id=image-url.errors Image or image URL must be specified + +Add image with image URL with invalid response + [Documentation] Verify validation of invalid response from a server + Input Text id=image-url ${SITE_URL}/test/invalid/response-400 + Submit Form id=add-image-form + Element Text Should Be id=image-url.errors Could not download file + +Add image with image URL to a file that does not exist + [Documentation] Verify validation of URL to non existing file + Input Text id=image-url ${SITE_URL}/test/invalid/response-404 + Submit Form id=add-image-form + Element Text Should Be id=image-url.errors File not found + +Add image with image URL that causes a redirect + [Documentation] Verify validation of URL with redirect + Input Text id=image-url ${SITE_URL}/test/invalid/response-301 + Submit Form id=add-image-form + Element Text Should Be id=image-url.errors URL must not redirect to another address + +Add image with image URL to an empty file + [Documentation] Verify validation of URL to an empty file + Input Text id=image-url ${SITE_URL}/test/invalid/empty-jpeg-file + Submit Form id=add-image-form + Element Text Should Be id=image-url.errors File must not be empty + +Add image with image URL to not an image file + [Documentation] Verify validation of URL to a file of unsupported type + Input Text id=image-url ${SITE_URL}/test/invalid/not-image-file + Submit Form id=add-image-form + Element Text Should Be id=image-url.errors Invalid file type + *** Keywords *** Before Test Suite [Documentation] Login as admin and open a page with a series info From aec2c934834f0b0a54e89e34f5f8b91f746b7252 Mon Sep 17 00:00:00 2001 From: Slava Semushin Date: Mon, 16 Oct 2017 19:47:32 +0200 Subject: [PATCH 6/6] add tests for invalid url --- src/test/robotframework/series/add-image/validation.robot | 6 ++++++ src/test/robotframework/series/creation/validation.robot | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/src/test/robotframework/series/add-image/validation.robot b/src/test/robotframework/series/add-image/validation.robot index 5aa4ab7294..1198ab77f5 100644 --- a/src/test/robotframework/series/add-image/validation.robot +++ b/src/test/robotframework/series/add-image/validation.robot @@ -27,6 +27,12 @@ Add image with both image and an image URL Element Text Should Be id=image.errors Image or image URL must be specified Element Text Should Be id=image-url.errors Image or image URL must be specified +Add image with invalid URL + [Documentation] Verify validation of invalid URL + Input Text id=image-url invalid-url + Submit Form id=add-image-form + Element Text Should Be id=image-url.errors Value must be a valid URL + Add image with image URL with invalid response [Documentation] Verify validation of invalid response from a server Input Text id=image-url ${SITE_URL}/test/invalid/response-400 diff --git a/src/test/robotframework/series/creation/validation.robot b/src/test/robotframework/series/creation/validation.robot index 11def12cea..6b8c87e66e 100644 --- a/src/test/robotframework/series/creation/validation.robot +++ b/src/test/robotframework/series/creation/validation.robot @@ -47,6 +47,12 @@ Create series with both image and an image URL Element Text Should Be id=image.errors Image or image URL must be specified Element Text Should Be id=image-url.errors Image or image URL must be specified +Create series with invalid image URL + [Documentation] Verify validation of invalid URL + Input Text id=image-url invalid-url + Submit Form id=add-series-form + Element Text Should Be id=image-url.errors Value must be a valid URL + Create series with image URL with invalid response [Documentation] Verify validation of invalid response from a server Input Text id=image-url ${SITE_URL}/test/invalid/response-400