From 2bbcdbda043a12bb69668a3af8e462e228d61816 Mon Sep 17 00:00:00 2001 From: Jason House Date: Tue, 23 Mar 2021 15:36:00 -0400 Subject: [PATCH] Adding mocked plex for testing --- .github/workflows/gaps-java-ci.yml | 2 +- .gitignore | 3 +- MockedPlex/pom.xml | 57 ++ .../mocked_plex/MockedPlexApplication.java | 48 ++ .../controller/MockedPlexController.java | 91 +++ .../src/main/resources/application.yaml | 17 + MockedPlex/src/main/resources/bestMovies.xml | 691 ++++++++++++++++++ MockedPlex/src/main/resources/newMetadata.xml | 592 +++++++++++++++ MockedPlex/src/main/resources/plex.xml | 42 ++ MockedPlex/src/main/resources/saw.xml | 31 + MockedPlex/src/main/resources/sections.xml | 46 ++ MockedPlex/src/test/resources/gaps-test.json | 74 ++ pom.xml | 1 + 13 files changed, 1693 insertions(+), 2 deletions(-) create mode 100755 MockedPlex/pom.xml create mode 100755 MockedPlex/src/main/java/com/jasonhhouse/mocked_plex/MockedPlexApplication.java create mode 100755 MockedPlex/src/main/java/com/jasonhhouse/mocked_plex/controller/MockedPlexController.java create mode 100755 MockedPlex/src/main/resources/application.yaml create mode 100644 MockedPlex/src/main/resources/bestMovies.xml create mode 100644 MockedPlex/src/main/resources/newMetadata.xml create mode 100644 MockedPlex/src/main/resources/plex.xml create mode 100644 MockedPlex/src/main/resources/saw.xml create mode 100644 MockedPlex/src/main/resources/sections.xml create mode 100644 MockedPlex/src/test/resources/gaps-test.json diff --git a/.github/workflows/gaps-java-ci.yml b/.github/workflows/gaps-java-ci.yml index 73310ec..aa972f8 100644 --- a/.github/workflows/gaps-java-ci.yml +++ b/.github/workflows/gaps-java-ci.yml @@ -5,7 +5,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - name: Use Node.js 15.x + - name: Use Node.js 12.x uses: actions/setup-node@v1 with: node-version: '12.x' diff --git a/.gitignore b/.gitignore index d2bae57..effc0f0 100755 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,7 @@ Core/target/ GapsWeb/target/ RadarrV3/target/ Plex/target/ +MockedPlex/target/ /rssFeed.json *.zip @@ -50,4 +51,4 @@ cypress/videos ### Ignore everything in Gaps on Windows except startup GapsAsJar/* !GapsAsJar/start.bat -!GapsAsJar/gaps.nsi +!GapsAsJar/gaps.nsi \ No newline at end of file diff --git a/MockedPlex/pom.xml b/MockedPlex/pom.xml new file mode 100755 index 0000000..bfdebd8 --- /dev/null +++ b/MockedPlex/pom.xml @@ -0,0 +1,57 @@ + + + + Gaps + com.jasonhhouse + 0.8.10 + + 4.0.0 + + MockedPlex + + + com.jasonhhouse.gaps.MockedPlex + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-devtools + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.jetbrains + annotations + + + + + \ No newline at end of file diff --git a/MockedPlex/src/main/java/com/jasonhhouse/mocked_plex/MockedPlexApplication.java b/MockedPlex/src/main/java/com/jasonhhouse/mocked_plex/MockedPlexApplication.java new file mode 100755 index 0000000..1d3e2c0 --- /dev/null +++ b/MockedPlex/src/main/java/com/jasonhhouse/mocked_plex/MockedPlexApplication.java @@ -0,0 +1,48 @@ +/* + * Copyright 2019 Jason H House + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.jasonhhouse.mocked_plex; + +import java.util.concurrent.Executor; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.domain.EntityScan; +import org.springframework.boot.context.properties.ConfigurationPropertiesScan; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.scheduling.annotation.EnableAsync; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; + +/** + * Mocked Plex Main Application for Testing + */ +@SpringBootApplication +@EntityScan("com.jasonhhouse") +@EnableAsync +@EnableConfigurationProperties +@ConfigurationPropertiesScan +public class MockedPlexApplication { + + public static void main(String[] args) { + SpringApplication.run(MockedPlexApplication.class, args); + } + + @Bean + public Executor taskExecutor() { + ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); + executor.setCorePoolSize(1); + executor.setMaxPoolSize(1); + executor.setQueueCapacity(50); + executor.setThreadNamePrefix("MockedPlex-"); + executor.initialize(); + return executor; + } + +} diff --git a/MockedPlex/src/main/java/com/jasonhhouse/mocked_plex/controller/MockedPlexController.java b/MockedPlex/src/main/java/com/jasonhhouse/mocked_plex/controller/MockedPlexController.java new file mode 100755 index 0000000..c975067 --- /dev/null +++ b/MockedPlex/src/main/java/com/jasonhhouse/mocked_plex/controller/MockedPlexController.java @@ -0,0 +1,91 @@ +/* + * Copyright 2020 Jason H House + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +package com.jasonhhouse.mocked_plex.controller; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStreamReader; +import java.nio.charset.StandardCharsets; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.util.ResourceUtils; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +public class MockedPlexController { + + private static final Logger LOGGER = LoggerFactory.getLogger(MockedPlexController.class); + + @GetMapping(path = "/", + produces = MediaType.APPLICATION_XML_VALUE) + public ResponseEntity getPlex(@RequestParam(value = "X-Plex-Token", required = false) final String xPlexToken) { + LOGGER.info("getPlex( {} )", xPlexToken); + return ResponseEntity.ok(getPlexXmlFile("plex.xml")); + } + + @GetMapping(path = "/library/sections", + produces = MediaType.APPLICATION_XML_VALUE) + public ResponseEntity getPlexLibrarySections(@RequestParam(value = "X-Plex-Token", required = false) final String xPlexToken) { + LOGGER.info("getPlex( {} )", xPlexToken); + return ResponseEntity.ok(getPlexXmlFile("sections.xml")); + } + + @GetMapping(path = "/library/sections/5/all", + produces = MediaType.APPLICATION_XML_VALUE) + public ResponseEntity getSaw(@RequestParam(value = "X-Plex-Token", required = false) final String xPlexToken) { + LOGGER.info("getPlex( {} )", xPlexToken); + return ResponseEntity.ok(getPlexXmlFile("saw.xml")); + } + + @GetMapping(path = "/library/sections/4/all", + produces = MediaType.APPLICATION_XML_VALUE) + public ResponseEntity getBestMovies(@RequestParam(value = "X-Plex-Token", required = false) final String xPlexToken) { + LOGGER.info("getPlex( {} )", xPlexToken); + return ResponseEntity.ok(getPlexXmlFile("bestMovies.xml")); + } + + @GetMapping(path = "/library/sections/6/all", + produces = MediaType.APPLICATION_XML_VALUE) + public ResponseEntity getNewMetadata(@RequestParam(value = "X-Plex-Token", required = false) final String xPlexToken) { + LOGGER.info("getPlex( {} )", xPlexToken); + return ResponseEntity.ok(getPlexXmlFile("newMetadata.xml")); + } + + private @NotNull String getPlexXmlFile(@NotNull String fileName) { + final File file; + try { + file = ResourceUtils.getFile("classpath:" + fileName); + + try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8))) { + StringBuilder fullFile = new StringBuilder(); + String line; + while ((line = br.readLine()) != null) { + fullFile.append(line); + } + + return fullFile.toString(); + } catch (IOException e) { + LOGGER.error(String.format("Failed to read file %s", fileName), e); + return ""; + } + } catch (FileNotFoundException e) { + LOGGER.error(String.format("Failed to find file %s", fileName), e); + return ""; + } + } +} diff --git a/MockedPlex/src/main/resources/application.yaml b/MockedPlex/src/main/resources/application.yaml new file mode 100755 index 0000000..fd46605 --- /dev/null +++ b/MockedPlex/src/main/resources/application.yaml @@ -0,0 +1,17 @@ +#Copyright 2019 Jason H House +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +# Maximum time the response should be cached (in seconds) +# The cache must re-validate stale resources with the server. Any expired resources must not be used without re-validating. +# The resources are public and any cache may store the response. + +logging: + level: + root: INFO +server: + port: 32400 \ No newline at end of file diff --git a/MockedPlex/src/main/resources/bestMovies.xml b/MockedPlex/src/main/resources/bestMovies.xml new file mode 100644 index 0000000..a228281 --- /dev/null +++ b/MockedPlex/src/main/resources/bestMovies.xml @@ -0,0 +1,691 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MockedPlex/src/main/resources/newMetadata.xml b/MockedPlex/src/main/resources/newMetadata.xml new file mode 100644 index 0000000..fc54e76 --- /dev/null +++ b/MockedPlex/src/main/resources/newMetadata.xml @@ -0,0 +1,592 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MockedPlex/src/main/resources/plex.xml b/MockedPlex/src/main/resources/plex.xml new file mode 100644 index 0000000..92f2fa6 --- /dev/null +++ b/MockedPlex/src/main/resources/plex.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/MockedPlex/src/main/resources/saw.xml b/MockedPlex/src/main/resources/saw.xml new file mode 100644 index 0000000..9fba7ef --- /dev/null +++ b/MockedPlex/src/main/resources/saw.xml @@ -0,0 +1,31 @@ + + + + diff --git a/MockedPlex/src/main/resources/sections.xml b/MockedPlex/src/main/resources/sections.xml new file mode 100644 index 0000000..094b2aa --- /dev/null +++ b/MockedPlex/src/main/resources/sections.xml @@ -0,0 +1,46 @@ + + + + + + + + + diff --git a/MockedPlex/src/test/resources/gaps-test.json b/MockedPlex/src/test/resources/gaps-test.json new file mode 100644 index 0000000..c266330 --- /dev/null +++ b/MockedPlex/src/test/resources/gaps-test.json @@ -0,0 +1,74 @@ +{ + "telegramProperties": { + "enabled": false, + "notificationTypes": [ + "TEST", + "PLEX_SERVER_CONNECTION" + ], + "botId": "", + "chatId": "" + }, + "pushBulletProperties": { + "enabled": false, + "notificationTypes": [ + "TEST", + "PLEX_SERVER_CONNECTION" + ], + "channel_tag": "", + "accessToken": "" + }, + "emailProperties": { + "enabled": false, + "notificationTypes": [ + "TEST", + "PLEX_SERVER_CONNECTION" + ], + "username": "", + "password": "", + "mailTo": "", + "mailFrom": "", + "mailServer": "", + "mailPort": 0, + "mailTransportProtocol": "", + "mailSmtpAuth": "", + "mailSmtpTlsEnabled": false + }, + "gotifyProperties": { + "enabled": false, + "notificationTypes": [ + "TEST", + "PLEX_SERVER_CONNECTION" + ], + "address": "", + "token": "" + }, + "slackProperties": { + "enabled": false, + "notificationTypes": [ + "TEST", + "PLEX_SERVER_CONNECTION" + ], + "webHookUrl": "" + }, + "pushOverProperties": { + "enabled": false, + "notificationTypes": [ + "TEST", + "PLEX_SERVER_CONNECTION" + ], + "token": "", + "user": "", + "priority": 1, + "sound": "", + "retry": 1, + "expire": 2 + }, + "discordProperties": { + "enabled": false, + "notificationTypes": [ + "TEST", + "PLEX_SERVER_CONNECTION" + ], + "webHookUrl": "" + } +} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6d04d65..e07916b 100755 --- a/pom.xml +++ b/pom.xml @@ -6,6 +6,7 @@ Core GapsWeb + MockedPlex Plex RadarrV3