diff options
-rw-r--r-- | .classpath | 20 | ||||
-rw-r--r-- | .project | 2 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | build.gradle | 44 | ||||
-rw-r--r-- | settings.gradle | 2 | ||||
-rw-r--r-- | test/eu/equalparts/cardbase/filtering/CardFilteringTest.java | 198 |
6 files changed, 244 insertions, 24 deletions
@@ -1,9 +1,21 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="src" path="src"/> - <classpathentry kind="src" path="res"/> - <classpathentry kind="src" path="test"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/> + <classpathentry kind="src" path="res"> + <attributes> + <attribute name="FROM_GRADLE_MODEL" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" path="src"> + <attributes> + <attribute name="FROM_GRADLE_MODEL" value="true"/> + </attributes> + </classpathentry> + <classpathentry kind="src" path="test"> + <attributes> + <attribute name="FROM_GRADLE_MODEL" value="true"/> + </attributes> + </classpathentry> <classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/> <classpathentry kind="output" path="bin"/> </classpath> @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <projectDescription> - <name>NewCardbase</name> + <name>Cardbase</name> <comment>Project Cardbase created by Buildship.</comment> <projects> </projects> @@ -61,4 +61,4 @@ Use the "version" command to see the executable's version. ## Building -Cardbase now uses [gradle](https://gradle.org/) for building and dependency management. As recommended, use the provided `gradlew` script for best results. +Cardbase now uses [gradle](https://gradle.org/) for building and dependency management. As recommended, use the provided `gradlew` script for best results. In addition to the standard Java tasks, `./gradlew standalone` can be used to generate a "fat jar" with all necessary dependencies bundled. diff --git a/build.gradle b/build.gradle index acc2489..ebe537e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ /* - * This build file was auto generated by running the Gradle 'init' task - * by 'eddy' at '20/08/16 10:27' with Gradle 3.0 + * This build file was auto generated by running the Gradle "init" task + * by "eddy" at "20/08/16 10:27" with Gradle 3.0 * * This generated file contains a sample Java project to get you started. * For more details take a look at the Java Quickstart chapter in the Gradle @@ -8,45 +8,61 @@ */ // Apply the java plugin to add support for Java -apply plugin: 'java' +apply plugin: "java" + +// variables +version = "1.0" // In this section you declare where to find the dependencies of your project repositories { - // Use 'jcenter' for resolving your dependencies. + // Use "jcenter" for resolving your dependencies. // You can declare any Maven/Ivy/file repository here. jcenter() } +// configure sourceSets for the alternative project directory structure sourceSets { main { java { - srcDirs = ['src'] + srcDirs = ["src"] } resources { - srcDirs = ['res'] + srcDirs = ["res"] } } test { java { - srcDirs = ['test'] + srcDirs = ["test"] } resources { - srcDirs = ['test'] + srcDirs = ["test"] } } } +//create a single jar with all dependencies +task standalone(type: Jar) { + manifest { + attributes("Implementation-Title": "Cardbase", + "Implementation-Version": version, + "Main-Class": "eu.equalparts.cardbase.cli.CardbaseCLI") + } + baseName = project.name + "-all" + from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } + with jar +} + // In this section you declare the dependencies for your production and test code dependencies { // Declare the dependency for your favourite test framework you want to use in your tests. // TestNG is also supported by the Gradle Test task. Just change the - // testCompile dependency to testCompile 'org.testng:testng:6.8.1' and add - // 'test.useTestNG()' to your build script. - testCompile 'junit:junit:4.12' + // testCompile dependency to testCompile "org.testng:testng:6.8.1" and add + // "test.useTestNG()" to your build script. + testCompile "junit:junit:4.12" // Need jackson for the JSON - compile 'com.fasterxml.jackson.core:jackson-core:2.8.1' - compile 'com.fasterxml.jackson.core:jackson-annotations:2.8.1' - compile 'com.fasterxml.jackson.core:jackson-databind:2.8.1' + compile "com.fasterxml.jackson.core:jackson-core:2.8.1" + compile "com.fasterxml.jackson.core:jackson-annotations:2.8.1" + compile "com.fasterxml.jackson.core:jackson-databind:2.8.1" } diff --git a/settings.gradle b/settings.gradle index 70d7a3d..d9116de 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,4 +16,4 @@ include 'api' include 'services:webservice' */ -rootProject.name = 'NewCardbase' +rootProject.name = 'Cardbase' diff --git a/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java b/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java index d4839a6..77377e6 100644 --- a/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java +++ b/test/eu/equalparts/cardbase/filtering/CardFilteringTest.java @@ -856,18 +856,210 @@ public class CardFilteringTest { } @Test - public void filterByMultiverseID() throws Exception { + public void filterByMultiverseIDEquals() throws Exception { + Filter filter = new Filter(FilterType.EQUALS, "multiverseid", "74489"); + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Callow Jushi", testCards.get(0).name.get()); + } + + @Test + public void filterByMultiverseIDContains() throws Exception { + Filter filter = new Filter(FilterType.CONTAINS, "multiverseid", "38"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 3, testCards.size()); + int i = 0; + String[] names = { + "Nightmare", + "Shivan Dragon", + "Sorin Markov", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByMultiverseIDRegex() throws Exception { + Filter filter = new Filter(FilterType.REGEX, "multiverseid", ".{5}"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 2, testCards.size()); + int i = 0; + String[] names = { + "Callow Jushi", + "Disrupting Shoal", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByMultiverseIDGreaterThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "multiverseid", "300000"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 4, testCards.size()); + int i = 0; + String[] names = { + "Coerced Confession", + "Nightmare", + "Shivan Dragon", + "Ugin's Construct", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByMultiverseIDSmallerThan() throws Exception { + Filter filter = new Filter(FilterType.SMALLER_THAN, "multiverseid", "10000"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 0, testCards.size()); + } + + @Test + public void filterByImageNameEquals() throws Exception { + Filter filter = new Filter(FilterType.EQUALS, "imageName", "nightmare"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Nightmare", testCards.get(0).name.get()); + } + + @Test + public void filterByImageNameContains() throws Exception { + Filter filter = new Filter(FilterType.CONTAINS, "imageName", "co"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 2, testCards.size()); + int i = 0; + String[] names = { + "Coerced Confession", + "Ugin's Construct", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByImageNameRegex() throws Exception { + Filter filter = new Filter(FilterType.REGEX, "imageName", ".+? .+?"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 7, testCards.size()); + int i = 0; + String[] names = { + "Callow Jushi", + "Coerced Confession", + "Khalni Hydra", + "Shivan Dragon", + "Disrupting Shoal", + "Sorin Markov", + "Ugin's Construct", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterByImageNameGreaterThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "imageName", "10"); + + exception.expect(IllegalArgumentException.class); + CardFiltering.filterByField(testCards, filter); + } + + @Test + public void filterByImageNameSmallerThan() throws Exception { + Filter filter = new Filter(FilterType.SMALLER_THAN, "imageName", "10"); + + exception.expect(IllegalArgumentException.class); + CardFiltering.filterByField(testCards, filter); + } + + @Test + public void filterBySetCodeEquals() throws Exception { + Filter filter = new Filter(FilterType.EQUALS, "setCode", "GTC"); + + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 1, testCards.size()); + assertEquals("Coerced Confession", testCards.get(0).name.get()); } @Test - public void filterByImageName() throws Exception { + public void filterBySetCodeContains() throws Exception { + Filter filter = new Filter(FilterType.CONTAINS, "setCode", "o"); + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 3, testCards.size()); + int i = 0; + String[] names = { + "Callow Jushi", + "Khalni Hydra", + "Disrupting Shoal", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } } @Test - public void filterBySetCode() throws Exception { + public void filterBySetCodeRegex() throws Exception { + Filter filter = new Filter(FilterType.REGEX, "setCode", "M[0-9]{2}"); + CardFiltering.filterByField(testCards, filter); + + assertEquals("Wrong list size.", 3, testCards.size()); + int i = 0; + String[] names = { + "Nightmare", + "Shivan Dragon", + "Sorin Markov", + }; + for (Card card : testCards) { + assertTrue(card.name.get() + " should have been " + names[i] + ", i = " + i, card.name.get().equals(names[i])); + i++; + } + } + + @Test + public void filterBySetCodeGreaterThan() throws Exception { + Filter filter = new Filter(FilterType.GREATER_THAN, "setCode", "10"); + + exception.expect(IllegalArgumentException.class); + CardFiltering.filterByField(testCards, filter); + } + + @Test + public void filterBySetCodeSmallerThan() throws Exception { + Filter filter = new Filter(FilterType.SMALLER_THAN, "setCode", "10"); + + exception.expect(IllegalArgumentException.class); + CardFiltering.filterByField(testCards, filter); } /* |