JUnit addition for SDK-APP
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / model / PDPGroupContainer.java
index 3b3f119..c751c47 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP Policy Engine
  * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -31,8 +31,8 @@ import java.util.Set;
 
 import org.onap.policy.common.logging.flexlogger.FlexLogger;
 import org.onap.policy.common.logging.flexlogger.Logger;
-import org.onap.policy.utils.PolicyContainer;
-import org.onap.policy.utils.PolicyItemSetChangeNotifier;
+import org.onap.policy.rest.util.PolicyContainer;
+import org.onap.policy.rest.util.PolicyItemSetChangeNotifier;
 import org.onap.policy.xacml.api.XACMLErrorConstants;
 import org.onap.policy.xacml.api.pap.OnapPDP;
 import org.onap.policy.xacml.api.pap.OnapPDPGroup;
@@ -113,10 +113,7 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po
        }
     
     public boolean isSupported(Object itemId) {
-       if (itemId instanceof OnapPDPGroup) {
-               return true;
-       }
-       return false;
+       return itemId instanceof OnapPDPGroup;
     }
        
        public synchronized void refreshGroups() {
@@ -250,25 +247,25 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po
                if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("containsId: " + itemId);
                }
-               if (this.isSupported(itemId) == false) {
+               if (! this.isSupported(itemId)) {
                        return false;
                }
                return this.groups.contains(itemId);
        }
 
        @Override
-       public Object addItem() throws UnsupportedOperationException {
+       public Object addItem() {
                throw new UnsupportedOperationException("PDP Container cannot add a given item.");
        }
        
-       public void addNewGroup(String name, String description) throws NullPointerException, PAPException {
+       public void addNewGroup(String name, String description) throws PAPException {
                if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("addNewGroup " + name + " " + description);
                }
                this.papEngine.newGroup(name, description);
        }
        
-       public void addNewPDP(String id, OnapPDPGroup group, String name, String description, int jmxport) throws NullPointerException, PAPException {
+       public void addNewPDP(String id, OnapPDPGroup group, String name, String description, int jmxport) throws PAPException {
                if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("addNewPDP " + id + " " + name + " " + description + " " + jmxport);
                }
@@ -286,17 +283,17 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po
        }
 
        @Override
-       public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) throws UnsupportedOperationException {
+       public boolean addContainerProperty(Object propertyId, Class<?> type, Object defaultValue) {
                throw new UnsupportedOperationException("Cannot add a container property.");
        }
 
        @Override
-       public boolean removeContainerProperty(Object propertyId) throws UnsupportedOperationException {
+       public boolean removeContainerProperty(Object propertyId) {
                throw new UnsupportedOperationException("Cannot remove a container property.");
        }
 
        @Override
-       public boolean removeAllItems() throws UnsupportedOperationException {
+       public boolean removeAllItems() {
                throw new UnsupportedOperationException("PDP Container cannot remove all items. You must have at least the Default group.");
        }
 
@@ -310,7 +307,7 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po
 
        @Override
        public Object nextItemId(Object itemId) {
-               if (this.isSupported(itemId) == false) {
+               if (! this.isSupported(itemId)) {
                        return null;
                }
                int index = this.groups.indexOf(itemId);
@@ -337,7 +334,7 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po
 
        @Override
        public Object prevItemId(Object itemId) {
-               if (this.isSupported(itemId) == false) {
+               if (! this.isSupported(itemId)) {
                        return null;
                }
                int index = this.groups.indexOf(itemId);
@@ -403,7 +400,7 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po
        }
 
        @Override
-       public Object addItemAfter(Object previousItemId) throws UnsupportedOperationException {
+       public Object addItemAfter(Object previousItemId) {
                throw new UnsupportedOperationException("Cannot addItemAfter, there really is no real ordering.");
        }
 
@@ -429,22 +426,22 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po
        }
 
        @Override
-       public Object addItemAt(int index) throws UnsupportedOperationException {
+       public Object addItemAt(int index) {
                throw new UnsupportedOperationException("Cannot addItemAt");
        }
 
        @Override
-       public boolean removeItem(Object itemId) throws UnsupportedOperationException {
+       public boolean removeItem(Object itemId) {
                if (LOGGER.isTraceEnabled()) {
                        LOGGER.trace("removeItem: " + itemId);
                }
-               if (this.isSupported(itemId) == false) {
+               if (! this.isSupported(itemId)) {
                        return false;
                }
                //
                // You cannot remove the default group
                //
-               if ("Default".equals(((OnapPDPGroup) itemId).getId())) {
+               if (PROPERTY_DEFAULT.equals(((OnapPDPGroup) itemId).getId())) {
                        throw new UnsupportedOperationException("You can't remove the Default Group.");
                }
                //
@@ -458,63 +455,4 @@ public class PDPGroupContainer extends PolicyItemSetChangeNotifier implements Po
                }
                return false;
        }
-
-       public class PDPGroupItem{
-               private final OnapPDPGroup group;
-               
-               public PDPGroupItem(OnapPDPGroup itemId) {
-                       this.group = itemId;
-               }
-
-               public String getId() {
-                       if (LOGGER.isTraceEnabled()) {
-                               LOGGER.trace("getId: " + this.group);
-                       }
-                       return this.group.getId();
-               }
-               
-               public String getName() {
-                       if (LOGGER.isTraceEnabled()) {
-                               LOGGER.trace("getName: " + this.group);
-                       }
-                       return this.group.getName();
-               }
-               
-               public String getDescription() {
-                       if (LOGGER.isTraceEnabled()) {
-                               LOGGER.trace("getDescription: " + this.group);
-                       }
-                       return this.group.getDescription();
-               }
-               
-               public Boolean getDefault() {
-                       if (LOGGER.isTraceEnabled()) {
-                               LOGGER.trace("getDefault: " + this.group);
-                       }
-                       return this.group.isDefaultGroup();
-               }
-               
-        
-        public String  getStatus() {
-                       return this.group.getStatus().getStatus().toString();
-        }
-        
-        public Set<PDP>                getPDPs() {
-               return Collections.unmodifiableSet(this.group.getPdps());
-        }
-        
-        public Set<PDPPolicy> getPolicies() {
-                       if (LOGGER.isTraceEnabled()) {
-                               LOGGER.trace("getPolicies: " + this.group);
-                       }
-                       return this.group.getPolicies();
-        }
-        
-        public Set<PDPPIPConfig> getPipConfigs() {
-                       if (LOGGER.isTraceEnabled()) {
-                               LOGGER.trace("getPIPConfigs: " + this.group);
-                       }
-                       return this.group.getPipConfigs();
-        }
-       }
 }