Cleaning up tests

This commit is contained in:
Jason House
2020-08-06 17:32:34 +09:00
parent f1e5851f59
commit 4e19bd3c6f
4 changed files with 104 additions and 122 deletions

View File

@@ -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<NotificationAgent> notificationAgents;
public NotificationService(List<NotificationAgent> 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");

View File

@@ -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() {

View File

@@ -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});
}

View File

@@ -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});
}