james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From btell...@apache.org
Subject [16/21] james-project git commit: JAMES-2272 Strong typing for Cassandra SchemaVersion
Date Thu, 04 Jan 2018 08:13:31 GMT
JAMES-2272 Strong typing for Cassandra SchemaVersion


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

Branch: refs/heads/master
Commit: 955afb0f21f9e52330d3c43e576384e9146e2c76
Parents: 7e95d7a
Author: benwa <btellier@linagora.com>
Authored: Wed Jan 3 14:33:13 2018 +0700
Committer: benwa <btellier@linagora.com>
Committed: Thu Jan 4 15:12:47 2018 +0700

----------------------------------------------------------------------
 .../migration/CassandraMigrationService.java    | 43 ++++++-----
 .../cassandra/migration/MigrationTask.java      | 17 +++--
 .../versions/CassandraSchemaVersionDAO.java     |  9 +--
 .../versions/CassandraSchemaVersionManager.java | 30 ++++----
 .../cassandra/versions/SchemaVersion.java       | 76 ++++++++++++++++++++
 .../CassandraMigrationServiceTest.java          | 27 +++----
 .../versions/CassandraSchemaVersionDAOTest.java |  8 +--
 .../CassandraSchemaVersionManagerTest.java      | 66 ++++-------------
 .../modules/mailbox/CassandraSessionModule.java | 12 ++--
 .../james/CassandraVersionCheckingTest.java     | 12 ++--
 .../modules/server/CassandraRoutesModule.java   | 13 ++--
 .../WebAdminServerIntegrationTest.java          |  8 +--
 .../webadmin/dto/CassandraVersionRequest.java   |  8 ++-
 .../webadmin/dto/CassandraVersionResponse.java  |  6 ++
 .../routes/CassandraMigrationRoutes.java        |  4 +-
 .../james/webadmin/dto/VersionRequestTest.java  | 31 ++++----
 .../routes/CassandraMigrationRoutesTest.java    | 19 ++---
 17 files changed, 217 insertions(+), 172 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/CassandraMigrationService.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/CassandraMigrationService.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/CassandraMigrationService.java
index 9c494e1..9ab1177 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/CassandraMigrationService.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/CassandraMigrationService.java
@@ -30,56 +30,55 @@ import javax.inject.Named;
 
 import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO;
+import org.apache.james.backends.cassandra.versions.SchemaVersion;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Preconditions;
-
 public class CassandraMigrationService {
     public static final String LATEST_VERSION = "latestVersion";
     private final CassandraSchemaVersionDAO schemaVersionDAO;
-    private final int latestVersion;
-    private final Map<Integer, Migration> allMigrationClazz;
+    private final SchemaVersion latestVersion;
+    private final Map<SchemaVersion, Migration> allMigrationClazz;
     private final Logger LOG = LoggerFactory.getLogger(CassandraMigrationService.class);
 
     @Inject
-    public CassandraMigrationService(CassandraSchemaVersionDAO schemaVersionDAO, Map<Integer, Migration> allMigrationClazz, @Named(LATEST_VERSION) int latestVersion) {
-        Preconditions.checkArgument(latestVersion >= 0, "The latest version must be positive");
+    public CassandraMigrationService(CassandraSchemaVersionDAO schemaVersionDAO, Map<SchemaVersion, Migration> allMigrationClazz, @Named(LATEST_VERSION) SchemaVersion latestVersion) {
         this.schemaVersionDAO = schemaVersionDAO;
         this.latestVersion = latestVersion;
         this.allMigrationClazz = allMigrationClazz;
     }
 
-    public Optional<Integer> getCurrentVersion() {
+    public Optional<SchemaVersion> getCurrentVersion() {
         return schemaVersionDAO.getCurrentSchemaVersion().join();
     }
 
-    public Optional<Integer> getLatestVersion() {
+    public Optional<SchemaVersion> getLatestVersion() {
         return Optional.of(latestVersion);
     }
 
-    public Migration upgradeToVersion(int newVersion) {
-        int currentVersion = getCurrentVersion().orElse(DEFAULT_VERSION);
+    public Migration upgradeToVersion(SchemaVersion newVersion) {
+        SchemaVersion currentVersion = getCurrentVersion().orElse(DEFAULT_VERSION);
         assertMigrationNeeded(newVersion, currentVersion);
 
-        Migration migrationCombination = IntStream.range(currentVersion, newVersion)
+        Migration migrationCombination = IntStream.range(currentVersion.getValue(), newVersion.getValue())
             .boxed()
+            .map(SchemaVersion::new)
             .map(this::validateVersionNumber)
             .map(this::toMigration)
             .reduce(Migration.IDENTITY, Migration::combine);
         return new MigrationTask(migrationCombination, newVersion);
     }
 
-    private void assertMigrationNeeded(int newVersion, int currentVersion) {
-        boolean needMigration = currentVersion < newVersion;
+    private void assertMigrationNeeded(SchemaVersion newVersion, SchemaVersion currentVersion) {
+        boolean needMigration = currentVersion.isBefore(newVersion);
         if (!needMigration) {
             throw new IllegalStateException("Current version is already up to date");
         }
     }
 
-    private Integer validateVersionNumber(Integer versionNumber) {
+    private SchemaVersion validateVersionNumber(SchemaVersion versionNumber) {
         if (!allMigrationClazz.containsKey(versionNumber)) {
-            String message = String.format("Can not migrate to %d. No migration class registered.", versionNumber);
+            String message = String.format("Can not migrate to %d. No migration class registered.", versionNumber.getValue());
             LOG.error(message);
             throw new NotImplementedException(message);
         }
@@ -90,11 +89,11 @@ public class CassandraMigrationService {
         return upgradeToVersion(latestVersion);
     }
 
-    private Migration toMigration(Integer version) {
+    private Migration toMigration(SchemaVersion version) {
         return () -> {
-            int newVersion = version + 1;
-            int currentVersion = getCurrentVersion().orElse(DEFAULT_VERSION);
-            if (currentVersion >= newVersion) {
+            SchemaVersion newVersion = version.next();
+            SchemaVersion currentVersion = getCurrentVersion().orElse(DEFAULT_VERSION);
+            if (currentVersion.isAfterOrEquals(newVersion)) {
                 return Migration.Result.PARTIAL;
             }
 
@@ -107,13 +106,13 @@ public class CassandraMigrationService {
         };
     }
 
-    private void throwMigrationException(int newVersion) {
+    private void throwMigrationException(SchemaVersion newVersion) {
         throw new MigrationException(failureMessage(newVersion));
     }
 
-    private String failureMessage(Integer newVersion) {
+    private String failureMessage(SchemaVersion newVersion) {
         return String.format("Migrating to version %d partially done. " +
-                "Please check logs for cause of failure and re-run this migration.", newVersion);
+                "Please check logs for cause of failure and re-run this migration.", newVersion.getValue());
     }
 
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/MigrationTask.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/MigrationTask.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/MigrationTask.java
index 518b682..7fd3bdd 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/MigrationTask.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/migration/MigrationTask.java
@@ -21,25 +21,28 @@ package org.apache.james.backends.cassandra.migration;
 
 import java.util.Optional;
 
+import org.apache.james.backends.cassandra.versions.SchemaVersion;
+import org.apache.james.task.TaskExecutionDetails;
+
 public class MigrationTask implements Migration {
     public static final String CASSANDRA_MIGRATION = "CassandraMigration";
 
-    public static class Details {
-        private final int toVersion;
+    public static class Details implements TaskExecutionDetails.AdditionalInformation {
+        private final SchemaVersion toVersion;
 
-        public Details(int toVersion) {
+        public Details(SchemaVersion toVersion) {
             this.toVersion = toVersion;
         }
 
         public int getToVersion() {
-            return toVersion;
+            return toVersion.getValue();
         }
     }
 
     private final Migration migration;
-    private final int toVersion;
+    private final SchemaVersion toVersion;
 
-    public MigrationTask(Migration migration, int toVersion) {
+    public MigrationTask(Migration migration, SchemaVersion toVersion) {
         this.migration = migration;
         this.toVersion = toVersion;
     }
@@ -55,7 +58,7 @@ public class MigrationTask implements Migration {
     }
 
     @Override
-    public Optional<Object> details() {
+    public Optional<TaskExecutionDetails.AdditionalInformation> details() {
         return Optional.of(new Details(toVersion));
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionDAO.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionDAO.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionDAO.java
index 83a16ba..23ca069 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionDAO.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionDAO.java
@@ -66,18 +66,19 @@ public class CassandraSchemaVersionDAO {
                 .value(VALUE, bindMarker(VALUE)));
     }
 
-    public CompletableFuture<Optional<Integer>> getCurrentSchemaVersion() {
+    public CompletableFuture<Optional<SchemaVersion>> getCurrentSchemaVersion() {
         return cassandraAsyncExecutor.execute(readVersionStatement.bind())
             .thenApply(resultSet -> cassandraUtils.convertToStream(resultSet)
                 .map(row -> row.getInt(VALUE))
-                .reduce(Math::max));
+                .reduce(Math::max))
+            .thenApply(i -> i.map(SchemaVersion::new));
     }
 
-    public CompletableFuture<Void> updateVersion(int newVersion) {
+    public CompletableFuture<Void> updateVersion(SchemaVersion newVersion) {
         return cassandraAsyncExecutor.executeVoid(
             writeVersionStatement.bind()
                 .setUUID(KEY, UUIDs.timeBased())
-                .setInt(VALUE, newVersion));
+                .setInt(VALUE, newVersion.getValue()));
     }
 }
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionManager.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionManager.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionManager.java
index 42502e8..40b4a7d 100644
--- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionManager.java
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionManager.java
@@ -33,14 +33,14 @@ import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 
 public class CassandraSchemaVersionManager {
-    public static final int MIN_VERSION = 2;
-    public static final int MAX_VERSION = 5;
-    public static final int DEFAULT_VERSION = 2;
+    public static final SchemaVersion MIN_VERSION = new SchemaVersion(2);
+    public static final SchemaVersion MAX_VERSION = new SchemaVersion(5);
+    public static final SchemaVersion DEFAULT_VERSION = MIN_VERSION;
 
     private static final Logger LOGGER = LoggerFactory.getLogger(CassandraSchemaVersionManager.class);
 
-    private final int minVersion;
-    private final int maxVersion;
+    private final SchemaVersion minVersion;
+    private final SchemaVersion maxVersion;
     private final CassandraSchemaVersionDAO schemaVersionDAO;
 
     public enum SchemaState {
@@ -56,10 +56,8 @@ public class CassandraSchemaVersionManager {
     }
 
     @VisibleForTesting
-    public CassandraSchemaVersionManager(CassandraSchemaVersionDAO schemaVersionDAO, int minVersion, int maxVersion) {
-        Preconditions.checkArgument(minVersion > 0, "minVersion needs to be strictly positive");
-        Preconditions.checkArgument(maxVersion > 0, "maxVersion needs to be strictly positive");
-        Preconditions.checkArgument(maxVersion >= minVersion,
+    public CassandraSchemaVersionManager(CassandraSchemaVersionDAO schemaVersionDAO, SchemaVersion minVersion, SchemaVersion maxVersion) {
+        Preconditions.checkArgument(maxVersion.isAfterOrEquals(minVersion),
             "maxVersion should not be inferior to minVersion");
 
         this.schemaVersionDAO = schemaVersionDAO;
@@ -67,7 +65,7 @@ public class CassandraSchemaVersionManager {
         this.maxVersion = maxVersion;
     }
 
-    public int computeVersion() {
+    public SchemaVersion computeVersion() {
         return schemaVersionDAO
             .getCurrentSchemaVersion()
             .join()
@@ -78,21 +76,21 @@ public class CassandraSchemaVersionManager {
             });
     }
 
-    public int getMinimumSupportedVersion() {
+    public SchemaVersion getMinimumSupportedVersion() {
         return minVersion;
     }
 
-    public int getMaximumSupportedVersion() {
+    public SchemaVersion getMaximumSupportedVersion() {
         return maxVersion;
     }
 
     public SchemaState computeSchemaState() {
-        int version = computeVersion();
-        if (version < minVersion) {
+        SchemaVersion version = computeVersion();
+        if (version.isBefore(minVersion)) {
             return TOO_OLD;
-        } else if (version < maxVersion) {
+        } else if (version.isBefore(maxVersion)) {
             return UPGRADABLE;
-        } else if (version == maxVersion) {
+        } else if (version.equals(maxVersion)) {
             return UP_TO_DATE;
         } else {
             return TOO_RECENT;

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/SchemaVersion.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/SchemaVersion.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/SchemaVersion.java
new file mode 100644
index 0000000..f1b3d41
--- /dev/null
+++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/versions/SchemaVersion.java
@@ -0,0 +1,76 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+package org.apache.james.backends.cassandra.versions;
+
+import java.util.Objects;
+
+import com.google.common.base.MoreObjects;
+import com.google.common.base.Preconditions;
+
+public class SchemaVersion {
+    private final int value;
+
+    public SchemaVersion(int value) {
+        Preconditions.checkArgument(value > 0, "version needs to be strictly positive");
+        this.value = value;
+    }
+
+    public int getValue() {
+        return value;
+    }
+
+    public boolean isAfterOrEquals(SchemaVersion other) {
+        return this.value >= other.value;
+    }
+
+    public SchemaVersion next() {
+        return new SchemaVersion(value + 1);
+    }
+
+    public SchemaVersion previous() {
+        return new SchemaVersion(value - 1);
+    }
+
+    public boolean isBefore(SchemaVersion other) {
+        return this.value < other.value;
+    }
+
+    @Override
+    public final boolean equals(Object o) {
+        if (o instanceof SchemaVersion) {
+            SchemaVersion that = (SchemaVersion) o;
+
+            return Objects.equals(this.value, that.value);
+        }
+        return false;
+    }
+
+    @Override
+    public final int hashCode() {
+        return Objects.hash(value);
+    }
+
+    @Override
+    public String toString() {
+        return MoreObjects.toStringHelper(this)
+            .add("version", value)
+            .toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/CassandraMigrationServiceTest.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/CassandraMigrationServiceTest.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/CassandraMigrationServiceTest.java
index 5dea96b..4897800 100644
--- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/CassandraMigrationServiceTest.java
+++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/migration/CassandraMigrationServiceTest.java
@@ -36,6 +36,7 @@ import java.util.concurrent.Executors;
 
 import org.apache.commons.lang.NotImplementedException;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO;
+import org.apache.james.backends.cassandra.versions.SchemaVersion;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Rule;
@@ -46,10 +47,10 @@ import com.datastax.driver.core.Session;
 import com.google.common.collect.ImmutableMap;
 
 public class CassandraMigrationServiceTest {
-    private static final int LATEST_VERSION = 3;
-    private static final int INTERMEDIARY_VERSION = 2;
-    private static final int CURRENT_VERSION = INTERMEDIARY_VERSION;
-    private static final int OLDER_VERSION = 1;
+    private static final SchemaVersion LATEST_VERSION = new SchemaVersion(3);
+    private static final SchemaVersion INTERMEDIARY_VERSION = new SchemaVersion(2);
+    private static final SchemaVersion CURRENT_VERSION = INTERMEDIARY_VERSION;
+    private static final SchemaVersion OLDER_VERSION = new SchemaVersion(1);
     private CassandraMigrationService testee;
     private CassandraSchemaVersionDAO schemaVersionDAO;
     private ExecutorService executorService;
@@ -63,7 +64,7 @@ public class CassandraMigrationServiceTest {
         schemaVersionDAO = mock(CassandraSchemaVersionDAO.class);
         successfulMigration = mock(Migration.class);
         when(successfulMigration.run()).thenReturn(Migration.Result.COMPLETED);
-        Map<Integer, Migration> allMigrationClazz = ImmutableMap.<Integer, Migration>builder()
+        Map<SchemaVersion, Migration> allMigrationClazz = ImmutableMap.<SchemaVersion, Migration>builder()
             .put(OLDER_VERSION, successfulMigration)
             .put(CURRENT_VERSION, successfulMigration)
             .put(LATEST_VERSION, successfulMigration)
@@ -127,7 +128,7 @@ public class CassandraMigrationServiceTest {
 
     @Test
     public void upgradeToVersionShouldThrowOnMissingVersion() throws Exception {
-        Map<Integer, Migration> allMigrationClazz = ImmutableMap.<Integer, Migration>builder()
+        Map<SchemaVersion, Migration> allMigrationClazz = ImmutableMap.<SchemaVersion, Migration>builder()
             .put(OLDER_VERSION, successfulMigration)
             .put(LATEST_VERSION, successfulMigration)
             .build();
@@ -142,7 +143,7 @@ public class CassandraMigrationServiceTest {
     @Test
     public void upgradeToVersionShouldUpdateIntermediarySuccessfulMigrationsInCaseOfError() throws Exception {
         try {
-            Map<Integer, Migration> allMigrationClazz = ImmutableMap.<Integer, Migration>builder()
+            Map<SchemaVersion, Migration> allMigrationClazz = ImmutableMap.<SchemaVersion, Migration>builder()
                 .put(OLDER_VERSION, successfulMigration)
                 .put(INTERMEDIARY_VERSION, () -> Migration.Result.PARTIAL)
                 .put(LATEST_VERSION, successfulMigration)
@@ -164,7 +165,7 @@ public class CassandraMigrationServiceTest {
         when(migration1.run()).thenReturn(Migration.Result.PARTIAL);
         Migration migration2 = successfulMigration;
 
-        Map<Integer, Migration> allMigrationClazz = ImmutableMap.<Integer, Migration>builder()
+        Map<SchemaVersion, Migration> allMigrationClazz = ImmutableMap.<SchemaVersion, Migration>builder()
             .put(OLDER_VERSION, migration1)
             .put(CURRENT_VERSION, migration2)
             .build();
@@ -182,7 +183,7 @@ public class CassandraMigrationServiceTest {
         Migration migration2 = mock(Migration.class);
         when(migration2.run()).thenReturn(Migration.Result.COMPLETED);
 
-        Map<Integer, Migration> allMigrationClazz = ImmutableMap.<Integer, Migration>builder()
+        Map<SchemaVersion, Migration> allMigrationClazz = ImmutableMap.<SchemaVersion, Migration>builder()
             .put(OLDER_VERSION, migration1)
             .put(CURRENT_VERSION, migration2)
             .build();
@@ -200,20 +201,20 @@ public class CassandraMigrationServiceTest {
     }
 
     public static class InMemorySchemaDAO extends CassandraSchemaVersionDAO {
-        private int currentVersion;
+        private SchemaVersion currentVersion;
 
-        public InMemorySchemaDAO(int currentVersion) {
+        public InMemorySchemaDAO(SchemaVersion currentVersion) {
             super(mock(Session.class), null);
             this.currentVersion = currentVersion;
         }
 
         @Override
-        public CompletableFuture<Optional<Integer>> getCurrentSchemaVersion() {
+        public CompletableFuture<Optional<SchemaVersion>> getCurrentSchemaVersion() {
             return CompletableFuture.completedFuture(Optional.of(currentVersion));
         }
 
         @Override
-        public CompletableFuture<Void> updateVersion(int newVersion) {
+        public CompletableFuture<Void> updateVersion(SchemaVersion newVersion) {
             currentVersion = newVersion;
             return CompletableFuture.completedFuture(null);
         }

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionDAOTest.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionDAOTest.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionDAOTest.java
index 5e61068..5bd83b5 100644
--- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionDAOTest.java
+++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionDAOTest.java
@@ -59,7 +59,7 @@ public class CassandraSchemaVersionDAOTest {
 
     @Test
     public void getCurrentSchemaVersionShouldReturnVersionPresentInTheTable() {
-        int version = 42;
+        SchemaVersion version = new SchemaVersion(42);
 
         testee.updateVersion(version).join();
 
@@ -68,11 +68,11 @@ public class CassandraSchemaVersionDAOTest {
 
     @Test
     public void getCurrentSchemaVersionShouldBeIdempotent() {
-        int version = 42;
+        SchemaVersion version = new SchemaVersion(42);
 
-        testee.updateVersion(version + 1).join();
+        testee.updateVersion(version.next()).join();
         testee.updateVersion(version).join();
 
-        assertThat(testee.getCurrentSchemaVersion().join()).contains(version + 1);
+        assertThat(testee.getCurrentSchemaVersion().join()).contains(version.next());
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionManagerTest.java
----------------------------------------------------------------------
diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionManagerTest.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionManagerTest.java
index 708c492..dfffddc 100644
--- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionManagerTest.java
+++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/versions/CassandraSchemaVersionManagerTest.java
@@ -19,10 +19,10 @@
 
 package org.apache.james.backends.cassandra.versions;
 
-import static org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager.SchemaState.UP_TO_DATE;
-import static org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager.SchemaState.UPGRADABLE;
 import static org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager.SchemaState.TOO_OLD;
 import static org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager.SchemaState.TOO_RECENT;
+import static org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager.SchemaState.UPGRADABLE;
+import static org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager.SchemaState.UP_TO_DATE;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -38,8 +38,8 @@ import org.junit.rules.ExpectedException;
 
 public class CassandraSchemaVersionManagerTest {
 
-    private final int minVersion = 2;
-    private final int maxVersion = 4;
+    private final SchemaVersion minVersion = new SchemaVersion(2);
+    private final SchemaVersion maxVersion = new SchemaVersion(4);
     private CassandraSchemaVersionDAO schemaVersionDAO;
 
     @Rule
@@ -52,7 +52,7 @@ public class CassandraSchemaVersionManagerTest {
 
     @Test
     public void computeSchemaStateShouldReturnTooOldWhenVersionIsLessThanMinVersion() {
-        int currentVersion = minVersion - 1;
+        SchemaVersion currentVersion = minVersion.previous();
 
         when(schemaVersionDAO.getCurrentSchemaVersion())
             .thenReturn(CompletableFuture.completedFuture(Optional.of(currentVersion)));
@@ -67,7 +67,7 @@ public class CassandraSchemaVersionManagerTest {
 
     @Test
     public void computeSchemaStateShouldReturnTooOldWhenVersionIsMoreThanMaxVersion() {
-        int currentVersion = maxVersion + 1;
+        SchemaVersion currentVersion = maxVersion.next();
 
         when(schemaVersionDAO.getCurrentSchemaVersion())
             .thenReturn(CompletableFuture.completedFuture(Optional.of(currentVersion)));
@@ -82,7 +82,7 @@ public class CassandraSchemaVersionManagerTest {
 
     @Test
     public void computeSchemaStateShouldReturnUpToDateWhenVersionEqualsMaxVersion() {
-        int currentVersion = maxVersion;
+        SchemaVersion currentVersion = maxVersion;
 
         when(schemaVersionDAO.getCurrentSchemaVersion())
             .thenReturn(CompletableFuture.completedFuture(Optional.of(currentVersion)));
@@ -97,7 +97,7 @@ public class CassandraSchemaVersionManagerTest {
 
     @Test
     public void computeSchemaStateShouldReturnUpgradableWhenVersionBetweenMinAnd() {
-        int currentVersion = maxVersion - 1;
+        SchemaVersion currentVersion = minVersion.next();
 
         when(schemaVersionDAO.getCurrentSchemaVersion())
             .thenReturn(CompletableFuture.completedFuture(Optional.of(currentVersion)));
@@ -111,51 +111,11 @@ public class CassandraSchemaVersionManagerTest {
     }
 
     @Test
-    public void constructorShouldThrowOnNegativeMinVersion() {
-        expectedException.expect(IllegalArgumentException.class);
-
-        new CassandraSchemaVersionManager(
-            schemaVersionDAO,
-            -1,
-            maxVersion);
-    }
-
-    @Test
-    public void constructorShouldThrowOnZeroMinVersion() {
-        expectedException.expect(IllegalArgumentException.class);
-
-        new CassandraSchemaVersionManager(
-            schemaVersionDAO,
-            0,
-            maxVersion);
-    }
-
-    @Test
-    public void constructorShouldThrowOnNegativeMaxVersion() {
-        expectedException.expect(IllegalArgumentException.class);
-
-        new CassandraSchemaVersionManager(
-            schemaVersionDAO,
-            minVersion,
-            -1);
-    }
-
-    @Test
-    public void constructorShouldThrowOnZeroMaxVersion() {
-        expectedException.expect(IllegalArgumentException.class);
-
-        new CassandraSchemaVersionManager(
-            schemaVersionDAO,
-            minVersion,
-            0);
-    }
-
-    @Test
     public void constructorShouldThrowMinVersionIsSuperiorToMaxVersion() {
         expectedException.expect(IllegalArgumentException.class);
 
-        int minVersion = 4;
-        int maxVersion = 2;
+        SchemaVersion minVersion = new SchemaVersion(4);
+        SchemaVersion maxVersion = new SchemaVersion(2);
         new CassandraSchemaVersionManager(
             schemaVersionDAO,
             minVersion,
@@ -164,9 +124,9 @@ public class CassandraSchemaVersionManagerTest {
 
     @Test
     public void computeSchemaStateShouldReturnUpToDateWhenMinMaxAndVersionEquals() {
-        int minVersion = 4;
-        int maxVersion = 4;
-        int currentVersion = 4;
+        SchemaVersion minVersion = new SchemaVersion(4);
+        SchemaVersion maxVersion = new SchemaVersion(4);
+        SchemaVersion currentVersion = new SchemaVersion(4);
         when(schemaVersionDAO.getCurrentSchemaVersion())
             .thenReturn(CompletableFuture.completedFuture(Optional.of(currentVersion)));
 

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
index 31a856b..84a33db 100644
--- a/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
+++ b/server/container/guice/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java
@@ -192,13 +192,17 @@ public class CassandraSessionModule extends AbstractModule {
                 case TOO_OLD:
                     throw new IllegalStateException(
                         String.format("Current schema version is %d whereas minimum required version is %d. " +
-                            "Recommended version is %d", versionManager.computeVersion(), versionManager.getMinimumSupportedVersion(),
-                            versionManager.getMaximumSupportedVersion()));
+                            "Recommended version is %d",
+                            versionManager.computeVersion().getValue(),
+                            versionManager.getMinimumSupportedVersion().getValue(),
+                            versionManager.getMaximumSupportedVersion().getValue()));
                 case TOO_RECENT:
                     throw new IllegalStateException(
                         String.format("Current schema version is %d whereas the minimum supported version is %d. " +
-                            "Recommended version is %d.", versionManager.computeVersion(), versionManager.getMinimumSupportedVersion(),
-                            versionManager.getMaximumSupportedVersion()));
+                            "Recommended version is %d.",
+                            versionManager.computeVersion().getValue(),
+                            versionManager.getMinimumSupportedVersion().getValue(),
+                            versionManager.getMaximumSupportedVersion().getValue()));
                 case UP_TO_DATE:
                     LOGGER.info("Schema version is up-to-date");
                     return;

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
----------------------------------------------------------------------
diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
index 9e71aa6..4544587 100644
--- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
+++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraVersionCheckingTest.java
@@ -32,6 +32,7 @@ import java.util.concurrent.CompletableFuture;
 
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager;
+import org.apache.james.backends.cassandra.versions.SchemaVersion;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.ClassRule;
@@ -43,9 +44,8 @@ public class CassandraVersionCheckingTest {
 
     private static final String LOCAL_HOST = "127.0.0.1";
     private static final int IMAP_PORT = 1143;
-    private static final int MIN_VERSION = 2;
-    private static final int MAX_VERSION = 4;
-
+    private static final SchemaVersion MIN_VERSION = new SchemaVersion(2);
+    private static final SchemaVersion MAX_VERSION = new SchemaVersion(4);
 
     @ClassRule
     public static DockerCassandraRule cassandra = new DockerCassandraRule();
@@ -92,7 +92,7 @@ public class CassandraVersionCheckingTest {
     @Test
     public void serverShouldStartSuccessfullyWhenBetweenMinAndMaxVersion() throws Exception {
         when(versionDAO.getCurrentSchemaVersion())
-            .thenReturn(CompletableFuture.completedFuture(Optional.of(MIN_VERSION + 1)));
+            .thenReturn(CompletableFuture.completedFuture(Optional.of(MIN_VERSION.next())));
 
         jamesServer = cassandraJmapTestRule.jmapServer(
             cassandra.getModule(),
@@ -122,7 +122,7 @@ public class CassandraVersionCheckingTest {
     @Test
     public void serverShouldNotStartWhenUnderMinVersion() throws Exception {
         when(versionDAO.getCurrentSchemaVersion())
-            .thenReturn(CompletableFuture.completedFuture(Optional.of(MIN_VERSION - 1)));
+            .thenReturn(CompletableFuture.completedFuture(Optional.of(MIN_VERSION.previous())));
 
         jamesServer = cassandraJmapTestRule.jmapServer(
             cassandra.getModule(),
@@ -139,7 +139,7 @@ public class CassandraVersionCheckingTest {
     @Test
     public void serverShouldNotStartWhenAboveMaxVersion() throws Exception {
         when(versionDAO.getCurrentSchemaVersion())
-            .thenReturn(CompletableFuture.completedFuture(Optional.of(MAX_VERSION + 1)));
+            .thenReturn(CompletableFuture.completedFuture(Optional.of(MAX_VERSION.next())));
 
         jamesServer = cassandraJmapTestRule.jmapServer(
             cassandra.getModule(),

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/server/container/guice/protocols/webadmin-cassandra/src/main/java/org/apache/james/modules/server/CassandraRoutesModule.java
----------------------------------------------------------------------
diff --git a/server/container/guice/protocols/webadmin-cassandra/src/main/java/org/apache/james/modules/server/CassandraRoutesModule.java b/server/container/guice/protocols/webadmin-cassandra/src/main/java/org/apache/james/modules/server/CassandraRoutesModule.java
index 16b821b..1cf1f93 100644
--- a/server/container/guice/protocols/webadmin-cassandra/src/main/java/org/apache/james/modules/server/CassandraRoutesModule.java
+++ b/server/container/guice/protocols/webadmin-cassandra/src/main/java/org/apache/james/modules/server/CassandraRoutesModule.java
@@ -22,6 +22,7 @@ package org.apache.james.modules.server;
 import org.apache.james.backends.cassandra.migration.CassandraMigrationService;
 import org.apache.james.backends.cassandra.migration.Migration;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionManager;
+import org.apache.james.backends.cassandra.versions.SchemaVersion;
 import org.apache.james.mailbox.cassandra.mail.migration.AttachmentMessageIdCreation;
 import org.apache.james.mailbox.cassandra.mail.migration.AttachmentV2Migration;
 import org.apache.james.webadmin.Routes;
@@ -34,9 +35,9 @@ import com.google.inject.multibindings.Multibinder;
 import com.google.inject.name.Names;
 
 public class CassandraRoutesModule extends AbstractModule {
-    private static final int FROM_V2_TO_V3 = 2;
-    private static final int FROM_V3_TO_V4 = 3;
-    private static final int FROM_V4_TO_V5 = 4;
+    private static final SchemaVersion FROM_V2_TO_V3 = new SchemaVersion(2);
+    private static final SchemaVersion FROM_V3_TO_V4 = new SchemaVersion(3);
+    private static final SchemaVersion FROM_V4_TO_V5 = new SchemaVersion(4);
 
     @Override
     protected void configure() {
@@ -46,13 +47,13 @@ public class CassandraRoutesModule extends AbstractModule {
         Multibinder<Routes> routesMultibinder = Multibinder.newSetBinder(binder(), Routes.class);
         routesMultibinder.addBinding().to(CassandraMigrationRoutes.class);
 
-        MapBinder<Integer, Migration> allMigrationClazzBinder = MapBinder.newMapBinder(binder(), Integer.class, Migration.class);
+        MapBinder<SchemaVersion, Migration> allMigrationClazzBinder = MapBinder.newMapBinder(binder(), SchemaVersion.class, Migration.class);
         allMigrationClazzBinder.addBinding(FROM_V2_TO_V3).toInstance(() -> Migration.Result.COMPLETED);
         allMigrationClazzBinder.addBinding(FROM_V3_TO_V4).to(AttachmentV2Migration.class);
         allMigrationClazzBinder.addBinding(FROM_V4_TO_V5).to(AttachmentMessageIdCreation.class);
 
-        bindConstant()
+        bind(SchemaVersion.class)
             .annotatedWith(Names.named(CassandraMigrationService.LATEST_VERSION))
-            .to(CassandraSchemaVersionManager.MAX_VERSION);
+            .toInstance(CassandraSchemaVersionManager.MAX_VERSION);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/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 981fbf5..fee4465 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
@@ -227,14 +227,14 @@ public class WebAdminServerIntegrationTest {
         .then()
             .statusCode(HttpStatus.OK_200)
             .contentType(JSON_CONTENT_TYPE)
-            .body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION + "}"));
+            .body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION.getValue() + "}"));
     }
 
     @Test
     public void postShouldDoMigrationAndUpdateCurrentVersion() throws Exception {
         String taskId = with()
             .port(webAdminGuiceProbe.getWebAdminPort())
-            .body(String.valueOf(CassandraSchemaVersionManager.MAX_VERSION))
+            .body(String.valueOf(CassandraSchemaVersionManager.MAX_VERSION.getValue()))
         .post(UPGRADE_VERSION)
             .jsonPath()
             .get("taskId");
@@ -250,7 +250,7 @@ public class WebAdminServerIntegrationTest {
         .then()
             .statusCode(HttpStatus.OK_200)
             .contentType(JSON_CONTENT_TYPE)
-            .body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION + "}"));
+            .body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION.getValue() + "}"));
     }
 
     @Test
@@ -272,7 +272,7 @@ public class WebAdminServerIntegrationTest {
         .then()
             .statusCode(HttpStatus.OK_200)
             .contentType(JSON_CONTENT_TYPE)
-            .body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION + "}"));
+            .body(is("{\"version\":" + CassandraSchemaVersionManager.MAX_VERSION.getValue() + "}"));
     }
 
     @Test

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/CassandraVersionRequest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/CassandraVersionRequest.java b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/CassandraVersionRequest.java
index 5eaef46..73e4ca5 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/CassandraVersionRequest.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/CassandraVersionRequest.java
@@ -19,6 +19,8 @@
 
 package org.apache.james.webadmin.dto;
 
+import org.apache.james.backends.cassandra.versions.SchemaVersion;
+
 import com.google.common.base.Preconditions;
 
 public class CassandraVersionRequest {
@@ -30,11 +32,11 @@ public class CassandraVersionRequest {
     private final int value;
 
     private CassandraVersionRequest(int value) {
-        Preconditions.checkArgument(value >= 0);
+        Preconditions.checkArgument(value > 0);
         this.value = value;
     }
 
-    public int getValue() {
-        return value;
+    public SchemaVersion getValue() {
+        return new SchemaVersion(value);
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/CassandraVersionResponse.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/CassandraVersionResponse.java b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/CassandraVersionResponse.java
index 34e98a8..cc07c7c 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/CassandraVersionResponse.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/dto/CassandraVersionResponse.java
@@ -21,8 +21,14 @@ package org.apache.james.webadmin.dto;
 
 import java.util.Optional;
 
+import org.apache.james.backends.cassandra.versions.SchemaVersion;
+
 public class CassandraVersionResponse {
 
+    public static CassandraVersionResponse from(Optional<SchemaVersion> schemaVersion) {
+        return new CassandraVersionResponse(schemaVersion.map(SchemaVersion::getValue));
+    }
+
     private final Optional<Integer> version;
 
     public CassandraVersionResponse(Optional<Integer> version) {

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
index 4ae87ed..d30b9c5 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/main/java/org/apache/james/webadmin/routes/CassandraMigrationRoutes.java
@@ -167,7 +167,7 @@ public class CassandraMigrationRoutes implements Routes {
         @ApiResponse(code = HttpStatus.OK_200, message = "The latest version of the schema", response = CassandraVersionResponse.class)
     })
     public CassandraVersionResponse getCassandraLatestVersion() {
-        return new CassandraVersionResponse(cassandraMigrationService.getLatestVersion());
+        return CassandraVersionResponse.from(cassandraMigrationService.getLatestVersion());
     }
 
     @GET
@@ -176,6 +176,6 @@ public class CassandraMigrationRoutes implements Routes {
         @ApiResponse(code = HttpStatus.OK_200, message = "The current version of the schema", response = CassandraVersionResponse.class)
     })
     public CassandraVersionResponse getCassandraCurrentVersion() {
-        return new CassandraVersionResponse(cassandraMigrationService.getCurrentVersion());
+        return CassandraVersionResponse.from(cassandraMigrationService.getCurrentVersion());
     }
 }

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/dto/VersionRequestTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/dto/VersionRequestTest.java b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/dto/VersionRequestTest.java
index 48ce134..228120b 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/dto/VersionRequestTest.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/dto/VersionRequestTest.java
@@ -20,48 +20,41 @@
 package org.apache.james.webadmin.dto;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
 
-import org.junit.Rule;
+import org.apache.james.backends.cassandra.versions.SchemaVersion;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 
 public class VersionRequestTest {
-    @Rule
-    public ExpectedException expectedException = ExpectedException.none();
-
     @Test
     public void parseShouldThrowWhenNullVersion() throws Exception {
-        expectedException.expect(NullPointerException.class);
-
-        CassandraVersionRequest.parse(null);
+        assertThatThrownBy(() -> CassandraVersionRequest.parse(null))
+            .isInstanceOf(NullPointerException.class);
     }
 
     @Test
     public void parseShouldThrowWhenNonIntegerVersion() throws Exception {
-        expectedException.expect(IllegalArgumentException.class);
-
-        CassandraVersionRequest.parse("NoInt");
+        assertThatThrownBy(() -> CassandraVersionRequest.parse("NoInt"))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
     public void parseShouldThrowWhenNegativeVersion() throws Exception {
-        expectedException.expect(IllegalArgumentException.class);
-
-        CassandraVersionRequest.parse("-1");
+        assertThatThrownBy(() -> CassandraVersionRequest.parse("-1"))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
-    public void parseShouldAcceptZeroVersion() throws Exception {
-        CassandraVersionRequest cassandraVersionRequest = CassandraVersionRequest.parse("0");
-
-        assertThat(cassandraVersionRequest.getValue()).isEqualTo(0);
+    public void parseShouldThrowWhenZeroVersion() throws Exception {
+        assertThatThrownBy(() -> CassandraVersionRequest.parse("0"))
+            .isInstanceOf(IllegalArgumentException.class);
     }
 
     @Test
     public void parseShouldParseTheVersionValue() throws Exception {
         CassandraVersionRequest cassandraVersionRequest = CassandraVersionRequest.parse("1");
 
-        assertThat(cassandraVersionRequest.getValue()).isEqualTo(1);
+        assertThat(cassandraVersionRequest.getValue()).isEqualTo(new SchemaVersion(1));
     }
 
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/james-project/blob/955afb0f/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
----------------------------------------------------------------------
diff --git a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
index 0cc9d9c..1372c9b 100644
--- a/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
+++ b/server/protocols/webadmin/webadmin-cassandra/src/test/java/org/apache/james/webadmin/routes/CassandraMigrationRoutesTest.java
@@ -44,6 +44,7 @@ import org.apache.james.backends.cassandra.migration.CassandraMigrationService;
 import org.apache.james.backends.cassandra.migration.Migration;
 import org.apache.james.backends.cassandra.migration.MigrationTask;
 import org.apache.james.backends.cassandra.versions.CassandraSchemaVersionDAO;
+import org.apache.james.backends.cassandra.versions.SchemaVersion;
 import org.apache.james.metrics.logger.DefaultMetricFactory;
 import org.apache.james.task.MemoryTaskManager;
 import org.apache.james.webadmin.WebAdminServer;
@@ -61,9 +62,9 @@ import com.jayway.restassured.builder.RequestSpecBuilder;
 import com.jayway.restassured.http.ContentType;
 
 public class CassandraMigrationRoutesTest {
-    private static final Integer LATEST_VERSION = 3;
-    private static final Integer CURRENT_VERSION = 2;
-    private static final Integer OLDER_VERSION = 1;
+    private static final SchemaVersion LATEST_VERSION = new SchemaVersion(3);
+    private static final SchemaVersion CURRENT_VERSION = new SchemaVersion(2);
+    private static final SchemaVersion OLDER_VERSION = new SchemaVersion(1);
     private WebAdminServer webAdminServer;
     private CassandraSchemaVersionDAO schemaVersionDAO;
     private MemoryTaskManager taskManager;
@@ -72,7 +73,7 @@ public class CassandraMigrationRoutesTest {
         Migration successfulMigration = mock(Migration.class);
         when(successfulMigration.run()).thenReturn(Migration.Result.COMPLETED);
 
-        Map<Integer, Migration> allMigrationClazz = ImmutableMap.<Integer, Migration>builder()
+        Map<SchemaVersion, Migration> allMigrationClazz = ImmutableMap.<SchemaVersion, Migration>builder()
             .put(OLDER_VERSION, successfulMigration)
             .put(CURRENT_VERSION, successfulMigration)
             .put(LATEST_VERSION, successfulMigration)
@@ -124,7 +125,7 @@ public class CassandraMigrationRoutesTest {
                 .jsonPath()
                 .getInt("version");
 
-        assertThat(version).isEqualTo(CURRENT_VERSION);
+        assertThat(version).isEqualTo(CURRENT_VERSION.getValue());
     }
 
     @Test
@@ -140,7 +141,7 @@ public class CassandraMigrationRoutesTest {
                 .jsonPath()
                 .getInt("version");
 
-        assertThat(version).isEqualTo(LATEST_VERSION);
+        assertThat(version).isEqualTo(LATEST_VERSION.getValue());
     }
 
     @Ignore
@@ -182,7 +183,7 @@ public class CassandraMigrationRoutesTest {
         when(schemaVersionDAO.getCurrentSchemaVersion()).thenReturn(CompletableFuture.completedFuture(Optional.of(OLDER_VERSION)));
 
         String taskId = with()
-            .body(String.valueOf(CURRENT_VERSION))
+            .body(String.valueOf(CURRENT_VERSION.getValue()))
         .post("/upgrade")
             .jsonPath()
             .get("taskId");
@@ -204,7 +205,7 @@ public class CassandraMigrationRoutesTest {
         when(schemaVersionDAO.getCurrentSchemaVersion()).thenReturn(CompletableFuture.completedFuture(Optional.of(CURRENT_VERSION)));
 
         Map<String, Object> errors = given()
-            .body(String.valueOf(OLDER_VERSION))
+            .body(String.valueOf(OLDER_VERSION.getValue()))
         .with()
             .post("/upgrade")
         .then()
@@ -272,7 +273,7 @@ public class CassandraMigrationRoutesTest {
             .body("status", is("completed"))
             .body("taskId", is(notNullValue()))
             .body("type", is(MigrationTask.CASSANDRA_MIGRATION))
-            .body("additionalInformation.toVersion", is(LATEST_VERSION))
+            .body("additionalInformation.toVersion", is(LATEST_VERSION.getValue()))
             .body("startedDate", is(notNullValue()))
             .body("submitDate", is(notNullValue()))
             .body("completedDate", is(notNullValue()));


---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message