Moved duplicated isUpdateAcceptable method to IntentData
and wrote a unit test for it.

Change-Id: I8b38476c41fba70abbba7ed0b37364696f17966d
diff --git a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
index 9a8f9e7..370b0b5 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/intent/impl/GossipIntentStore.java
@@ -150,86 +150,14 @@
         return null;
     }
 
-    /**
-     * Determines whether an intent data update is allowed. The update must
-     * either have a higher version than the current data, or the state
-     * transition between two updates of the same version must be sane.
-     *
-     * @param currentData existing intent data in the store
-     * @param newData new intent data update proposal
-     * @return true if we can apply the update, otherwise false
-     */
-    private boolean isUpdateAcceptable(IntentData currentData, IntentData newData) {
 
-        if (currentData == null) {
-            return true;
-        } else if (currentData.version().compareTo(newData.version()) < 0) {
-            return true;
-        } else if (currentData.version().compareTo(newData.version()) > 0) {
-            return false;
-        }
-
-        // current and new data versions are the same
-        IntentState currentState = currentData.state();
-        IntentState newState = newData.state();
-
-        switch (newState) {
-        case INSTALLING:
-            if (currentState == INSTALLING) {
-                return false;
-            }
-            // FALLTHROUGH
-        case INSTALLED:
-            if (currentState == INSTALLED) {
-                return false;
-            } else if (currentState == WITHDRAWING || currentState == WITHDRAWN) {
-                log.warn("Invalid state transition from {} to {} for intent {}",
-                         currentState, newState, newData.key());
-                return false;
-            }
-            return true;
-
-        case WITHDRAWING:
-            if (currentState == WITHDRAWING) {
-                return false;
-            }
-            // FALLTHROUGH
-        case WITHDRAWN:
-            if (currentState == WITHDRAWN) {
-                return false;
-            } else if (currentState == INSTALLING || currentState == INSTALLED) {
-                log.warn("Invalid state transition from {} to {} for intent {}",
-                         currentState, newState, newData.key());
-                return false;
-            }
-            return true;
-
-
-        case FAILED:
-            if (currentState == FAILED) {
-                return false;
-            }
-            return true;
-
-        case PURGE_REQ:
-            return true;
-
-        case COMPILING:
-        case RECOMPILING:
-        case INSTALL_REQ:
-        case WITHDRAW_REQ:
-        default:
-            log.warn("Invalid state {} for intent {}", newState, newData.key());
-            return false;
-        }
-    }
 
     @Override
     public void write(IntentData newData) {
         checkNotNull(newData);
 
         IntentData currentData = currentMap.get(newData.key());
-        if (isUpdateAcceptable(currentData, newData)) {
+        if (IntentData.isUpdateAcceptable(currentData, newData)) {
             // Only the master is modifying the current state. Therefore assume
             // this always succeeds
             if (newData.state() == PURGE_REQ) {