JUnit test for policy/engine PolicyEngineAPI
[policy/engine.git] / PolicyEngineAPI / src / main / java / org / onap / policy / api / PolicyResponseStatus.java
index 63cb918..0db373c 100644 (file)
@@ -28,59 +28,65 @@ import com.fasterxml.jackson.annotation.JsonCreator;
  * 
  * @version 0.2
  */
-public enum PolicyResponseStatus {     
-       /**
-        * Indicates there is no action required.
-        */
-       NO_ACTION_REQUIRED("no_action"),
-       /** 
-        * Indicates that an action has been advised.
-        */
-       ACTION_ADVISED("action_advised"),
-       /**
-        * Indicates that an action has been taken.
-        */
-       ACTION_TAKEN("action_taken")
-       ;
-       
-       private String name;
-       private PolicyResponseStatus(String name){
-               this.name = name;
-       }
-       
-       /**
-        * Get the <code>PolicyResponseStatus</code> based on <code>String</code> representation of <code>PolicyResponse</code>
-        * 
-        * @param responseStatus the <code>String</code> Response Status
-        * @return the <code>PolicyResponseStatus</code> with the name matching <code>ACTION_ADVISED</code> or <code>ACTION_TAKEN</code> or <code>NO_ACTION_REQUIRED</code>
-        */
-       public static PolicyResponseStatus getStatus(String responseStatus) {
-               if("action_advised".equalsIgnoreCase(responseStatus)) {
-                       return ACTION_ADVISED;
-               }else if("action_taken".equalsIgnoreCase(responseStatus)) {
-                       return ACTION_TAKEN;
-               }else {
-                       return NO_ACTION_REQUIRED;
-               }
-       }
-       
-       /**
-        * Returns the <code>String</code> name for this <code>PolicyResponseStatus</code>
-        * 
-        * @return the <code>String</code> name for this <code>PolicyResponseStatus</code>
-        */
-       @Override
-       public String toString(){
-               return this.name;
-       }
-       
-       @JsonCreator
-    public static PolicyResponseStatus create (String value) {
-        for(PolicyResponseStatus type: values()){
-            if(type.toString().equals(value) || type.equals(PolicyResponseStatus.valueOf(value))){
+public enum PolicyResponseStatus {
+    /**
+     * Indicates there is no action required.
+     */
+    NO_ACTION_REQUIRED("no_action"),
+    /**
+     * Indicates that an action has been advised.
+     */
+    ACTION_ADVISED("action_advised"),
+    /**
+     * Indicates that an action has been taken.
+     */
+    ACTION_TAKEN("action_taken");
+
+    private final String name;
+
+    private PolicyResponseStatus(final String name) {
+        this.name = name;
+    }
+
+    /**
+     * Get the <code>PolicyResponseStatus</code> based on <code>String</code>
+     * representation of <code>PolicyResponse</code>
+     * 
+     * @param responseStatus
+     *            the <code>String</code> Response Status
+     * @return the <code>PolicyResponseStatus</code> with the name matching
+     *         <code>ACTION_ADVISED</code> or <code>ACTION_TAKEN</code> or
+     *         <code>NO_ACTION_REQUIRED</code>
+     */
+    public static PolicyResponseStatus getStatus(final String responseStatus) {
+        if (ACTION_ADVISED.name.equalsIgnoreCase(responseStatus)) {
+            return ACTION_ADVISED;
+        } else if (ACTION_TAKEN.name.equalsIgnoreCase(responseStatus)) {
+            return ACTION_TAKEN;
+        } else {
+            return NO_ACTION_REQUIRED;
+        }
+    }
+
+    /**
+     * Returns the <code>String</code> name for this
+     * <code>PolicyResponseStatus</code>
+     * 
+     * @return the <code>String</code> name for this
+     *         <code>PolicyResponseStatus</code>
+     */
+    @Override
+    public String toString() {
+        return this.name;
+    }
+
+    @JsonCreator
+    public static PolicyResponseStatus create(final String value) {
+        for (final PolicyResponseStatus type : values()) {
+            if (type.toString().equalsIgnoreCase(value) || type.name().equalsIgnoreCase(value)) {
                 return type;
             }
         }
-        throw new IllegalArgumentException();
+        throw new IllegalArgumentException("Invalid value: " + value);
     }
 }