Skip to content

Commit

Permalink
Added more unit tests for WAction, tweaked gradle build file
Browse files Browse the repository at this point in the history
  • Loading branch information
fastily committed Mar 16, 2017
1 parent a68fd2f commit 413c9da
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 24 deletions.
10 changes: 2 additions & 8 deletions ToDo.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
* RevDel/File RevDel
* Watch list
* Search
* Account Creation?

### Usability
* Verify correct error values in QueryTests
* Code Coverage ?

* Optimizations for WQuery and MQuery.
* Fix Normalizations.
* dwrap should use serialization

* Better handling of meta queries
* May want to back color log with log4j

* mockhttpserver for unit tests.

* Could cached Wiki objects be keyed by HttpUrl?
* Could cached Wiki objects be keyed by HttpUrl?
* Fix purge()
30 changes: 15 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ compileJava {
targetCompatibility = "1.8"
}

task writeNewPom << {
pom {
project {
inceptionYear '2014'
licenses {
license {
name 'GNU General Public License, Version 3.0'
url 'https://www.gnu.org/licenses/gpl-3.0.txt'
distribution 'repo'
task writeNewPom {
doLast {
pom {
project {
inceptionYear '2014'
licenses {
license {
name 'GNU General Public License, Version 3.0'
url 'https://www.gnu.org/licenses/gpl-3.0.txt'
distribution 'repo'
}
}
}
}
}.writeTo("$buildDir/pom.xml")
} .writeTo("$buildDir/pom.xml")
}
}
//build.finalizedBy(writeNewPom)


task genJavadoc(type: Javadoc) {
source = sourceSets.main.allJava
Expand All @@ -62,8 +62,8 @@ dependencies {
api "com.google.code.gson:gson:2.8.0"
api "com.squareup.okhttp3:okhttp:3.6.0"

testCompile 'junit:junit:4.12'
testCompile 'com.squareup.okhttp3:mockwebserver:3.6.0'
testImplementation 'junit:junit:4.12'
testImplementation 'com.squareup.okhttp3:mockwebserver:3.6.0'
}

task wrapper(type: Wrapper) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fastily/jwiki/core/ApiClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected ApiClient(Wiki from, Wiki to)
*/
private Request.Builder startReq(HashMap<String, String> params)
{
HttpUrl.Builder hb = wiki.conf.baseURL.newBuilder(); //new HttpUrl.Builder().scheme("https").host(wiki.conf.domain).addPathSegments(wiki.conf.scptPath);
HttpUrl.Builder hb = wiki.conf.baseURL.newBuilder();
params.forEach(hb::addQueryParameter);

return new Request.Builder().addHeader("User-Agent", wiki.conf.userAgent).url(hb.build());
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/fastily/jwiki/test/ActionTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ public void testEdit()
assertTrue(wiki.edit("Wikipedia:Sandbox", "Hello, World!", "This is a test"));
}

/**
* Tests prepending and appending text via edit.
*/
@Test
public void testAddText()
{
addResponse("mockSuccessEdit");
addResponse("mockSuccessEdit");
assertTrue(wiki.addText("Wikipedia:Sandbox", "Appending text!", "test", true));
assertTrue(wiki.addText("Wikipedia:Sandbox", "Appending text!", "test", false));
}

/**
* Loads a MockResponse into the {@code server}'s queue.
*
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/fastily/jwiki/test/LoggedInActionTests.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package fastily.jwiki.test;


import static org.junit.Assert.*;

import org.junit.Test;

import fastily.jwiki.core.Wiki;

/**
Expand All @@ -23,4 +28,24 @@ protected void initWiki()

wiki = new Wiki("Test", "password", server.url("/w/api.php"));
}

/**
* Test privileged delete.
*/
@Test
public void testDelete()
{
addResponse("mockDeleteSuccess");
assertTrue(wiki.delete("Test", "Test Reason"));
}

/**
* Test privileged undelete.
*/
@Test
public void testUndelete()
{
addResponse("mockUndeleteSuccess");
assertTrue(wiki.undelete("Test", "test"));
}
}
7 changes: 7 additions & 0 deletions src/test/resources/fastily/jwiki/test/mockDeleteSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"delete": {
"title": "Test",
"reason": "Test Reason",
"logid": 12345
}
}
20 changes: 20 additions & 0 deletions src/test/resources/fastily/jwiki/test/mockMultiPurgeSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"batchcomplete": "",
"purge": [
{
"ns": 0,
"title": "Foo",
"purged": ""
},
{
"ns": 0,
"title": "Test",
"purged": ""
},
{
"ns": 4,
"title": "Wikipedia:Sandbox",
"purged": ""
}
]
}
10 changes: 10 additions & 0 deletions src/test/resources/fastily/jwiki/test/mockSinglePurgeSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"batchcomplete": "",
"purge": [
{
"ns": 3,
"title": "User:Test",
"purged": ""
}
]
}
8 changes: 8 additions & 0 deletions src/test/resources/fastily/jwiki/test/mockUndeleteSuccess.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"undelete": {
"title": "Test",
"revisions": 1,
"fileversions": 0,
"reason": "1 revision restored: test"
}
}

0 comments on commit 413c9da

Please sign in to comment.