From 05df98f61e41868d4815108ec7381bbd7671c4c1 Mon Sep 17 00:00:00 2001 From: Henning Gerhardt Date: Tue, 7 Feb 2023 10:07:29 +0100 Subject: [PATCH] Remove support for Travis use --- Kitodo/pom.xml | 8 -- .../testframework/BaseTestSelenium.java | 12 +-- .../selenium/testframework/Browser.java | 16 ---- .../testframework/helper/MailSender.java | 86 ------------------- .../testframework/helper/TestWatcherImpl.java | 76 ---------------- pom.xml | 12 --- 6 files changed, 1 insertion(+), 209 deletions(-) delete mode 100644 Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/MailSender.java delete mode 100644 Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/TestWatcherImpl.java diff --git a/Kitodo/pom.xml b/Kitodo/pom.xml index 61b3b98f8be..0f333e36878 100644 --- a/Kitodo/pom.xml +++ b/Kitodo/pom.xml @@ -121,14 +121,6 @@ org.codehaus.plexus plexus-container-default - - javax.mail - mail - - - org.apache.commons - commons-email - org.apache.activemq activemq-client diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/BaseTestSelenium.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/BaseTestSelenium.java index c655bd0930d..b474d88ec88 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/BaseTestSelenium.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/BaseTestSelenium.java @@ -18,14 +18,11 @@ import org.apache.logging.log4j.Logger; import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Rule; -import org.junit.rules.TestRule; -import org.kitodo.config.ConfigCore; import org.kitodo.ExecutionPermission; import org.kitodo.FileLoader; import org.kitodo.MockDatabase; +import org.kitodo.config.ConfigCore; import org.kitodo.config.enums.ParameterCore; -import org.kitodo.selenium.testframework.helper.TestWatcherImpl; public class BaseTestSelenium { @@ -77,11 +74,4 @@ public static void tearDown() throws Exception { MockDatabase.stopDatabaseServer(); MockDatabase.cleanDatabase(); } - - /** - * Watcher for WebDriverExceptions on travis which takes screenshot and sends - * email - */ - @Rule - public TestRule seleniumExceptionWatcher = new TestWatcherImpl(); } diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/Browser.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/Browser.java index 2618195861f..00187830e5f 100644 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/Browser.java +++ b/Kitodo/src/test/java/org/kitodo/selenium/testframework/Browser.java @@ -61,8 +61,6 @@ public class Browser { private static Actions actions; - private static boolean onTravis = false; - private static RemoteWebDriver webDriver; /** @@ -80,11 +78,6 @@ public static void Initialize() throws IOException { webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); goTo(""); webDriver.manage().window().setSize(new Dimension(1280, 1024)); - - if ("true".equals(System.getenv().get("TRAVIS"))) { - logger.debug("TRAVIS environment detected"); - onTravis = true; - } } private static void provideChromeDriver() throws IOException { @@ -346,13 +339,4 @@ public static int getDelayAfterCatalogSelection() { return DELAY_AFTER_CATALOG_SELECTION; } - /** - * Gets onTravis. - * - * @return True if this runs on Travis. - */ - public static boolean isOnTravis() { - return onTravis; - } - } diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/MailSender.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/MailSender.java deleted file mode 100644 index 9e7a27ea89e..00000000000 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/MailSender.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * (c) Kitodo. Key to digital objects e. V. - * - * This file is part of the Kitodo project. - * - * It is licensed under GNU General Public License version 3 or later. - * - * For the full copyright and license information, please read the - * GPL3-License.txt file that was distributed with this source code. - */ - -package org.kitodo.selenium.testframework.helper; - -import java.io.File; -import java.util.ArrayList; - -import javax.mail.internet.AddressException; -import javax.mail.internet.InternetAddress; - -import org.apache.commons.mail.DefaultAuthenticator; -import org.apache.commons.mail.EmailAttachment; -import org.apache.commons.mail.EmailException; -import org.apache.commons.mail.MultiPartEmail; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -public class MailSender { - - private static final Logger logger = LogManager.getLogger(MailSender.class); - - /** - * Sends an email. - * - * @param user - * The user name for login in to email account. - * @param password - * The password for login in to email account. - * @param subject - * The email subject. - * @param message - * The email message. - * @param attachedFile - * The attached file. - * @param recipient - * The recipient email address. - */ - public static void sendEmail(String user, String password, String subject, String message, File attachedFile, - String recipient) throws EmailException, AddressException { - - if (user != null && password != null && recipient != null) { - InternetAddress address = new InternetAddress(recipient); - - ArrayList addressList = new ArrayList<>(); - addressList.add(address); - - EmailAttachment attachment = new EmailAttachment(); - if (attachedFile != null) { - // Create the attachment - attachment.setPath(attachedFile.getAbsolutePath()); - attachment.setDisposition(EmailAttachment.ATTACHMENT); - attachment.setDescription("SeleniumScreenShot"); - attachment.setName("screenshot.png"); - } - - MultiPartEmail email = new MultiPartEmail(); - email.setHostName("smtp.gmail.com"); - email.setSmtpPort(465); - email.setAuthenticator(new DefaultAuthenticator(user, password)); - email.setSSLOnConnect(true); - email.setFrom("Travis CI Screenshot "); - if (subject != null) { - email.setSubject(subject); - } - if (message != null) { - email.setMsg(message); - } - email.setTo(addressList); - email.attach(attachment); - email.send(); - } else { - logger.error("Email was not send due to missing environmental variables"); - } - - } - -} diff --git a/Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/TestWatcherImpl.java b/Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/TestWatcherImpl.java deleted file mode 100644 index 2a5eaa1e438..00000000000 --- a/Kitodo/src/test/java/org/kitodo/selenium/testframework/helper/TestWatcherImpl.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * (c) Kitodo. Key to digital objects e. V. - * - * This file is part of the Kitodo project. - * - * It is licensed under GNU General Public License version 3 or later. - * - * For the full copyright and license information, please read the - * GPL3-License.txt file that was distributed with this source code. - */ - -package org.kitodo.selenium.testframework.helper; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.junit.rules.TestWatcher; -import org.junit.runner.Description; -import org.kitodo.selenium.testframework.Browser; -import org.openqa.selenium.WebDriverException; - -public class TestWatcherImpl extends TestWatcher { - - private static final Logger logger = LogManager.getLogger(TestWatcherImpl.class); - - private static final String TRAVIS_BUILD_NUMBER = "TRAVIS_BUILD_NUMBER"; - private static final String TRAVIS_BRANCH = "TRAVIS_BRANCH"; - private static final String TRAVIS_REPO_SLUG = "TRAVIS_REPO_SLUG"; - private static final String TRAVIS_BUILD_ID = "TRAVIS_BUILD_ID"; - private static final String MAIL_USER = "MAIL_USER"; - private static final String MAIL_PASSWORD = "MAIL_PASSWORD"; - private static final String MAIL_RECIPIENT = "MAIL_RECIPIENT"; - - @Override - protected void failed(Throwable ex, Description description) { - if (Browser.isOnTravis() && (ex instanceof WebDriverException)) { - try { - File screenshot = Browser.captureScreenShot(); - Map travisProperties = getTravisProperties(); - - String emailSubject = String.format("%s - #%s: Test Failure: %s: %s", - travisProperties.get(TRAVIS_BRANCH), travisProperties.get(TRAVIS_BUILD_NUMBER), - description.getClassName(), description.getMethodName()); - - String emailMessage = String.format( - "Selenium Test failed on build #%s: https://travis-ci.org/%s/builds/%s", - travisProperties.get(TRAVIS_BUILD_NUMBER), travisProperties.get(TRAVIS_REPO_SLUG), - travisProperties.get(TRAVIS_BUILD_ID)); - - String user = travisProperties.get(MAIL_USER); - String password = travisProperties.get(MAIL_PASSWORD); - String recipient = travisProperties.get(MAIL_RECIPIENT); - - MailSender.sendEmail(user, password, emailSubject, emailMessage, screenshot, recipient); - } catch (Exception mailException) { - logger.error("Unable to send screenshot", mailException); - } - } - super.failed(ex, description); - } - - private Map getTravisProperties() { - Map properties = new HashMap<>(); - properties.put(TRAVIS_BRANCH, System.getenv().get(TRAVIS_BRANCH)); - properties.put(TRAVIS_BUILD_ID, System.getenv().get(TRAVIS_BUILD_ID)); - properties.put(TRAVIS_BUILD_NUMBER, System.getenv().get(TRAVIS_BUILD_NUMBER)); - properties.put(TRAVIS_REPO_SLUG, System.getenv().get(TRAVIS_REPO_SLUG)); - properties.put(MAIL_USER, System.getenv().get(MAIL_USER)); - properties.put(MAIL_PASSWORD, System.getenv().get(MAIL_PASSWORD)); - properties.put(MAIL_RECIPIENT, System.getenv().get(MAIL_RECIPIENT)); - return properties; - } -} diff --git a/pom.xml b/pom.xml index b4f798ad2c9..85b6c85fd4d 100644 --- a/pom.xml +++ b/pom.xml @@ -210,12 +210,6 @@ 3.0.0 provided - - javax.mail - mail - 1.4.7 - test - javax.servlet jstl @@ -281,12 +275,6 @@ from system library in Java 11+ --> - - org.apache.commons - commons-email - 1.5 - test - org.apache.commons commons-exec