mirror of
https://github.com/JasonHHouse/gaps.git
synced 2026-02-09 04:08:41 -06:00
added unit tests to movie
This commit is contained in:
@@ -42,5 +42,14 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.10.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
@@ -13,17 +13,38 @@ package com.jasonhhouse.gaps;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Handles the process of searching, movies, counts, and canceling
|
||||
*/
|
||||
public interface GapsSearch {
|
||||
|
||||
/**
|
||||
* Kicks of searching for all missing movies
|
||||
*/
|
||||
void run();
|
||||
|
||||
/**
|
||||
* @return The total count of movies to be searched
|
||||
*/
|
||||
@NotNull Integer getTotalMovieCount();
|
||||
|
||||
/**
|
||||
* @return The current count of movies searched
|
||||
*/
|
||||
@NotNull Integer getSearchedMovieCount();
|
||||
|
||||
/**
|
||||
* @return The movies that are missing from collections
|
||||
*/
|
||||
@NotNull CopyOnWriteArrayList<Movie> getRecommendedMovies();
|
||||
|
||||
/**
|
||||
* Cancel the current search
|
||||
*/
|
||||
void cancelSearch();
|
||||
|
||||
/**
|
||||
* @return Returns true if currently searching
|
||||
*/
|
||||
boolean isSearching();
|
||||
}
|
||||
@@ -13,11 +13,27 @@ package com.jasonhhouse.gaps;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Blackboard service interface for storing the PlexSearch object controllers
|
||||
*/
|
||||
public interface GapsService {
|
||||
|
||||
/**
|
||||
* @return Returns the PlexSearch instance as a singleton
|
||||
*/
|
||||
PlexSearch getPlexSearch();
|
||||
|
||||
/**
|
||||
* Updates PlexLibrary's to add them if not added and set them selected or unselected if added
|
||||
*
|
||||
* @param plexLibraries The libraries to add or update
|
||||
*/
|
||||
void updateLibrarySelections(@NotNull List<PlexLibrary> plexLibraries);
|
||||
|
||||
/**
|
||||
* Updates the plex search object itself to the singleton object
|
||||
*
|
||||
* @param plexSearch The object to copy into the plex search singleton
|
||||
*/
|
||||
void updatePlexSearch(PlexSearch plexSearch);
|
||||
}
|
||||
|
||||
@@ -13,8 +13,15 @@ package com.jasonhhouse.gaps;
|
||||
import java.util.List;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Interface to handle connecting to a Plex instance and returning the known movie libraries
|
||||
*/
|
||||
public interface PlexQuery {
|
||||
|
||||
/**
|
||||
* @param plexSearch Needs to have the IP Address, port, and plex token to connect
|
||||
* @return The list of libraries that are of type movie for that Plex server
|
||||
*/
|
||||
@NotNull List<PlexLibrary> getLibraries(@NotNull PlexSearch plexSearch);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.jasonhhouse.gaps.json;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonFactory;
|
||||
import com.fasterxml.jackson.core.JsonGenerator;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||
import com.jasonhhouse.gaps.Movie;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
public class MovieSerializerTest {
|
||||
|
||||
@Test
|
||||
void serializeAndDeserialize() throws Exception {
|
||||
MovieSerializer movieSerializer = new MovieSerializer();
|
||||
MovieDeserializer movieDeserializer = new MovieDeserializer();
|
||||
|
||||
Movie movie = new Movie.Builder("Alien", 1979)
|
||||
.setTvdbId(1345)
|
||||
.setCollection("Aliens Collection")
|
||||
.setCollectionId(5423)
|
||||
.setImdbId("IMDB ID")
|
||||
.setPosterUrl("POSTER URL")
|
||||
.build();
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
Writer jsonWriter = new StringWriter();
|
||||
JsonFactory factory = new JsonFactory();
|
||||
JsonGenerator jsonGenerator = factory.createGenerator(jsonWriter);
|
||||
SerializerProvider serializerProvider = objectMapper.getSerializerProvider();
|
||||
|
||||
movieSerializer.serialize(movie, jsonGenerator, serializerProvider);
|
||||
jsonGenerator.flush();
|
||||
|
||||
JsonParser jsonParser = factory.createParser(jsonWriter.toString());
|
||||
DeserializationContext deserializationContext = objectMapper.getDeserializationContext();
|
||||
jsonParser.setCodec(objectMapper);
|
||||
|
||||
Movie movie1 = movieDeserializer.deserialize(jsonParser, deserializationContext);
|
||||
assertEquals(movie1, movie, "Failed to serialize then deserialize a movie");
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,6 @@
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.5.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
/**
|
||||
* Using TMDB api (V3), get access to user list and add recommended movies to
|
||||
*/
|
||||
private @Nullable String getTmdbAuthorization() {
|
||||
/* private @Nullable String getTmdbAuthorization() {
|
||||
// Create the request_token request
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
@@ -286,7 +286,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
LOGGER.error("Unable to create session id: " + e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Using TMDB api (V3), get access to user list and add recommended movies to
|
||||
@@ -336,7 +336,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Connect to plex via the URL and parse all of the movies from the returned XML creating a HashSet of movies the
|
||||
* Connect to plex via the URL and parse all the movies from the returned XML creating a HashSet of movies the
|
||||
* user has.
|
||||
*/
|
||||
private void findAllPlexMovies() throws SearchCancelledException {
|
||||
@@ -358,7 +358,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
for (String url : urls) {
|
||||
//Cancel search if needed
|
||||
if (cancelSearch.get()) {
|
||||
throw new SearchCancelledException("Search was cancelled");
|
||||
throw new SearchCancelledException("Search cancelled");
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -813,7 +813,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
}
|
||||
|
||||
|
||||
public static class UserInputThreadCountdown implements Runnable {
|
||||
/* public static class UserInputThreadCountdown implements Runnable {
|
||||
|
||||
int time_limit = 60;
|
||||
|
||||
@@ -837,7 +837,7 @@ public class GapsSearchService implements GapsSearch {
|
||||
System.in.close();
|
||||
}
|
||||
|
||||
}
|
||||
}*/
|
||||
|
||||
private List<String> generatePlexUrls() {
|
||||
LOGGER.info(gapsService.getPlexSearch().getLibraries().toString());
|
||||
|
||||
8
pom.xml
8
pom.xml
@@ -55,6 +55,14 @@
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>17.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>5.5.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user