JAMES-2096 Write integration test for Cassandra migration

Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/28855e75
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/28855e75
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/28855e75

Branch: refs/heads/master
Commit: 28855e75d091655416b141cbd9d29ed98bd1bb6d
Parents: 48043b4
Author: benwa <[email protected]>
Authored: Tue Jul 25 11:55:26 2017 +0700
Committer: benwa <[email protected]>
Committed: Tue Jul 25 17:51:18 2017 +0700

----------------------------------------------------------------------
 .../WebAdminServerIntegrationTest.java          | 67 ++++++++++++++++++++
 1 file changed, 67 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/28855e75/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
----------------------------------------------------------------------
diff --git 
a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
 
b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
index 59bf851..afd47d4 100644
--- 
a/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
+++ 
b/server/protocols/webadmin-integration-test/src/test/java/org/apache/james/webadmin/integration/WebAdminServerIntegrationTest.java
@@ -28,6 +28,7 @@ import static org.hamcrest.Matchers.is;
 
 import org.apache.james.CassandraJmapTestRule;
 import org.apache.james.GuiceJamesServer;
+import 
org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager;
 import org.apache.james.modules.MailboxProbeImpl;
 import org.apache.james.probe.DataProbe;
 import org.apache.james.utils.DataProbeImpl;
@@ -35,12 +36,16 @@ import org.apache.james.utils.WebAdminGuiceProbe;
 import org.apache.james.webadmin.routes.DomainRoutes;
 import org.apache.james.webadmin.routes.UserMailboxesRoutes;
 import org.apache.james.webadmin.routes.UserRoutes;
+import org.apache.james.webadmin.service.CassandraMigrationService;
+
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 
 import com.google.common.base.Charsets;
+import com.google.inject.AbstractModule;
+import com.google.inject.name.Names;
 import com.jayway.restassured.RestAssured;
 import com.jayway.restassured.builder.RequestSpecBuilder;
 import com.jayway.restassured.http.ContentType;
@@ -53,6 +58,10 @@ public class WebAdminServerIntegrationTest {
     public static final String SPECIFIC_USER = UserRoutes.USERS + SEPARATOR + 
USERNAME;
     public static final String MAILBOX = "mailbox";
     public static final String SPECIFIC_MAILBOX = SPECIFIC_USER + SEPARATOR + 
UserMailboxesRoutes.MAILBOXES + SEPARATOR + MAILBOX;
+    public static final String VERSION = "/cassandra/version";
+    public static final String VERSION_LATEST = VERSION + "/latest";
+    public static final String UPGRADE_VERSION = VERSION + "/upgrade";
+    public static final String UPGRADE_TO_LATEST_VERSION = UPGRADE_VERSION + 
"/latest";
 
     @Rule
     public CassandraJmapTestRule cassandraJmapTestRule = 
CassandraJmapTestRule.defaultTestRule();
@@ -183,4 +192,62 @@ public class WebAdminServerIntegrationTest {
         
assertThat(guiceJamesServer.getProbe(MailboxProbeImpl.class).listUserMailboxes(USERNAME)).isEmpty();
     }
 
+    @Test
+    public void 
getCurrentVersionShouldReturnNullForCurrentVersionAsBeginning() throws 
Exception {
+        given()
+            .port(webAdminGuiceProbe.getWebAdminPort())
+        .when()
+            .get(VERSION)
+        .then()
+            .statusCode(200)
+            .body(is("{\"version\":null}"));
+    }
+
+    @Test
+    public void getLatestVersionShouldReturnTheConfiguredLatestVersion() 
throws Exception {
+        given()
+            .port(webAdminGuiceProbe.getWebAdminPort())
+        .when()
+            .get(VERSION_LATEST)
+        .then()
+            .statusCode(200)
+            .body(is("{\"version\":" + 
CassandraSchemaVersionManager.MAX_VERSION + "}"));
+    }
+
+    @Test
+    public void postShouldDoMigrationAndUpdateCurrentVersion() throws 
Exception {
+        given()
+            .port(webAdminGuiceProbe.getWebAdminPort())
+            .body("2")
+        .when()
+            .post(UPGRADE_VERSION)
+        .then()
+            .statusCode(204);
+
+        given()
+            .port(webAdminGuiceProbe.getWebAdminPort())
+        .when()
+            .get(VERSION)
+        .then()
+            .statusCode(200)
+            .body(is("{\"version\":2}"));
+    }
+
+    @Test
+    public void postShouldDoMigrationAndUpdateToTheLatestVersion() throws 
Exception {
+        given()
+            .port(webAdminGuiceProbe.getWebAdminPort())
+        .when()
+            .post(UPGRADE_TO_LATEST_VERSION)
+        .then()
+            .statusCode(200);
+
+        given()
+            .port(webAdminGuiceProbe.getWebAdminPort())
+        .when()
+            .get(VERSION)
+        .then()
+            .statusCode(200)
+            .body(is("{\"version\":" + 
CassandraSchemaVersionManager.MAX_VERSION + "}"));
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to