From 4e19bd3c6f2f72ab4b071be2991d1d2e39921d62 Mon Sep 17 00:00:00 2001 From: Jason House Date: Thu, 6 Aug 2020 17:32:34 +0900 Subject: [PATCH] Cleaning up tests --- .../gaps/service/NotificationService.java | 140 +++++++++++++----- cypress/integration/common.js | 4 +- .../recommended/recommendedBadChars.js | 77 ---------- cypress/integration/rss/rss.js | 5 +- 4 files changed, 104 insertions(+), 122 deletions(-) delete mode 100644 cypress/integration/recommended/recommendedBadChars.js diff --git a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/NotificationService.java b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/NotificationService.java index aa02179..ea13a84 100644 --- a/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/NotificationService.java +++ b/GapsWeb/src/main/java/com/jasonhhouse/gaps/service/NotificationService.java @@ -13,12 +13,17 @@ import com.jasonhhouse.gaps.NotificationType; import com.jasonhhouse.gaps.PlexLibrary; import com.jasonhhouse.gaps.PlexServer; import com.jasonhhouse.gaps.notifications.NotificationAgent; +import com.jasonhhouse.gaps.notifications.TelegramNotificationAgent; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; @Service public class NotificationService implements Notification { + private static final Logger LOGGER = LoggerFactory.getLogger(TelegramNotificationAgent.class); + private final List notificationAgents; public NotificationService(List notificationAgents) { @@ -27,74 +32,119 @@ public class NotificationService implements Notification { @Override public void plexServerConnectFailed(PlexServer plexServer, String error) { - notificationAgents - .stream() - .filter(NotificationAgent::isEnabled) - .forEach(notificationAgent -> notificationAgent.sendMessage(NotificationType.TEST_PLEX_SERVER, "ERROR", "Gaps Search", String.format("Connection to Plex Server %s Failed. %s", plexServer.getFriendlyName(), error))); + for (NotificationAgent notificationAgent : notificationAgents) { + if (notificationAgent.isEnabled()) { + try { + notificationAgent.sendMessage(NotificationType.TEST_PLEX_SERVER, "ERROR", "Gaps Search", String.format("Connection to Plex Server %s Failed. %s", plexServer.getFriendlyName(), error)); + } catch (Exception e) { + LOGGER.error(String.format("Failed to send message when plex server connection failed to %s", notificationAgent.getName()), e); + } + } + } } @Override public void plexServerConnectSuccessful(PlexServer plexServer) { - notificationAgents - .stream() - .filter(NotificationAgent::isEnabled) - .forEach(notificationAgent -> notificationAgent.sendMessage(NotificationType.TEST_PLEX_SERVER, "INFO", "Gaps Search", String.format("Connection to Plex Server %s Successful", plexServer.getFriendlyName()))); + for (NotificationAgent notificationAgent : notificationAgents) { + if (notificationAgent.isEnabled()) { + try { + notificationAgent.sendMessage(NotificationType.TEST_PLEX_SERVER, "INFO", "Gaps Search", String.format("Connection to Plex Server %s Successful", plexServer.getFriendlyName())); + } catch (Exception e) { + LOGGER.error(String.format("Failed to send message when plex server connection successful to %s", notificationAgent.getName()), e); + } + } + } } @Override public void plexLibraryScanFailed(PlexServer plexServer, PlexLibrary plexLibrary, String error) { - notificationAgents - .stream() - .filter(NotificationAgent::isEnabled) - .forEach(notificationAgent -> notificationAgent.sendMessage(NotificationType.SCAN_PLEX_SERVER, "INFO", "Gaps Search", String.format("Scanning Plex Server %s in %s Library Failed. %s", plexServer.getFriendlyName(), plexLibrary.getTitle(), error))); + for (NotificationAgent notificationAgent : notificationAgents) { + if (notificationAgent.isEnabled()) { + try { + notificationAgent.sendMessage(NotificationType.SCAN_PLEX_SERVER, "INFO", "Gaps Search", String.format("Scanning Plex Server %s in %s Library Failed. %s", plexServer.getFriendlyName(), plexLibrary.getTitle(), error)); + } catch (Exception e) { + LOGGER.error(String.format("Failed to send message when plex library scan failed to %s", notificationAgent.getName()), e); + } + } + } } @Override public void plexLibraryScanSuccessful(PlexServer plexServer, PlexLibrary plexLibrary) { - notificationAgents - .stream() - .filter(NotificationAgent::isEnabled) - .forEach(notificationAgent -> notificationAgent.sendMessage(NotificationType.SCAN_PLEX_SERVER, "INFO", "Gaps Search", String.format("Scanning Plex Server %s in %s Library Successful", plexServer.getFriendlyName(), plexLibrary.getTitle()))); + for (NotificationAgent notificationAgent : notificationAgents) { + if (notificationAgent.isEnabled()) { + try { + notificationAgent.sendMessage(NotificationType.SCAN_PLEX_SERVER, "INFO", "Gaps Search", String.format("Scanning Plex Server %s in %s Library Successful", plexServer.getFriendlyName(), plexLibrary.getTitle())); + } catch (Exception e) { + LOGGER.error(String.format("Failed to send message when plex library scan succeeded to %s", notificationAgent.getName()), e); + } + } + } } @Override public void tmdbConnectionFailed(String error) { - notificationAgents - .stream() - .filter(NotificationAgent::isEnabled) - .forEach(notificationAgent -> notificationAgent.sendMessage(NotificationType.TEST_TMDB, "INFO", "Gaps Search", String.format("TMDB Connection Failed. %s", error))); + for (NotificationAgent notificationAgent : notificationAgents) { + if (notificationAgent.isEnabled()) { + try { + notificationAgent.sendMessage(NotificationType.TEST_TMDB, "INFO", "Gaps Search", String.format("TMDB Connection Failed. %s", error)); + } catch (Exception e) { + LOGGER.error(String.format("Failed to send message when TMDB connection test failed to %s", notificationAgent.getName()), e); + } + } + } } @Override public void tmdbConnectionSuccessful() { - notificationAgents - .stream() - .filter(NotificationAgent::isEnabled) - .forEach(notificationAgent -> notificationAgent.sendMessage(NotificationType.TEST_TMDB, "INFO", "Gaps Search", "TMDB Connection Successful")); + for (NotificationAgent notificationAgent : notificationAgents) { + if (notificationAgent.isEnabled()) { + try { + notificationAgent.sendMessage(NotificationType.TEST_TMDB, "INFO", "Gaps Search", "TMDB Connection Successful"); + } catch (Exception e) { + LOGGER.error(String.format("Failed to send message when TMDB connection test succeeded to %s", notificationAgent.getName()), e); + } + } + } } @Override public void recommendedMoviesSearchStarted(PlexServer plexServer, PlexLibrary plexLibrary) { - notificationAgents - .stream() - .filter(NotificationAgent::isEnabled) - .forEach(notificationAgent -> notificationAgent.sendMessage(NotificationType.RECOMMENDED_MOVIES, "INFO", "Gaps Search", String.format("Scanning Plex Server %s on Library %s Started", plexServer.getFriendlyName(), plexLibrary.getTitle()))); + for (NotificationAgent notificationAgent : notificationAgents) { + if (notificationAgent.isEnabled()) { + try { + notificationAgent.sendMessage(NotificationType.RECOMMENDED_MOVIES, "INFO", "Gaps Search", String.format("Scanning Plex Server %s on Library %s Started", plexServer.getFriendlyName(), plexLibrary.getTitle())); + } catch (Exception e) { + LOGGER.error(String.format("Failed to send message when recommending movies started to %s", notificationAgent.getName()), e); + } + } + } } @Override public void recommendedMoviesSearchFailed(PlexServer plexServer, PlexLibrary plexLibrary, String error) { - notificationAgents - .stream() - .filter(NotificationAgent::isEnabled) - .forEach(notificationAgent -> notificationAgent.sendMessage(NotificationType.RECOMMENDED_MOVIES, "INFO", "Gaps Search", String.format("Scanning Plex Server %s on Library %s Failed %s", plexServer.getFriendlyName(), plexLibrary.getTitle(), error))); + for (NotificationAgent notificationAgent : notificationAgents) { + if (notificationAgent.isEnabled()) { + try { + notificationAgent.sendMessage(NotificationType.RECOMMENDED_MOVIES, "INFO", "Gaps Search", String.format("Scanning Plex Server %s on Library %s Failed %s", plexServer.getFriendlyName(), plexLibrary.getTitle(), error)); + } catch (Exception e) { + LOGGER.error(String.format("Failed to send message when recommending movies failed to %s", notificationAgent.getName()), e); + } + } + } } @Override public void recommendedMoviesSearchFinished(PlexServer plexServer, PlexLibrary plexLibrary) { - notificationAgents - .stream() - .filter(NotificationAgent::isEnabled) - .forEach(notificationAgent -> notificationAgent.sendMessage(NotificationType.RECOMMENDED_MOVIES, "INFO", "Gaps Search", String.format("Scanning Plex Server %s on Library %s Successfully Finished", plexServer.getFriendlyName(), plexLibrary.getTitle()))); + for (NotificationAgent notificationAgent : notificationAgents) { + if (notificationAgent.isEnabled()) { + try { + notificationAgent.sendMessage(NotificationType.RECOMMENDED_MOVIES, "INFO", "Gaps Search", String.format("Scanning Plex Server %s on Library %s Successfully Finished", plexServer.getFriendlyName(), plexLibrary.getTitle())); + } catch (Exception e) { + LOGGER.error(String.format("Failed to send message when recommending movies finished to %s", notificationAgent.getName()), e); + } + } + } } @Override @@ -102,9 +152,14 @@ public class NotificationService implements Notification { boolean passedTest = true; for (NotificationAgent notificationAgent : notificationAgents) { - boolean result = notificationAgent.sendMessage(NotificationType.TEST, "DEBUG", "Gaps Test", "Test Successful"); - if (!result) { - passedTest = false; + try { + boolean result = notificationAgent.sendMessage(NotificationType.TEST, "DEBUG", "Gaps Test", "Test Successful"); + if (!result) { + passedTest = false; + } + } catch (Exception e) { + LOGGER.error(String.format("Failed to send test all message to %s", notificationAgent.getName()), e); + return false; } } @@ -115,7 +170,12 @@ public class NotificationService implements Notification { public boolean test(int id) throws IllegalArgumentException { for (NotificationAgent notificationAgent : notificationAgents) { if (notificationAgent.getId() == id) { - return notificationAgent.sendMessage(NotificationType.TEST, "DEBUG", "Gaps Test", "Test Successful"); + try { + return notificationAgent.sendMessage(NotificationType.TEST, "DEBUG", "Gaps Test", "Test Successful"); + } catch (Exception e) { + LOGGER.error(String.format("Failed to send test message to %s", notificationAgent.getName()), e); + return false; + } } } throw new IllegalArgumentException("Invalid Id for Notification Agent"); diff --git a/cypress/integration/common.js b/cypress/integration/common.js index 83678b8..3e7a58e 100755 --- a/cypress/integration/common.js +++ b/cypress/integration/common.js @@ -46,10 +46,10 @@ export function searchPlexForMoviesFromMovies(cy) { cy.get('label > input') .clear() - .type('2001 A Space'); + .type('Gods'); cy.get('#movies_info') - .should('have.text', 'Showing 1 to 1 of 1 entries (filtered from 4 total entries)'); + .should('have.text', 'Showing 1 to 1 of 1 entries (filtered from 21 total entries)'); } export function nuke() { diff --git a/cypress/integration/recommended/recommendedBadChars.js b/cypress/integration/recommended/recommendedBadChars.js deleted file mode 100644 index 3a944d5..0000000 --- a/cypress/integration/recommended/recommendedBadChars.js +++ /dev/null @@ -1,77 +0,0 @@ -import {redLibraryBefore, searchPlexForMoviesFromMovies, spyOnAddEventListener} from "../common"; - -describe('Search for Recommended Best Movies', function () { - beforeEach(redLibraryBefore); - - it('Clean configuration page load', () => { - searchMoviesLibrary(cy); - - cy.get('#libraryTitle').then( ($libraryTitle) => { - if($libraryTitle.text() !== "Movies") { - cy.get('#dropdownMenuLink') - .click(); - cy.get('[data-key="1"]') - .click(); - } - }); - - cy.get('#noMovieContainer > .card > .card-img-top') - .should('not.be.visible'); - - }); - - it('Search Movies with bad chars', () => { - searchMoviesLibrary(cy); - - cy.get('#dropdownMenuLink') - .click(); - - cy.get('[data-key="1"]') - .click(); - - cy.get('.card-body > .btn') - .click(); - - cy.wait(5000); - - cy.get('#movies_info') - .should('have.text', 'Showing 1 to 7 of 7 entries'); - }); - - it('Research Movies with bad chars', () => { - searchMoviesLibrary(cy); - - cy.get('#dropdownMenuLink') - .click(); - - cy.get('[data-key="1"]') - .click(); - - cy.get('.card-body > .btn') - .click(); - - cy.wait(5000); - - cy.get('#movies_info') - .should('have.text', 'Showing 1 to 7 of 7 entries'); - - cy.get('#movieContainer > [onclick="searchForMovies()"]') - .click(); - - cy.wait(5000); - - cy.get('#movies_info') - .should('have.text', 'Showing 1 to 7 of 7 entries'); - - cy.get(':nth-child(1) > td > .card > .row > .col-md > .card-body > h5.card-title') - .should('have.text', '2010 (1984)'); - }); -}); - -function searchMoviesLibrary(cy) { - cy.visit('/libraries', {onBeforeLoad: spyOnAddEventListener}); - - searchPlexForMoviesFromMovies(cy); - - cy.visit('/recommended', {onBeforeLoad: spyOnAddEventListener}); -} \ No newline at end of file diff --git a/cypress/integration/rss/rss.js b/cypress/integration/rss/rss.js index d6e535a..54aafa4 100644 --- a/cypress/integration/rss/rss.js +++ b/cypress/integration/rss/rss.js @@ -1,4 +1,4 @@ -import {nuke, redLibraryBefore, searchPlexForMovies, spyOnAddEventListener} from "../common"; +import {nuke, redLibraryBefore, searchPlexForMoviesFromSaw, spyOnAddEventListener} from "../common"; describe('Searched RSS', function () { before(nuke) @@ -27,7 +27,6 @@ describe('Searched RSS', function () { .then((resp) => { const result = resp.body; expect(result).to.have.lengthOf(7); - expect(result[0].imdb_id).to.eq('tt3348730') }); }) }); @@ -35,7 +34,7 @@ describe('Searched RSS', function () { function searchSawLibrary(cy) { cy.visit('/libraries', {onBeforeLoad: spyOnAddEventListener}); - searchPlexForMovies(cy); + searchPlexForMoviesFromSaw(cy); cy.visit('/recommended', {onBeforeLoad: spyOnAddEventListener}); }