aboutsummaryrefslogtreecommitdiffstats
path: root/PolicyEngineClient
diff options
context:
space:
mode:
Diffstat (limited to 'PolicyEngineClient')
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ActionPolicyClient.java156
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/BrmsParamPolicyClient.java77
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/BrmsRawPolicyClient.java51
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ClosedLoopPolicyClient.java167
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ClosedLoopPolicyPerformanceMetricClient.java169
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigBasePolicyClient.java108
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigFirewallPolicyClient.java143
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/DecisionPolicyClient.java167
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/DeletePolicyClient.java53
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/GeneralTestClient.java653
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/GetConfigSample.java31
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/Handler.java180
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ImportBRMSTemplate.java40
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ImportMicroServiceClient.java47
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ListConfigPoliciesClient.java87
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/ListPolicyClient.java7
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/MainClient.java169
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/MicroServicesPolicyClient.java158
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/OptimizationPolicyJavaAPIClient.java162
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/PolicyEngineTestClient.java273
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/PushPoliciesToPDP.java54
-rw-r--r--PolicyEngineClient/src/test/java/org/onap/policyengine/RawDecisionPolicyClient.java12
22 files changed, 1512 insertions, 1452 deletions
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ActionPolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ActionPolicyClient.java
index 94c6043c5..a3c29fb8e 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/ActionPolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ActionPolicyClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -34,78 +34,84 @@ import org.onap.policy.api.PolicyEngine;
import org.onap.policy.api.PolicyParameters;
public class ActionPolicyClient {
- static Boolean isEdit = true;
- public static void main(String[] args) {
- try {
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- PolicyParameters policyParameters = new PolicyParameters();
- // Set Policy Type
- policyParameters.setPolicyClass(PolicyClass.Action); //required
- policyParameters.setPolicyName("MikeAPItesting.testActionAPI5"); //required
- policyParameters.setPolicyDescription("This is a sample Action policy update example with no Action Body"); //optional
- //policyParameters.setPolicyScope("MikeAPItesting"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI
-
- //Set the Component Attributes... These are Optional
- Map<String, String> configAttributes = new HashMap<>();
- configAttributes.put("Template", "UpdateTemplate");
- configAttributes.put("controller", "default");
- configAttributes.put("SamPoll", "30");
- configAttributes.put("value", "abcd");
-
- Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
- attributes.put(AttributeType.MATCHING, configAttributes);
- policyParameters.setAttributes(attributes);
+ static Boolean isEdit = true;
-
- List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
- List<String> dynamicRuleAlgorithmFunctions = new LinkedList<>();
- List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
- List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
-
- //Example of a complex Rule algorithm
- /* label field1 function field2
- * *****************************************************
- * A1 cobal integer-equal 90
- * A2 cap string-contains ca
- * A3 cobal integer-equal 90
- * A4 A2 and A3
- * A5 Config integer-greater-than 45
- * A6 A4 ` or A5
- * A7 A1 and A6
- */
- dynamicRuleAlgorithmLabels = Arrays.asList("A1","A2","A3","A4","A5","A6","A7");
- dynamicRuleAlgorithmField1 = Arrays.asList("cobal","cap","cobal","A2","Config","A4","A1");
- dynamicRuleAlgorithmFunctions = Arrays.asList("integer-equal","string-contains","integer-equal","and","integer-greater-than","or","and");
- dynamicRuleAlgorithmField2 = Arrays.asList("90","ca","90","A3","45","A5","A6");
-
- policyParameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
- policyParameters.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
- policyParameters.setDynamicRuleAlgorithmFunctions(dynamicRuleAlgorithmFunctions);
- policyParameters.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
-
- policyParameters.setActionPerformer("PEP");
- policyParameters.setActionAttribute("mikeTest2");
- policyParameters.setRequestID(UUID.randomUUID());
-
- // API method to create Policy or update policy
- PolicyChangeResponse response = null;
- if (!isEdit) {
- response = policyEngine.createPolicy(policyParameters);
- } else {
- response = policyEngine.updatePolicy(policyParameters);
- }
-
- if(response.getResponseCode()==200){
- System.out.println(response.getResponseMessage());
- System.out.println("Policy Created Successfully!");
- }else{
- System.out.println("Error! " + response.getResponseMessage());
- }
- } catch (Exception e) {
- System.err.println(e.getMessage() + e);
- }
- }
-
-}
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ try {
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ PolicyParameters policyParameters = new PolicyParameters();
+ // Set Policy Type
+ policyParameters.setPolicyClass(PolicyClass.Action); // required
+ policyParameters.setPolicyName("MikeAPItesting.testActionAPI5"); // required
+ policyParameters.setPolicyDescription(
+ "This is a sample Action policy update example with no Action Body"); // optional
+ // saved... this displays a a subscope on the GUI
+
+ // Set the Component Attributes... These are Optional
+ Map<String, String> configAttributes = new HashMap<>();
+ configAttributes.put("Template", "UpdateTemplate");
+ configAttributes.put("controller", "default");
+ configAttributes.put("SamPoll", "30");
+ configAttributes.put("value", "abcd");
+
+ Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
+ attributes.put(AttributeType.MATCHING, configAttributes);
+ policyParameters.setAttributes(attributes);
+
+ List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmFunctions = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
+
+ // Example of a complex Rule algorithm
+ /*
+ * label field1 function field2
+ * *****************************************************
+ * A1 cobal integer-equal 90
+ * A2 cap string-contains ca
+ * A3 cobal integer-equal 90
+ * A4 A2 and A3
+ * A5 Config integer-greater-than 45
+ * A6 A4 ` or A5
+ * A7 A1 and A6
+ */
+ dynamicRuleAlgorithmLabels = Arrays.asList("A1", "A2", "A3", "A4", "A5", "A6", "A7");
+ dynamicRuleAlgorithmField1 = Arrays.asList("cobal", "cap", "cobal", "A2", "Config", "A4", "A1");
+ dynamicRuleAlgorithmFunctions = Arrays.asList("integer-equal", "string-contains", "integer-equal", "and",
+ "integer-greater-than", "or", "and");
+ List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
+ dynamicRuleAlgorithmField2 = Arrays.asList("90", "ca", "90", "A3", "45", "A5", "A6");
+ policyParameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
+ policyParameters.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
+ policyParameters.setDynamicRuleAlgorithmFunctions(dynamicRuleAlgorithmFunctions);
+ policyParameters.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
+ policyParameters.setActionPerformer("PEP");
+ policyParameters.setActionAttribute("mikeTest2");
+ policyParameters.setRequestID(UUID.randomUUID());
+
+ // API method to create Policy or update policy
+ PolicyChangeResponse response = null;
+ if (!isEdit) {
+ response = policyEngine.createPolicy(policyParameters);
+ } else {
+ response = policyEngine.updatePolicy(policyParameters);
+ }
+
+ if (response.getResponseCode() == 200) {
+ System.out.println(response.getResponseMessage());
+ System.out.println("Policy Created Successfully!");
+ } else {
+ System.out.println("Error! " + response.getResponseMessage());
+ }
+ } catch (Exception e) {
+ System.err.println(e.getMessage() + e);
+ }
+ }
+
+}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/BrmsParamPolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/BrmsParamPolicyClient.java
index 33ceedf7f..60022d526 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/BrmsParamPolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/BrmsParamPolicyClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -32,65 +32,68 @@ import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyEngine;
import org.onap.policy.api.PolicyParameters;
-
public class BrmsParamPolicyClient {
-
- public static void main(String[] args) {
- try {
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ /**
+ * main.
+ *
+ * @param args String[] of arguments
+ */
+ public static void main(String[] args) {
+ try {
PolicyParameters policyParameters = new PolicyParameters();
- // Set Policy Type(Mandatory)
+ // Set Policy Type(Mandatory)
policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
-
- // Set Policy Name(Mandatory)
+
+ // Set Policy Name(Mandatory)
policyParameters.setPolicyName("Lakshman.testParamPolicyThree");
-
+
+ // Set Safe Policy value for Risk Type
+ SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateformat3.parse("15/10/2016");
+ policyParameters.setTtlDate(date);
+ // Set Safe Policy value for Guard
+ policyParameters.setGuard(true);
+ // Set Safe Policy value for Risk Level
+ policyParameters.setRiskLevel("5");
// Set Safe Policy value for Risk Type
- SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateformat3.parse("15/10/2016");
- policyParameters.setTtlDate(date);
- // Set Safe Policy value for Guard
- policyParameters.setGuard(true);
- // Set Safe Policy value for Risk Level
- policyParameters.setRiskLevel("5");
- // Set Safe Policy value for Risk Type
- policyParameters.setRiskType("PROD");
-
+ policyParameters.setRiskType("PROD");
+
// Set description of the policy(Optional)
policyParameters.setPolicyDescription("This is a sample BRMS Param policy creation example");
-
- // Set BRMS Param Template Attributes(Mandatory)
+
+ // Set BRMS Param Template Attributes(Mandatory)
Map<String, String> ruleAttributes = new HashMap<>();
- ruleAttributes.put("templateName", "Sample"); // This sampleTemplate is the Template name from dictionary.
- ruleAttributes.put("controller", "default"); // Set Rule to a PDP Controller, default is the controller name.
- ruleAttributes.put("SamPoll", "300"); // Template specific key and value set by us.
- ruleAttributes.put("value", "abcd"); // Template specific key and value set by us.
+ ruleAttributes.put("templateName", "Sample"); // This sampleTemplate is the Template name from dictionary.
+ // Set Rule to a PDP Controller, default is the controller
+ // name.
+ ruleAttributes.put("controller", "default");
+ ruleAttributes.put("SamPoll", "300"); // Template specific key and value set by us.
+ ruleAttributes.put("value", "abcd"); // Template specific key and value set by us.
Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
attributes.put(AttributeType.RULE, ruleAttributes);
policyParameters.setAttributes(attributes);
-
- //Set a random UUID(Mandatory)
+
+ // Set a random UUID(Mandatory)
policyParameters.setRequestID(UUID.randomUUID());
- // CreatePolicy method to create Policy.
+ // CreatePolicy method to create Policy.
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
PolicyChangeResponse response = policyEngine.updatePolicy(policyParameters);
- if(response.getResponseCode()==200){
+ if (response.getResponseCode() == 200) {
System.out.println(response.getResponseMessage());
System.out.println("Policy Created Successfully!");
- }else{
+ } else {
System.out.println("Error! " + response.getResponseMessage());
}
} catch (Exception e) {
System.err.println(e.getMessage() + e);
}
-
- }
-
-}
+ }
+}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/BrmsRawPolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/BrmsRawPolicyClient.java
index 60e2c5df7..41bb6c556 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/BrmsRawPolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/BrmsRawPolicyClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -42,39 +42,44 @@ import org.onap.policy.api.PolicyType;
public class BrmsRawPolicyClient {
static Boolean isEdit = true;
- //Reads a File and converts into a String.
- private static String readFile( String file ) throws IOException {
+ // Reads a File and converts into a String.
+ private static String readFile(String file) throws IOException {
- String line = null;
- StringBuilder stringBuilder = new StringBuilder();
- String ls = System.getProperty("line.separator");
+ String line = null;
+ StringBuilder stringBuilder = new StringBuilder();
+ String ls = System.getProperty("line.separator");
- try (BufferedReader reader = new BufferedReader( new FileReader (file))) {
- while( ( line = reader.readLine() ) != null ) {
- stringBuilder.append( line );
- stringBuilder.append( ls );
+ try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
+ while ((line = reader.readLine()) != null) {
+ stringBuilder.append(line);
+ stringBuilder.append(ls);
}
return stringBuilder.toString();
}
}
-
+ /**
+ * main.
+ *
+ * @param args String[] of arguments
+ */
public static void main(String[] args) {
try {
PolicyEngine policyEngine = new PolicyEngine("config.properties");
- PolicyParameters policyParameters = new PolicyParameters();
- Map<String, String> attrib= new HashMap<>();
- attrib.put("cpu","80");
+ Map<String, String> attrib = new HashMap<>();
+ attrib.put("cpu", "80");
attrib.put("memory", "50");
Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
attributes.put(AttributeType.RULE, attrib);
+ PolicyParameters policyParameters = new PolicyParameters();
// Set Policy Type
- policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_RAW); //required
- policyParameters.setPolicyName("Lakshman.testBRMSRawAPITwo"); //required
- policyParameters.setPolicyDescription("This is a sample BRMS Raw policy body"); //optional
+ policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_RAW); // required
+ policyParameters.setPolicyName("Lakshman.testBRMSRawAPITwo"); // required
+ policyParameters.setPolicyDescription("This is a sample BRMS Raw policy body"); // optional
policyParameters.setAttributes(attributes);
- //policyParameters.setPolicyScope("Lakshman"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI
+ // policyParameters.setPolicyScope("Lakshman"); //Directory will be created where the Policies are saved...
+ // this displays a a subscope on the GUI
policyParameters.setRequestID(UUID.randomUUID());
// Set Safe Policy value for Risk Type
@@ -104,10 +109,10 @@ public class BrmsRawPolicyClient {
response = policyEngine.updatePolicy(policyParameters);
}
- if(response.getResponseCode()==200){
+ if (response.getResponseCode() == 200) {
System.out.println(response.getResponseMessage());
System.out.println("Policy Created Successfully!");
- }else{
+ } else {
System.out.println("Error! " + response.getResponseMessage());
}
} catch (Exception e) {
@@ -116,5 +121,3 @@ public class BrmsRawPolicyClient {
}
}
-
-
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ClosedLoopPolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ClosedLoopPolicyClient.java
index 29a0f4363..13b9f4794 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/ClosedLoopPolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ClosedLoopPolicyClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -43,83 +43,88 @@ import org.onap.policy.api.PolicyParameters;
import org.onap.policy.api.PolicyType;
public class ClosedLoopPolicyClient {
- //For updating a ClosedLoop_Fault policy set the "isEdit" flag to true.
- //For creating a ClosedLoop_Fault policy set the "isEdit" flag to false.
- static Boolean isEdit = false;
-
- //Builds JSONObject from File
- private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException {
- JsonObject json = null;;
- JsonReader jsonReader = null;
- if (jsonString != null && jsonInput == null) {
- StringReader in = null;
- in = new StringReader(jsonString);
- jsonReader = Json.createReader(in);
- json = jsonReader.readObject();
- in.close();
- }else {
- InputStream in = null;
- in = new FileInputStream(jsonInput);
- jsonReader = Json.createReader(in);
- json = jsonReader.readObject();
- try {
- in.close();
- } catch (IOException e) {
- System.err.println("Exception Occured while closing input stream"+e);
- }
- }
- jsonReader.close();
-
- return json;
- }
- public static void main(String[] args) {
- try {
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- PolicyParameters policyParameters = new PolicyParameters();
- // Set Policy Type
- policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault);
- policyParameters.setPolicyName("MikeAPItests.ClosedLoopFaultApiTest45");
- policyParameters.setPolicyDescription("This is a sample ClosedLoop_Fault policy CREATE example");
- //policyParameters.setPolicyScope("MikeAPItests");
-
- // Set up Micro Services Attributes
- File jsonFile = null;
- String MSjsonString= null;
- Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\faultTestJson.json");
- jsonFile = file.toFile();
-
- policyParameters.setConfigBody(buildJSON(jsonFile, MSjsonString).toString());
- policyParameters.setConfigBodyType(PolicyType.JSON);
+ // For updating a ClosedLoop_Fault policy set the "isEdit" flag to true.
+ // For creating a ClosedLoop_Fault policy set the "isEdit" flag to false.
+ static Boolean isEdit = false;
- policyParameters.setRequestID(UUID.randomUUID());
- // Set Safe Policy value for Risk Type
- SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateformat3.parse("15/10/2016");
- policyParameters.setTtlDate(date);
- // Set Safe Policy value for Guard
- policyParameters.setGuard(true);
- // Set Safe Policy value for Risk Level
- policyParameters.setRiskLevel("5");
- // Set Safe Policy value for Risk Type
- policyParameters.setRiskType("PROD");
-
- // API method to create or update Policy.
- PolicyChangeResponse response = null;
- if (!isEdit) {
- response = policyEngine.createPolicy(policyParameters);
- }
- else {
- response = policyEngine.updatePolicy(policyParameters);
- }
-
- if(response.getResponseCode()==200){
- System.out.println(response.getResponseMessage());
- System.out.println("Policy Created Successfully!");
- }else{
- System.out.println("Error! " + response.getResponseMessage());
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- }
+ // Builds JSONObject from File
+ private static JsonObject buildJson(File jsonInput, String jsonString) throws FileNotFoundException {
+ JsonObject json = null;;
+ JsonReader jsonReader = null;
+ if (jsonString != null && jsonInput == null) {
+ StringReader in = null;
+ in = new StringReader(jsonString);
+ jsonReader = Json.createReader(in);
+ json = jsonReader.readObject();
+ in.close();
+ } else {
+ InputStream in = null;
+ in = new FileInputStream(jsonInput);
+ jsonReader = Json.createReader(in);
+ json = jsonReader.readObject();
+ try {
+ in.close();
+ } catch (IOException e) {
+ System.err.println("Exception Occured while closing input stream" + e);
+ }
+ }
+ jsonReader.close();
+
+ return json;
+ }
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ try {
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ PolicyParameters policyParameters = new PolicyParameters();
+ // Set Policy Type
+ policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault);
+ policyParameters.setPolicyName("MikeAPItests.ClosedLoopFaultApiTest45");
+ policyParameters.setPolicyDescription("This is a sample ClosedLoop_Fault policy CREATE example");
+ // policyParameters.setPolicyScope("MikeAPItests");
+
+ // Set up Micro Services Attributes
+ File jsonFile = null;
+ String msJsonString = null;
+ Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\faultTestJson.json");
+ jsonFile = file.toFile();
+
+ policyParameters.setConfigBody(buildJson(jsonFile, msJsonString).toString());
+ policyParameters.setConfigBodyType(PolicyType.JSON);
+
+ policyParameters.setRequestID(UUID.randomUUID());
+ // Set Safe Policy value for Risk Type
+ SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateformat3.parse("15/10/2016");
+ policyParameters.setTtlDate(date);
+ // Set Safe Policy value for Guard
+ policyParameters.setGuard(true);
+ // Set Safe Policy value for Risk Level
+ policyParameters.setRiskLevel("5");
+ // Set Safe Policy value for Risk Type
+ policyParameters.setRiskType("PROD");
+
+ // API method to create or update Policy.
+ PolicyChangeResponse response = null;
+ if (!isEdit) {
+ response = policyEngine.createPolicy(policyParameters);
+ } else {
+ response = policyEngine.updatePolicy(policyParameters);
+ }
+
+ if (response.getResponseCode() == 200) {
+ System.out.println(response.getResponseMessage());
+ System.out.println("Policy Created Successfully!");
+ } else {
+ System.out.println("Error! " + response.getResponseMessage());
+ }
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ClosedLoopPolicyPerformanceMetricClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ClosedLoopPolicyPerformanceMetricClient.java
index eaee2a325..bcdeaabd1 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/ClosedLoopPolicyPerformanceMetricClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ClosedLoopPolicyPerformanceMetricClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -43,85 +43,88 @@ import org.onap.policy.api.PolicyParameters;
import org.onap.policy.api.PolicyType;
public class ClosedLoopPolicyPerformanceMetricClient {
-
- //For updating a ClosedLoop_Fault policy set the "isEdit" flag to true.
- //For creating a ClosedLoop_Fault policy set the "isEdit" flag to false.
- static Boolean isEdit = true;
-
- //Builds JSONObject from File
- private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException {
- JsonObject json = null;;
- JsonReader jsonReader = null;
- if (jsonString != null && jsonInput == null) {
- StringReader in = null;
- in = new StringReader(jsonString);
- jsonReader = Json.createReader(in);
- json = jsonReader.readObject();
- in.close();
- }
- else {
- InputStream in = null;
- in = new FileInputStream(jsonInput);
- jsonReader = Json.createReader(in);
- json = jsonReader.readObject();
- try {
- in.close();
- } catch (IOException e) {
- System.err.println("Exception Occured while closing input stream"+e);
- }
- }
- jsonReader.close();
- return json;
- }
-
- public static void main(String[] args) {
- try {
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- PolicyParameters policyParameters = new PolicyParameters();
- // Set Policy Type
- policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_PM);
- policyParameters.setPolicyName("MikeAPItests.ClosedLoopPmApiTest");
- policyParameters.setPolicyDescription("This is a sample ClosedLoop_PM policy CREATE example");
- //policyParameters.setPolicyScope("MikeAPItests");
-
- // Set up Micro Services Attributes
- File jsonFile = null;
- String MSjsonString= null;
- Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\pmTestJson.json");
- jsonFile = file.toFile();
-
- policyParameters.setConfigBody(buildJSON(jsonFile, MSjsonString).toString());
- policyParameters.setConfigBodyType(PolicyType.JSON);
- policyParameters.setRequestID(UUID.randomUUID());
- // Set Safe Policy value for Risk Type
- SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateformat3.parse("15/10/2016");
- policyParameters.setTtlDate(date);
- // Set Safe Policy value for Guard
- policyParameters.setGuard(true);
- // Set Safe Policy value for Risk Level
- policyParameters.setRiskLevel("5");
- // Set Safe Policy value for Risk Type
- policyParameters.setRiskType("PROD");
-
- // API method to create or update Policy.
- PolicyChangeResponse response = null;
- if (!isEdit) {
- response = policyEngine.createPolicy(policyParameters);
- }
- else {
- response = policyEngine.updatePolicy(policyParameters);
- }
-
- if(response.getResponseCode()==200){
- System.out.println(response.getResponseMessage());
- System.out.println("Policy Created Successfully!");
- }else{
- System.out.println("Error! " + response.getResponseMessage());
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- }
+ // For updating a ClosedLoop_Fault policy set the "isEdit" flag to true.
+ // For creating a ClosedLoop_Fault policy set the "isEdit" flag to false.
+ static Boolean isEdit = true;
+
+ // Builds JSONObject from File
+ private static JsonObject buildJson(File jsonInput, String jsonString) throws FileNotFoundException {
+ JsonObject json = null;;
+ JsonReader jsonReader = null;
+ if (jsonString != null && jsonInput == null) {
+ StringReader in = null;
+ in = new StringReader(jsonString);
+ jsonReader = Json.createReader(in);
+ json = jsonReader.readObject();
+ in.close();
+ } else {
+ InputStream in = null;
+ in = new FileInputStream(jsonInput);
+ jsonReader = Json.createReader(in);
+ json = jsonReader.readObject();
+ try {
+ in.close();
+ } catch (IOException e) {
+ System.err.println("Exception Occured while closing input stream" + e);
+ }
+ }
+ jsonReader.close();
+ return json;
+ }
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ try {
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ PolicyParameters policyParameters = new PolicyParameters();
+ // Set Policy Type
+ policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_PM);
+ policyParameters.setPolicyName("MikeAPItests.ClosedLoopPmApiTest");
+ policyParameters.setPolicyDescription("This is a sample ClosedLoop_PM policy CREATE example");
+ // policyParameters.setPolicyScope("MikeAPItests");
+
+ // Set up Micro Services Attributes
+ File jsonFile = null;
+ String msJsonString = null;
+ Path file = Paths.get("C:\\policyAPI\\ClosedLoopJSON\\pmTestJson.json");
+ jsonFile = file.toFile();
+
+ policyParameters.setConfigBody(buildJson(jsonFile, msJsonString).toString());
+ policyParameters.setConfigBodyType(PolicyType.JSON);
+
+ policyParameters.setRequestID(UUID.randomUUID());
+ // Set Safe Policy value for Risk Type
+ SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateformat3.parse("15/10/2016");
+ policyParameters.setTtlDate(date);
+ // Set Safe Policy value for Guard
+ policyParameters.setGuard(true);
+ // Set Safe Policy value for Risk Level
+ policyParameters.setRiskLevel("5");
+ // Set Safe Policy value for Risk Type
+ policyParameters.setRiskType("PROD");
+
+ // API method to create or update Policy.
+ PolicyChangeResponse response = null;
+ if (!isEdit) {
+ response = policyEngine.createPolicy(policyParameters);
+ } else {
+ response = policyEngine.updatePolicy(policyParameters);
+ }
+
+ if (response.getResponseCode() == 200) {
+ System.out.println(response.getResponseMessage());
+ System.out.println("Policy Created Successfully!");
+ } else {
+ System.out.println("Error! " + response.getResponseMessage());
+ }
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigBasePolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigBasePolicyClient.java
index cfcc1460b..cfc47cc1e 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigBasePolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigBasePolicyClient.java
@@ -1,22 +1,22 @@
- /*-
- * ============LICENSE_START=======================================================
- * PolicyEngineClient
- * ================================================================================
- * Copyright (C) 2017 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.
- * 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.
- * ============LICENSE_END=========================================================
- */
+/*-
+* ============LICENSE_START=======================================================
+* PolicyEngineClient
+* ================================================================================
+* Copyright (C) 2017, 2019 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.
+* 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.
+* ============LICENSE_END=========================================================
+*/
package org.onap.policyengine;
@@ -33,59 +33,65 @@ import org.onap.policy.api.PolicyEngine;
import org.onap.policy.api.PolicyParameters;
import org.onap.policy.api.PolicyType;
-public class ConfigBasePolicyClient{
- static Boolean isEdit = false;
- public static void main(String[] args) {
+public class ConfigBasePolicyClient {
+ static Boolean isEdit = false;
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
try {
PolicyEngine policyEngine = new PolicyEngine("config.properties");
PolicyParameters policyParameters = new PolicyParameters();
// Set Policy Type
- policyParameters.setPolicyConfigType(PolicyConfigType.Base); //required
- policyParameters.setPolicyName("MikeConsole.testDeleteAPI6"); //required
- policyParameters.setPolicyDescription("This is a sample Config Base policy creation example"); //optional
- policyParameters.setOnapName("DCAE"); //required
- policyParameters.setConfigName("testBase"); //required
- policyParameters.setConfigBodyType(PolicyType.OTHER); //required
- policyParameters.setConfigBody("testing"); //required
-
- //Set the Config Attributes... These are Optional
- Map<String, String> configAttributes = new HashMap<>();
+ policyParameters.setPolicyConfigType(PolicyConfigType.Base); // required
+ policyParameters.setPolicyName("MikeConsole.testDeleteAPI6"); // required
+ policyParameters.setPolicyDescription("This is a sample Config Base policy creation example"); // optional
+ policyParameters.setOnapName("DCAE"); // required
+ policyParameters.setConfigName("testBase"); // required
+ policyParameters.setConfigBodyType(PolicyType.OTHER); // required
+ policyParameters.setConfigBody("testing"); // required
+
+ // Set the Config Attributes... These are Optional
+ Map<String, String> configAttributes = new HashMap<>();
configAttributes.put("Template", "SampleTemplate");
- configAttributes.put("controller", "default");
+ configAttributes.put("controller", "default");
configAttributes.put("SamPoll", "30");
- configAttributes.put("value", "abcd");
- Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
+ configAttributes.put("value", "abcd");
+ Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
attributes.put(AttributeType.MATCHING, configAttributes);
policyParameters.setAttributes(attributes);
policyParameters.setRequestID(UUID.randomUUID());
// Set Safe Policy value for Risk Type
- SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateformat3.parse("15/10/2016");
- policyParameters.setTtlDate(date);
- // Set Safe Policy value for Guard
- policyParameters.setGuard(true);
- // Set Safe Policy value for Risk Level
- policyParameters.setRiskLevel("5");
- // Set Safe Policy value for Risk Type
- policyParameters.setRiskType("PROD");
-
+ SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateformat3.parse("15/10/2016");
+ policyParameters.setTtlDate(date);
+ // Set Safe Policy value for Guard
+ policyParameters.setGuard(true);
+ // Set Safe Policy value for Risk Level
+ policyParameters.setRiskLevel("5");
+ // Set Safe Policy value for Risk Type
+ policyParameters.setRiskType("PROD");
+
// API method to create Policy or update policy
PolicyChangeResponse response = null;
if (!isEdit) {
response = policyEngine.createPolicy(policyParameters);
} else {
- response = policyEngine.updatePolicy(policyParameters);
+ response = policyEngine.updatePolicy(policyParameters);
}
-
- if(response.getResponseCode()==200){
+
+ if (response.getResponseCode() == 200) {
System.out.println(response.getResponseMessage());
System.out.println("Policy Created Successfully!");
- }else{
+ } else {
System.out.println("Error! " + response.getResponseMessage());
}
} catch (Exception e) {
System.err.println(e.getMessage());
}
- }
-
+ }
+
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigFirewallPolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigFirewallPolicyClient.java
index 37ec9fabd..f7665f9ac 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigFirewallPolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ConfigFirewallPolicyClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -43,77 +43,84 @@ import org.onap.policy.api.PolicyParameters;
import org.onap.policy.api.PolicyType;
public class ConfigFirewallPolicyClient {
- static Boolean isEdit = false;
- public static void main(String[] args) {
- try{
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- PolicyParameters policyParameters = new PolicyParameters();
- // Set Policy Type
- policyParameters.setPolicyConfigType(PolicyConfigType.Firewall); //required
- policyParameters.setPolicyName("MikeAPItesting.testConfigFirewallPolicy1607_1"); //required
- //policyParameters.setPolicyScope("MikeAPItesting"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI
- policyParameters.setRequestID(UUID.randomUUID());
-
+ static Boolean isEdit = false;
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ try {
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ PolicyParameters policyParameters = new PolicyParameters();
+ // Set Policy Type
+ policyParameters.setPolicyConfigType(PolicyConfigType.Firewall); // required
+ policyParameters.setPolicyName("MikeAPItesting.testConfigFirewallPolicy1607_1"); // required
+ // policyParameters.setPolicyScope("MikeAPItesting"); //Directory will be created where the Policies are
+ // saved... this displays a a subscope on the GUI
+ policyParameters.setRequestID(UUID.randomUUID());
+
+ // Set Safe Policy value for Risk Type
+ SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateformat3.parse("15/10/2016");
+ policyParameters.setTtlDate(date);
+ // Set Safe Policy value for Guard
+ policyParameters.setGuard(true);
+ // Set Safe Policy value for Risk Level
+ policyParameters.setRiskLevel("5");
// Set Safe Policy value for Risk Type
- SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateformat3.parse("15/10/2016");
- policyParameters.setTtlDate(date);
- // Set Safe Policy value for Guard
- policyParameters.setGuard(true);
- // Set Safe Policy value for Risk Level
- policyParameters.setRiskLevel("5");
- // Set Safe Policy value for Risk Type
- policyParameters.setRiskType("PROD");
- File jsonFile = null;
- String jsonRuleList = null;
- Path file = Paths.get("C:\\policyAPI\\firewallRulesJSON\\Config_FW_1607Rule.json");
- jsonFile = file.toFile();
-
- //buildJSON(jsonFile, jsonRuleList);
- policyParameters.setConfigBody(buildJSON(jsonFile, jsonRuleList).toString());
- policyParameters.setConfigBodyType(PolicyType.JSON);
+ policyParameters.setRiskType("PROD");
+ File jsonFile = null;
+ String jsonRuleList = null;
+ Path file = Paths.get("C:\\policyAPI\\firewallRulesJSON\\Config_FW_1607Rule.json");
+ jsonFile = file.toFile();
+
+ // buildJSON(jsonFile, jsonRuleList);
+ policyParameters.setConfigBody(buildJson(jsonFile, jsonRuleList).toString());
+ policyParameters.setConfigBodyType(PolicyType.JSON);
// API method to create Policy or update policy
PolicyChangeResponse response = null;
if (!isEdit) {
response = policyEngine.createPolicy(policyParameters);
} else {
- response = policyEngine.updatePolicy(policyParameters);
+ response = policyEngine.updatePolicy(policyParameters);
}
-
- if(response.getResponseCode()==200){
- System.out.println(response.getResponseMessage());
- System.out.println("Policy Created Successfully!");
- }else{
- System.out.println("Error! " + response.getResponseMessage());
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
-
-}
-
- private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException {
- JsonObject json = null;
- JsonReader jsonReader = null;
- if (jsonString != null && jsonInput == null) {
- StringReader in = null;
- in = new StringReader(jsonString);
- jsonReader = Json.createReader(in);
- json = jsonReader.readObject();
- in.close();
- } else {
- InputStream in = null;
- in = new FileInputStream(jsonInput);
- jsonReader = Json.createReader(in);
- json = jsonReader.readObject();
- try {
- in.close();
- } catch (IOException e) {
- System.err.println("Exception Occured while closing input stream"+e);
- }
- }
- jsonReader.close();
- return json;
- }
+
+ if (response.getResponseCode() == 200) {
+ System.out.println(response.getResponseMessage());
+ System.out.println("Policy Created Successfully!");
+ } else {
+ System.out.println("Error! " + response.getResponseMessage());
+ }
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+
+ }
+
+ private static JsonObject buildJson(File jsonInput, String jsonString) throws FileNotFoundException {
+ JsonObject json = null;
+ JsonReader jsonReader = null;
+ if (jsonString != null && jsonInput == null) {
+ StringReader in = null;
+ in = new StringReader(jsonString);
+ jsonReader = Json.createReader(in);
+ json = jsonReader.readObject();
+ in.close();
+ } else {
+ InputStream in = null;
+ in = new FileInputStream(jsonInput);
+ jsonReader = Json.createReader(in);
+ json = jsonReader.readObject();
+ try {
+ in.close();
+ } catch (IOException e) {
+ System.err.println("Exception Occured while closing input stream" + e);
+ }
+ }
+ jsonReader.close();
+ return json;
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/DecisionPolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/DecisionPolicyClient.java
index 2ef2d3b1a..44fb455af 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/DecisionPolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/DecisionPolicyClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -34,81 +34,90 @@ import org.onap.policy.api.PolicyEngine;
import org.onap.policy.api.PolicyParameters;
public class DecisionPolicyClient {
- static Boolean isEdit = true;
- public static void main(String[] args) {
- try {
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- PolicyParameters policyParameters = new PolicyParameters();
- // Set Policy Type
- policyParameters.setPolicyClass(PolicyClass.Decision); //required
- policyParameters.setPolicyName("MikeAPItests.testDecisionAPI"); //required
- policyParameters.setOnapName("java"); //required
- policyParameters.setPolicyDescription("This is a sample Decision policy UPDATE example with Settings"); //optional
- //policyParameters.setPolicyScope("MikeAPItests"); //Directory will be created where the Policies are saved... this displays a a subscope on the GUI
-
- //Set the Component Attributes... These are Optional
- Map<String, String> configAttributes = new HashMap<>();
- configAttributes.put("Template", "UpdateTemplate");
- configAttributes.put("controller", "default");
- configAttributes.put("SamPoll", "30");
- configAttributes.put("value", "abcd");
-
- Map<AttributeType, Map<String,String>> attributes = new HashMap<>();
- attributes.put(AttributeType.MATCHING, configAttributes);
-
- //Set the settings... These are Optional
- Map<String, String> settingsMap = new HashMap<>();
- settingsMap.put("server", "5");
-
- attributes.put(AttributeType.SETTINGS, settingsMap);
- policyParameters.setAttributes(attributes);
-
-
- List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
- List<String> dynamicRuleAlgorithmFunctions = new LinkedList<>();
- List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
- List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
-
- //Example of a complex Rule algorithm using the settings in the Field1
- /* label field1 function field2
- * *****************************************************
- * A1 S_server integer-equal 90
- * A2 cap string-contains ca
- * A3 cobal integer-equal 90
- * A4 A2 and A3
- * A5 Config integer-greater-than 45
- * A6 A4 ` or A5
- * A7 A1 and A6
- */
- dynamicRuleAlgorithmLabels = Arrays.asList("A1","A2","A3","A4","A5","A6","A7");
- dynamicRuleAlgorithmField1 = Arrays.asList("S_server","cap","cobal","A2","Config","A4","A1");
- dynamicRuleAlgorithmFunctions = Arrays.asList("integer-equal","string-contains","integer-equal","and","integer-greater-than","or","and");
- dynamicRuleAlgorithmField2 = Arrays.asList("90","ca","90","A3","45","A5","A6");
-
- policyParameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
- policyParameters.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
- policyParameters.setDynamicRuleAlgorithmFunctions(dynamicRuleAlgorithmFunctions);
- policyParameters.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
-
- policyParameters.setRequestID(UUID.randomUUID());
-
- // API method to create Policy or update policy
- PolicyChangeResponse response = null;
- if (!isEdit) {
- response = policyEngine.createPolicy(policyParameters);
- } else {
- response = policyEngine.updatePolicy(policyParameters);
- }
-
- if(response.getResponseCode()==200){
- System.out.println(response.getResponseMessage());
- System.out.println("Policy Created Successfully!");
- }else{
- System.out.println("Error! " + response.getResponseMessage());
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- }
+ static Boolean isEdit = true;
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ try {
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ PolicyParameters policyParameters = new PolicyParameters();
+ // Set Policy Type
+ policyParameters.setPolicyClass(PolicyClass.Decision); // required
+ policyParameters.setPolicyName("MikeAPItests.testDecisionAPI"); // required
+ policyParameters.setOnapName("java"); // required
+ policyParameters.setPolicyDescription(
+ "This is a sample Decision policy UPDATE example with Settings"); // optional
+ // policyParameters.setPolicyScope("MikeAPItests"); //Directory will be created where the Policies are
+ // saved... this displays a a subscope on the GUI
+
+ // Set the Component Attributes... These are Optional
+ Map<String, String> configAttributes = new HashMap<>();
+ configAttributes.put("Template", "UpdateTemplate");
+ configAttributes.put("controller", "default");
+ configAttributes.put("SamPoll", "30");
+ configAttributes.put("value", "abcd");
+
+ Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
+ attributes.put(AttributeType.MATCHING, configAttributes);
+
+ // Set the settings... These are Optional
+ Map<String, String> settingsMap = new HashMap<>();
+ settingsMap.put("server", "5");
+
+ attributes.put(AttributeType.SETTINGS, settingsMap);
+ policyParameters.setAttributes(attributes);
+
+ List<String> dynamicRuleAlgorithmLabels = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmFunctions = new LinkedList<>();
+ List<String> dynamicRuleAlgorithmField1 = new LinkedList<>();
+
+ // Example of a complex Rule algorithm using the settings in the Field1
+ /*
+ * label field1 function field2
+ * *****************************************************
+ * A1 S_server integer-equal 90
+ * A2 cap string-contains ca
+ * A3 cobal integer-equal 90
+ * A4 A2 and A3
+ * A5 Config integer-greater-than 45
+ * A6 A4 ` or A5
+ * A7 A1 and A6
+ */
+ dynamicRuleAlgorithmLabels = Arrays.asList("A1", "A2", "A3", "A4", "A5", "A6", "A7");
+ dynamicRuleAlgorithmField1 = Arrays.asList("S_server", "cap", "cobal", "A2", "Config", "A4", "A1");
+ dynamicRuleAlgorithmFunctions = Arrays.asList("integer-equal", "string-contains", "integer-equal", "and",
+ "integer-greater-than", "or", "and");
+ List<String> dynamicRuleAlgorithmField2 = new LinkedList<>();
+ dynamicRuleAlgorithmField2 = Arrays.asList("90", "ca", "90", "A3", "45", "A5", "A6");
+
+ policyParameters.setDynamicRuleAlgorithmLabels(dynamicRuleAlgorithmLabels);
+ policyParameters.setDynamicRuleAlgorithmField1(dynamicRuleAlgorithmField1);
+ policyParameters.setDynamicRuleAlgorithmFunctions(dynamicRuleAlgorithmFunctions);
+ policyParameters.setDynamicRuleAlgorithmField2(dynamicRuleAlgorithmField2);
+
+ policyParameters.setRequestID(UUID.randomUUID());
+
+ // API method to create Policy or update policy
+ PolicyChangeResponse response = null;
+ if (!isEdit) {
+ response = policyEngine.createPolicy(policyParameters);
+ } else {
+ response = policyEngine.updatePolicy(policyParameters);
+ }
+
+ if (response.getResponseCode() == 200) {
+ System.out.println(response.getResponseMessage());
+ System.out.println("Policy Created Successfully!");
+ } else {
+ System.out.println("Error! " + response.getResponseMessage());
+ }
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/DeletePolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/DeletePolicyClient.java
index c66067942..e411a4c6f 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/DeletePolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/DeletePolicyClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -27,36 +27,39 @@ import org.onap.policy.api.PolicyEngine;
public class DeletePolicyClient {
- public static void main(String[] args) {
- try {
-
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- DeletePolicyParameters policyParameters = new DeletePolicyParameters();
-
- //Parameter arguments
- policyParameters.setPolicyName("MikeConsole.Config_testDeleteAPI6.1.xml");
- policyParameters.setPolicyComponent("PDP");
- policyParameters.setPdpGroup("default");
- policyParameters.setDeleteCondition(DeletePolicyCondition.ALL);
- policyParameters.setRequestID(null);
-
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ try {
+ DeletePolicyParameters policyParameters = new DeletePolicyParameters();
+
+ // Parameter arguments
+ policyParameters.setPolicyName("MikeConsole.Config_testDeleteAPI6.1.xml");
+ policyParameters.setPolicyComponent("PDP");
+ policyParameters.setPdpGroup("default");
+ policyParameters.setDeleteCondition(DeletePolicyCondition.ALL);
+ policyParameters.setRequestID(null);
+
// API method to Push Policy to PDP
PolicyChangeResponse response = null;
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
response = policyEngine.deletePolicy(policyParameters);
- if(response.getResponseCode()==200){
+ if (response.getResponseCode() == 200) {
System.out.println(response.getResponseMessage());
System.out.println("Policy Deleted Successfully!");
- }else{
+ } else {
System.out.println("Error! " + response.getResponseMessage());
}
- } catch (Exception e) {
- System.err.println(e.getMessage());
-
- }
-
- }
-
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+
+ }
+
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/GeneralTestClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/GeneralTestClient.java
index 4c5a262df..77a12279a 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/GeneralTestClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/GeneralTestClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policyengine;
import java.io.FileNotFoundException;
@@ -43,347 +44,315 @@ import org.onap.policy.common.logging.flexlogger.Logger;
* Class reads from .testCases file and run the test cases available in the file
* and generates output for each test cases specifing whether is passed or fail
* and reason why it fails.
- *
- *
+ *
+ *
* @version 1.0
*
*/
public class GeneralTestClient {
-
- private static final Logger LOGGER = FlexLogger.getLogger(GeneralTestClient.class);
-
- static int totalTC = 0, passTC = 0, failTC = 0;
-
- public static void main(String[] args) {
- Path file;
- /* command line arguments */
- if (args.length != 0) {
- for (int index = 0; index < args.length; index++) {
- // System.out.println(args[index]);
- file = Paths.get(args[index]);
- runTestClientOnConfigFile(file);
- }
- } else {
- /* default file */
- file = Paths.get("input.testCases");
- runTestClientOnConfigFile(file);
- }
- System.out
- .println("###############################################################################################");
- System.out.println("\n\t SUMMARY: TOTAL: " + totalTC + ",\tPASS: "
- + passTC + ",\tFAIL: " + failTC + "\n");
- System.out
- .println("###############################################################################################");
-
- System.out.println("Enter a any key to exit");
- try {
- System.in.read();
- } catch (IOException e) {
- //
- }
-
- }
-
- /**
- * This function reads the files passed as arguments and runs the test cases
- * in the file
- *
- * @param file
- */
- private static void runTestClientOnConfigFile(Path file) {
- String resultReturned, onapComponentName;
- int totalTCforFile = 0, passTCforFile = 0, failTCforFile = 0;
- System.out
- .println("\n###############################################################################################");
- System.out.println("\tRuning test Client on Config file: " + file);
- System.out
- .println("###############################################################################################\n");
-
- if (Files.notExists(file)) {
- System.out.println("file doesnot exist");
- // throw new
- // PolicyEngineException("File doesn't exist in the specified Path "
- // + file.toString());
- } else if (file.toString().endsWith(".testCases")) {
- try {
- // read the json file
- FileReader reader = new FileReader(file.toString());
-
- JSONParser jsonParser = new JSONParser();
- JSONArray jsonObjectArray = (JSONArray) jsonParser
- .parse(reader);
- for (Object jsonObject : jsonObjectArray) {
- totalTC++;
- totalTCforFile++;
- ArrayList<String> expectedResult = new ArrayList<>();
- ArrayList<String> resultReceived = new ArrayList<>();
- JSONObject testCase = (JSONObject) jsonObject;
- // get a String from the JSON object
- long id = (long) testCase.get("id");
- String testFor = (String) testCase.get("testFor");
- String testCaseDescription = (String) testCase
- .get("testCaseDescription");
- JSONArray expectedResultJson = (JSONArray) testCase
- .get("expectedResult");
- @SuppressWarnings("rawtypes")
- Iterator i = expectedResultJson.iterator();
- while (i.hasNext()) {
- expectedResult.add((String) i.next());
- }
- String pdp_urlConfigFile = (String) testCase
- .get("PDP_URLConfigFile");
- // System.out.println(pdp_urlConfigFile);
- PolicyEngine policyEngine;
- try {
- policyEngine = new PolicyEngine(pdp_urlConfigFile);
-
- switch (testFor) {
-
- case "getConfig":
- onapComponentName = (String) testCase
- .get("ONAPName");
- String configName = (String) testCase
- .get("ConfigName");
- Map<String, String> configAttributes = new HashMap<>();
- configAttributes.put("key", "value");
- JSONArray configAttributesJSON = (JSONArray) testCase
- .get("configAttributes");
- if(configAttributesJSON!=null){
- i = configAttributesJSON.iterator();
- while (i.hasNext()) {
- JSONObject innerObj = (JSONObject) i.next();
- configAttributes.put(
- (String) innerObj.get("key"),
- (String) innerObj.get("value"));
-
- }
- }else{
- configAttributes = null;
- }
- resultReceived = PolicyEngineTestClient.getConfig(
- policyEngine, onapComponentName,
- configName, configAttributes);
- Collections.sort(expectedResult);
- Collections.sort(resultReceived);
- resultReturned = compareResults(expectedResult,resultReceived);
- if (resultReturned.equals("PASSED")) {
- printResult(id, testFor, testCaseDescription,
- "PASSED");
- passTCforFile++;
- passTC++;
- } else {
- printResult(id, testFor, testCaseDescription,
- "FAILED", resultReturned);
- failTCforFile++;
- failTC++;
- }
- break;
-
- case "getAction":
- Map<String, String> eventAttributes = new HashMap<>();
- eventAttributes.put("Key", "Value");
- JSONArray eventAttributesJSON = (JSONArray) testCase
- .get("eventAttributes");
- if(eventAttributesJSON != null){
- i = eventAttributesJSON.iterator();
- while (i.hasNext()) {
- JSONObject innerObj = (JSONObject) i.next();
- eventAttributes.put(
- (String) innerObj.get("key"),
- (String) innerObj.get("value"));
- }
- }else{
- eventAttributes=null;
- }
- resultReceived = PolicyEngineTestClient.getAction(
- policyEngine, eventAttributes);
- Collections.sort(expectedResult);
- Collections.sort(resultReceived);
- resultReturned = compareResults(expectedResult,
- resultReceived);
- if (resultReturned.equals("PASSED")) {
- printResult(id, testFor, testCaseDescription,
- "PASSED");
- passTCforFile++;
- passTC++;
- } else {
- printResult(id, testFor, testCaseDescription,
- "FAILED", resultReturned);
- failTCforFile++;
- failTC++;
- }
- break;
-
- case "getDecision":
- onapComponentName = (String) testCase
- .get("ONAPName");
- Map<String, String> decisionAttributes = new HashMap<>();
- decisionAttributes.put("Key", "Value");
- JSONArray decisionAttributesJSON = (JSONArray) testCase
- .get("decisionAttributes");
- i = decisionAttributesJSON.iterator();
- while (i.hasNext()) {
- JSONObject innerObj = (JSONObject) i.next();
- decisionAttributes.put(
- (String) innerObj.get("key"),
- (String) innerObj.get("value"));
-
- }
-
- resultReceived = PolicyEngineTestClient
- .getDecision(policyEngine,
- onapComponentName,
- decisionAttributes);
- Collections.sort(expectedResult);
- Collections.sort(resultReceived);
- resultReturned = compareResults(expectedResult,
- resultReceived);
- if (resultReturned.equals("PASSED")) {
- printResult(id, testFor, testCaseDescription,
- "PASSED");
- passTCforFile++;
- passTC++;
- } else {
- printResult(id, testFor, testCaseDescription,
- "FAILED", resultReturned);
- failTCforFile++;
- failTC++;
- }
- break;
-
- // case "getManualNotification":
- // PolicyEngineTestClient
- // .getManualNotifications(org.onap.policyEngine);
- // break;
- // case "getAutoNotification":
- // PolicyEngineTestClient
- // .getAutoNotifications(org.onap.policyEngine);
- // break;
-
- default:
- printResult(id, testFor, testCaseDescription,
- "FAILED", "\tINVAILD TEST CASE.");
- failTCforFile++;
- failTC++;
- break;
-
- }
- } catch (PolicyEngineException e) {
- printResult(id, testFor, testCaseDescription, "FAILED");
- failTCforFile++;
- failTC++;
- LOGGER.error("Exception Occured"+e);
- } catch (Exception e) {
- printResult(id, testFor, testCaseDescription, "FAILED");
- failTCforFile++;
- failTC++;
- LOGGER.error("Exception Occured"+e);
- }
- }
-
- } catch (FileNotFoundException ex) {
- LOGGER.error("Exception Occured due to File not found"+ex);
- } catch (IOException ex) {
- LOGGER.error("Exception Occured"+ex);
- } catch (NullPointerException ex) {
- LOGGER.error("Exception Occured due to Null Pointer"+ex);
- } catch (org.json.simple.parser.ParseException e) {
- LOGGER.error("Exception Occured while Parsing"+e);
- }
- }
- System.out.println("\n\n\t Summary for the file: TOTAL: "
- + totalTCforFile + ",\tPASS: " + passTCforFile + ",\tFAIL: "
- + failTCforFile + "\n");
- }
-
- /**
- * This function prints the reason if test fails.
- *
- * @param id
- * @param testFor
- * @param testCaseDescription
- * @param passFail
- * @param resultReturned
- */
- private static void printResult(long id, String testFor,
- String testCaseDescription, String passFail, String resultReturned) {
- // TODO Auto-generated method stub
- printResult(id, testFor, testCaseDescription, passFail);
- System.out.println(resultReturned);
-
- }
-
- /**
- * This function prints in output in required format.
- *
- * @param id
- * @param testFor
- * @param testCaseDescription
- * @param result
- */
- private static void printResult(long id, String testFor,
- String testCaseDescription, String result) {
- System.out.println(result + " - Test Case " + id + " - Test type: "
- + testFor + " - " + testCaseDescription);
- }
-
- /**
- * This function compares the required expected output and received output
- * and returns PASS if expected output and received output matches
- *
- * @param expectedResult
- * @param resultReceived
- * @return
- */
- private static String compareResults(ArrayList<String> expectedResult,
- ArrayList<String> resultReceived) {
- // TODO Auto-generated method stub
- String returnString = "";
- int index;
-// System.out.println(expectedResult.size());
-// System.out.println(resultReceived.size());
- for (index = 0; index < expectedResult.size()
- || index < resultReceived.size(); index++) {
- if (index < expectedResult.size() && index < resultReceived.size()) {
- if (!expectedResult.get(index)
- .equals(resultReceived.get(index))) {
- //returnString = "FAILED";
- returnString += "\tExpected Output: "
- + expectedResult.get(index)
- + ",\n\tOutput Received: "
- + resultReceived.get(index)+"\n";
-//
- //System.out.println(resultReceived.get(index));
- }
-
- } else {
- if (index >= expectedResult.size()) {
- returnString += "\tExpected Size of output: "
- + expectedResult.size()
- + ", Size of output received: "
- + resultReceived.size()
- + "\n\tExpected Output: none,\n\tOutput Received: "
- + resultReceived.get(index)+"\n";
-
- } else {
- if (index >= resultReceived.size()) {
- returnString += "\tExpected Size of output: "
- + expectedResult.size()
- + ", Size of output received: "
- + resultReceived.size()
- + "\n\tExpected Output: "
- + expectedResult.get(index)
- + ",\n\tOutput Received: none\n";
-
- }
- }
- }
-
- }
- if(index==expectedResult.size() && index==resultReceived.size() && returnString.equals("")){
- returnString="PASSED";
- }
- return returnString;
-
- }
+
+ private static final Logger LOGGER = FlexLogger.getLogger(GeneralTestClient.class);
+
+ static int totalTC = 0;
+ static int passTC = 0;
+ static int failTC = 0;
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ Path file;
+ /* command line arguments */
+ if (args.length != 0) {
+ for (int index = 0; index < args.length; index++) {
+ // System.out.println(args[index]);
+ file = Paths.get(args[index]);
+ runTestClientOnConfigFile(file);
+ }
+ } else {
+ /* default file */
+ file = Paths.get("input.testCases");
+ runTestClientOnConfigFile(file);
+ }
+ System.out.println(
+ "###############################################################################################");
+ System.out.println("\n\t SUMMARY: TOTAL: " + totalTC + ",\tPASS: " + passTC + ",\tFAIL: " + failTC + "\n");
+ System.out.println(
+ "###############################################################################################");
+
+ System.out.println("Enter a any key to exit");
+ try {
+ System.in.read();
+ } catch (IOException e) {
+ //
+ }
+
+ }
+
+ /**
+ * This function reads the files passed as arguments and runs the test cases
+ * in the file.
+ *
+ * @param file Path
+ */
+ private static void runTestClientOnConfigFile(Path file) {
+ String resultReturned;
+ String onapComponentName;
+ int totalTCforFile = 0;
+ int passTCforFile = 0;
+ int failTCforFile = 0;
+ System.out.println(
+ "\n###############################################################################################");
+ System.out.println("\tRuning test Client on Config file: " + file);
+ System.out.println(
+ "###############################################################################################\n");
+
+ if (Files.notExists(file)) {
+ System.out.println("file doesnot exist");
+ // throw new
+ // PolicyEngineException("File doesn't exist in the specified Path "
+ // + file.toString());
+ } else if (file.toString().endsWith(".testCases")) {
+ try {
+ // read the json file
+ FileReader reader = new FileReader(file.toString());
+
+ JSONParser jsonParser = new JSONParser();
+ JSONArray jsonObjectArray = (JSONArray) jsonParser.parse(reader);
+ for (Object jsonObject : jsonObjectArray) {
+ totalTC++;
+ totalTCforFile++;
+ ArrayList<String> expectedResult = new ArrayList<>();
+ ArrayList<String> resultReceived = new ArrayList<>();
+ JSONObject testCase = (JSONObject) jsonObject;
+ // get a String from the JSON object
+ long id = (long) testCase.get("id");
+ String testFor = (String) testCase.get("testFor");
+ String testCaseDescription = (String) testCase.get("testCaseDescription");
+ JSONArray expectedResultJson = (JSONArray) testCase.get("expectedResult");
+ @SuppressWarnings("rawtypes")
+ Iterator iter = expectedResultJson.iterator();
+ while (iter.hasNext()) {
+ expectedResult.add((String) iter.next());
+ }
+ String pdpUrlConfigFile = (String) testCase.get("PDP_URLConfigFile");
+ // System.out.println(pdp_urlConfigFile);
+ PolicyEngine policyEngine;
+ try {
+ policyEngine = new PolicyEngine(pdpUrlConfigFile);
+
+ switch (testFor) {
+
+ case "getConfig":
+ onapComponentName = (String) testCase.get("ONAPName");
+ String configName = (String) testCase.get("ConfigName");
+ Map<String, String> configAttributes = new HashMap<>();
+ configAttributes.put("key", "value");
+ JSONArray configAttributesJson = (JSONArray) testCase.get("configAttributes");
+ if (configAttributesJson != null) {
+ iter = configAttributesJson.iterator();
+ while (iter.hasNext()) {
+ JSONObject innerObj = (JSONObject) iter.next();
+ configAttributes.put((String) innerObj.get("key"),
+ (String) innerObj.get("value"));
+
+ }
+ } else {
+ configAttributes = null;
+ }
+ resultReceived = PolicyEngineTestClient.getConfig(policyEngine, onapComponentName,
+ configName, configAttributes);
+ Collections.sort(expectedResult);
+ Collections.sort(resultReceived);
+ resultReturned = compareResults(expectedResult, resultReceived);
+ if (resultReturned.equals("PASSED")) {
+ printResult(id, testFor, testCaseDescription, "PASSED");
+ passTCforFile++;
+ passTC++;
+ } else {
+ printResult(id, testFor, testCaseDescription, "FAILED", resultReturned);
+ failTCforFile++;
+ failTC++;
+ }
+ break;
+
+ case "getAction":
+ Map<String, String> eventAttributes = new HashMap<>();
+ eventAttributes.put("Key", "Value");
+ JSONArray eventAttributesJson = (JSONArray) testCase.get("eventAttributes");
+ if (eventAttributesJson != null) {
+ iter = eventAttributesJson.iterator();
+ while (iter.hasNext()) {
+ JSONObject innerObj = (JSONObject) iter.next();
+ eventAttributes.put((String) innerObj.get("key"),
+ (String) innerObj.get("value"));
+ }
+ } else {
+ eventAttributes = null;
+ }
+ resultReceived = PolicyEngineTestClient.getAction(policyEngine, eventAttributes);
+ Collections.sort(expectedResult);
+ Collections.sort(resultReceived);
+ resultReturned = compareResults(expectedResult, resultReceived);
+ if (resultReturned.equals("PASSED")) {
+ printResult(id, testFor, testCaseDescription, "PASSED");
+ passTCforFile++;
+ passTC++;
+ } else {
+ printResult(id, testFor, testCaseDescription, "FAILED", resultReturned);
+ failTCforFile++;
+ failTC++;
+ }
+ break;
+
+ case "getDecision":
+ onapComponentName = (String) testCase.get("ONAPName");
+ Map<String, String> decisionAttributes = new HashMap<>();
+ decisionAttributes.put("Key", "Value");
+ JSONArray decisionAttributesJson = (JSONArray) testCase.get("decisionAttributes");
+ iter = decisionAttributesJson.iterator();
+ while (iter.hasNext()) {
+ JSONObject innerObj = (JSONObject) iter.next();
+ decisionAttributes.put((String) innerObj.get("key"),
+ (String) innerObj.get("value"));
+
+ }
+
+ resultReceived = PolicyEngineTestClient.getDecision(policyEngine, onapComponentName,
+ decisionAttributes);
+ Collections.sort(expectedResult);
+ Collections.sort(resultReceived);
+ resultReturned = compareResults(expectedResult, resultReceived);
+ if (resultReturned.equals("PASSED")) {
+ printResult(id, testFor, testCaseDescription, "PASSED");
+ passTCforFile++;
+ passTC++;
+ } else {
+ printResult(id, testFor, testCaseDescription, "FAILED", resultReturned);
+ failTCforFile++;
+ failTC++;
+ }
+ break;
+
+ // case "getManualNotification":
+ // PolicyEngineTestClient
+ // .getManualNotifications(org.onap.policyEngine);
+ // break;
+ // case "getAutoNotification":
+ // PolicyEngineTestClient
+ // .getAutoNotifications(org.onap.policyEngine);
+ // break;
+
+ default:
+ printResult(id, testFor, testCaseDescription, "FAILED", "\tINVAILD TEST CASE.");
+ failTCforFile++;
+ failTC++;
+ break;
+
+ }
+ } catch (PolicyEngineException e) {
+ printResult(id, testFor, testCaseDescription, "FAILED");
+ failTCforFile++;
+ failTC++;
+ LOGGER.error("Exception Occured" + e);
+ } catch (Exception e) {
+ printResult(id, testFor, testCaseDescription, "FAILED");
+ failTCforFile++;
+ failTC++;
+ LOGGER.error("Exception Occured" + e);
+ }
+ }
+
+ } catch (FileNotFoundException ex) {
+ LOGGER.error("Exception Occured due to File not found" + ex);
+ } catch (IOException ex) {
+ LOGGER.error("Exception Occured" + ex);
+ } catch (NullPointerException ex) {
+ LOGGER.error("Exception Occured due to Null Pointer" + ex);
+ } catch (org.json.simple.parser.ParseException e) {
+ LOGGER.error("Exception Occured while Parsing" + e);
+ }
+ }
+ System.out.println("\n\n\t Summary for the file: TOTAL: " + totalTCforFile + ",\tPASS: " + passTCforFile
+ + ",\tFAIL: " + failTCforFile + "\n");
+ }
+
+ /**
+ * This function prints the reason if test fails.
+ *
+ * @param id long
+ * @param testFor String
+ * @param testCaseDescription String
+ * @param passFail String
+ * @param resultReturned String
+ */
+ private static void printResult(long id, String testFor, String testCaseDescription, String passFail,
+ String resultReturned) {
+ // TODO Auto-generated method stub
+ printResult(id, testFor, testCaseDescription, passFail);
+ System.out.println(resultReturned);
+
+ }
+
+ /**
+ * This function prints in output in required format.
+ *
+ * @param id long
+ * @param testFor String
+ * @param testCaseDescription String
+ * @param result String
+ */
+ private static void printResult(long id, String testFor, String testCaseDescription, String result) {
+ System.out.println(result + " - Test Case " + id + " - Test type: " + testFor + " - " + testCaseDescription);
+ }
+
+ /**
+ * This function compares the required expected output and received output
+ * and returns PASS if expected output and received output matches.
+ *
+ * @param expectedResult ArrayList of Strings
+ * @param resultReceived ArrayList of Strings
+ * @return String
+ */
+ private static String compareResults(ArrayList<String> expectedResult, ArrayList<String> resultReceived) {
+ // TODO Auto-generated method stub
+ String returnString = "";
+ int index;
+ // System.out.println(expectedResult.size());
+ // System.out.println(resultReceived.size());
+ for (index = 0; index < expectedResult.size() || index < resultReceived.size(); index++) {
+ if (index < expectedResult.size() && index < resultReceived.size()) {
+ if (!expectedResult.get(index).equals(resultReceived.get(index))) {
+ // returnString = "FAILED";
+ returnString += "\tExpected Output: " + expectedResult.get(index) + ",\n\tOutput Received: "
+ + resultReceived.get(index) + "\n";
+ //
+ // System.out.println(resultReceived.get(index));
+ }
+
+ } else {
+ if (index >= expectedResult.size()) {
+ returnString += "\tExpected Size of output: " + expectedResult.size()
+ + ", Size of output received: " + resultReceived.size()
+ + "\n\tExpected Output: none,\n\tOutput Received: " + resultReceived.get(index) + "\n";
+
+ } else {
+ if (index >= resultReceived.size()) {
+ returnString += "\tExpected Size of output: " + expectedResult.size()
+ + ", Size of output received: " + resultReceived.size() + "\n\tExpected Output: "
+ + expectedResult.get(index) + ",\n\tOutput Received: none\n";
+
+ }
+ }
+ }
+
+ }
+ if (index == expectedResult.size() && index == resultReceived.size() && returnString.equals("")) {
+ returnString = "PASSED";
+ }
+ return returnString;
+
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/GetConfigSample.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/GetConfigSample.java
index 94cc69fd7..033eccaad 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/GetConfigSample.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/GetConfigSample.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -28,14 +28,19 @@ import org.onap.policy.api.PolicyEngine;
public class GetConfigSample {
- public static void main(String[] args) throws Exception {
- PolicyEngine pe = new PolicyEngine("config.properties");
- ConfigRequestParameters configRequestParams = new ConfigRequestParameters();
- configRequestParams.setPolicyName(".*");
- Collection<PolicyConfig> configs = pe.getConfig(configRequestParams);
- for (PolicyConfig config: configs){
- System.out.println(config.getPolicyConfigMessage());
- System.out.println(config.getPolicyConfigStatus());
- }
- }
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) throws Exception {
+ PolicyEngine pe = new PolicyEngine("config.properties");
+ ConfigRequestParameters configRequestParams = new ConfigRequestParameters();
+ configRequestParams.setPolicyName(".*");
+ Collection<PolicyConfig> configs = pe.getConfig(configRequestParams);
+ for (PolicyConfig config : configs) {
+ System.out.println(config.getPolicyConfigMessage());
+ System.out.println(config.getPolicyConfigStatus());
+ }
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/Handler.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/Handler.java
index 12fca6e93..243c86021 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/Handler.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/Handler.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -35,93 +35,93 @@ import org.onap.policy.api.RemovedPolicy;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
-public class Handler implements NotificationHandler{
+public class Handler implements NotificationHandler {
- private static final Logger LOGGER = FlexLogger.getLogger(Handler.class);
-
- @Override
- public void notificationReceived(PDPNotification notification) {
- System.out.println("Notification Received...");
- System.out.println(notification.getNotificationType());
- if(notification.getNotificationType().equals(NotificationType.REMOVE)){
- System.out.println("Removed Policies: \n");
- for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){
- System.out.println(removedPolicy.getPolicyName());
- System.out.println(removedPolicy.getVersionNo());
- }
- }else if(notification.getNotificationType().equals(NotificationType.UPDATE)){
- System.out.println("Updated Policies: \n");
- for(LoadedPolicy updatedPolicy: notification.getLoadedPolicies()){
- System.out.println("policyName : " + updatedPolicy.getPolicyName());
- System.out.println("policyVersion :" + updatedPolicy.getVersionNo());
- if(updatedPolicy.getPolicyName().contains(".Config_")){
- System.out.println("Matches: " + updatedPolicy.getMatches());
- System.out.println("UpdateType: "+ updatedPolicy.getUpdateType());
- // Checking the Name is correct or not.
- try {
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- @SuppressWarnings("deprecation")
- Collection<PolicyConfig> policyConfigs = policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName());
- for(PolicyConfig policyConfig: policyConfigs){
- if(policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)){
- System.out.println("Policy Retrieved with this Name notified. ");
- }else{
- System.err.println("\n\n Fail to retrieve policy !!!!\n\n");
- }
- // Also Test this case.
- if(policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())){
- System.out.println("Policy Name is good. ");
- }else{
- System.err.println("\n\n Fail to check Name \n\n");
- }
- }
- } catch (PolicyEngineException e) {
- LOGGER.error("Exception Occured"+e);
- } catch (PolicyConfigException e) {
- LOGGER.error("Exception Occured"+e);
- }
- }
- }
- }else if(notification.getNotificationType().equals(NotificationType.BOTH)){
- System.out.println("Both updated and Removed Notification: \n");
- System.out.println("Removed Policies: \n");
- for(RemovedPolicy removedPolicy: notification.getRemovedPolicies()){
- System.out.println(removedPolicy.getPolicyName());
- System.out.println(removedPolicy.getVersionNo());
- }
- System.out.println("Updated Policies: \n");
- for(LoadedPolicy updatedPolicy: notification.getLoadedPolicies()){
- System.out.println("policyName : " + updatedPolicy.getPolicyName());
- System.out.println("policyVersion :" + updatedPolicy.getVersionNo());
- System.out.println("Matches: " + updatedPolicy.getMatches());
- System.out.println("UpdateType: "+ updatedPolicy.getUpdateType());
- // Checking the Name is correct or not.
- try {
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- @SuppressWarnings("deprecation")
- Collection<PolicyConfig> policyConfigs = policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName());
- for(PolicyConfig policyConfig: policyConfigs){
- if(policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)){
- System.out.println("Policy Retrieved with this Name notified. ");
- }else{
- System.err.println("\n\n Fail to retrieve policy !!!!\n\n");
- }
- // Also Test this case.
- if(policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())){
- System.out.println("Policy Name is good. ");
- }else{
- System.err.println("\n\n Fail to check Name \n\n");
- }
- }
- } catch (PolicyEngineException e) {
- LOGGER.error("Exception Occured"+e);
- } catch (PolicyConfigException e) {
- LOGGER.error("Exception Occured"+e);
- }
- }
- }
- }
+ private static final Logger LOGGER = FlexLogger.getLogger(Handler.class);
+
+ @Override
+ public void notificationReceived(PDPNotification notification) {
+ System.out.println("Notification Received...");
+ System.out.println(notification.getNotificationType());
+ if (notification.getNotificationType().equals(NotificationType.REMOVE)) {
+ System.out.println("Removed Policies: \n");
+ for (RemovedPolicy removedPolicy : notification.getRemovedPolicies()) {
+ System.out.println(removedPolicy.getPolicyName());
+ System.out.println(removedPolicy.getVersionNo());
+ }
+ } else if (notification.getNotificationType().equals(NotificationType.UPDATE)) {
+ System.out.println("Updated Policies: \n");
+ for (LoadedPolicy updatedPolicy : notification.getLoadedPolicies()) {
+ System.out.println("policyName : " + updatedPolicy.getPolicyName());
+ System.out.println("policyVersion :" + updatedPolicy.getVersionNo());
+ if (updatedPolicy.getPolicyName().contains(".Config_")) {
+ System.out.println("Matches: " + updatedPolicy.getMatches());
+ System.out.println("UpdateType: " + updatedPolicy.getUpdateType());
+ // Checking the Name is correct or not.
+ try {
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ @SuppressWarnings("deprecation")
+ Collection<PolicyConfig> policyConfigs =
+ policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName());
+ for (PolicyConfig policyConfig : policyConfigs) {
+ if (policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)) {
+ System.out.println("Policy Retrieved with this Name notified. ");
+ } else {
+ System.err.println("\n\n Fail to retrieve policy !!!!\n\n");
+ }
+ // Also Test this case.
+ if (policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())) {
+ System.out.println("Policy Name is good. ");
+ } else {
+ System.err.println("\n\n Fail to check Name \n\n");
+ }
+ }
+ } catch (PolicyEngineException e) {
+ LOGGER.error("Exception Occured" + e);
+ } catch (PolicyConfigException e) {
+ LOGGER.error("Exception Occured" + e);
+ }
+ }
+ }
+ } else if (notification.getNotificationType().equals(NotificationType.BOTH)) {
+ System.out.println("Both updated and Removed Notification: \n");
+ System.out.println("Removed Policies: \n");
+ for (RemovedPolicy removedPolicy : notification.getRemovedPolicies()) {
+ System.out.println(removedPolicy.getPolicyName());
+ System.out.println(removedPolicy.getVersionNo());
+ }
+ System.out.println("Updated Policies: \n");
+ for (LoadedPolicy updatedPolicy : notification.getLoadedPolicies()) {
+ System.out.println("policyName : " + updatedPolicy.getPolicyName());
+ System.out.println("policyVersion :" + updatedPolicy.getVersionNo());
+ System.out.println("Matches: " + updatedPolicy.getMatches());
+ System.out.println("UpdateType: " + updatedPolicy.getUpdateType());
+ // Checking the Name is correct or not.
+ try {
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ @SuppressWarnings("deprecation")
+ Collection<PolicyConfig> policyConfigs =
+ policyEngine.getConfigByPolicyName(updatedPolicy.getPolicyName());
+ for (PolicyConfig policyConfig : policyConfigs) {
+ if (policyConfig.getPolicyConfigStatus().equals(PolicyConfigStatus.CONFIG_RETRIEVED)) {
+ System.out.println("Policy Retrieved with this Name notified. ");
+ } else {
+ System.err.println("\n\n Fail to retrieve policy !!!!\n\n");
+ }
+ // Also Test this case.
+ if (policyConfig.getPolicyName().equals(updatedPolicy.getPolicyName())) {
+ System.out.println("Policy Name is good. ");
+ } else {
+ System.err.println("\n\n Fail to check Name \n\n");
+ }
+ }
+ } catch (PolicyEngineException e) {
+ LOGGER.error("Exception Occured" + e);
+ } catch (PolicyConfigException e) {
+ LOGGER.error("Exception Occured" + e);
+ }
+ }
+ }
+ }
-
-
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ImportBRMSTemplate.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ImportBRMSTemplate.java
index 20175b28d..2e5f0e169 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/ImportBRMSTemplate.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ImportBRMSTemplate.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -24,27 +24,33 @@ import java.io.File;
import java.util.UUID;
import org.onap.policy.api.ImportParameters;
+import org.onap.policy.api.ImportParameters.IMPORT_TYPE;
import org.onap.policy.api.PolicyChangeResponse;
import org.onap.policy.api.PolicyEngine;
-import org.onap.policy.api.ImportParameters.IMPORT_TYPE;
public class ImportBRMSTemplate {
- public static void main(String[] args) {
- try{
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- ImportParameters importParameters = new ImportParameters();
- importParameters.setFilePath("testResources"+File.separator+"test.drl");
- importParameters.setServiceName("testTemplate");
- importParameters.setRequestID(UUID.randomUUID());
- importParameters.setServiceType(IMPORT_TYPE.BRMSPARAM);
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ try {
+ ImportParameters importParameters = new ImportParameters();
+ importParameters.setFilePath("testResources" + File.separator + "test.drl");
+ importParameters.setServiceName("testTemplate");
+ importParameters.setRequestID(UUID.randomUUID());
+ importParameters.setServiceType(IMPORT_TYPE.BRMSPARAM);
// API method to create Policy or update policy
- PolicyChangeResponse response = null;
+ PolicyChangeResponse response = null;
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
response = policyEngine.policyEngineImport(importParameters);
System.out.println(response.getResponseMessage());
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- }
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ImportMicroServiceClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ImportMicroServiceClient.java
index 86439583a..377dfcbb5 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/ImportMicroServiceClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ImportMicroServiceClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -28,26 +28,33 @@ import org.onap.policy.api.PolicyChangeResponse;
import org.onap.policy.api.PolicyEngine;
public class ImportMicroServiceClient {
- static Boolean isEdit = false;
- public static void main(String[] args) {
- try{
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- ImportParameters importParameters = new ImportParameters();
- importParameters.setFilePath("C:\\Workspaces\\models\\TestingModel\\ControllerServiceSampleSdnlServiceInstance-v0.1.0-SNAPSHOT.zip");
- importParameters.setServiceName("ControllerServiceSampleSdnlServiceInstance");
-
- importParameters.setRequestID(UUID.randomUUID());
- importParameters.setServiceType(IMPORT_TYPE.MICROSERVICE);
- importParameters.setVersion("1607-2");
+ static Boolean isEdit = false;
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ try {
+ ImportParameters importParameters = new ImportParameters();
+ importParameters.setFilePath(
+ "C:\\Workspaces\\models\\TestingModel\\ControllerServiceSampleSdnlServiceInstance-v0.1.0-SNAPSHOT.zip");
+ importParameters.setServiceName("ControllerServiceSampleSdnlServiceInstance");
+
+ importParameters.setRequestID(UUID.randomUUID());
+ importParameters.setServiceType(IMPORT_TYPE.MICROSERVICE);
+ importParameters.setVersion("1607-2");
// API method to create Policy or update policy
- PolicyChangeResponse response = null;
+ PolicyChangeResponse response = null;
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
response = policyEngine.policyEngineImport(importParameters);
System.out.println(response.getResponseMessage());
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- }
-
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
+
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ListConfigPoliciesClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ListConfigPoliciesClient.java
index 9973ce70c..c56a234ca 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/ListConfigPoliciesClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ListConfigPoliciesClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -33,44 +33,49 @@ import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
public class ListConfigPoliciesClient {
-
- private static final Logger LOGGER = FlexLogger.getLogger(ListConfigPoliciesClient.class);
-
- public static void main(String[] args) {
- PolicyEngine policyEngine;
- // List Config Policies Example
- try {
- policyEngine = new PolicyEngine("config.properties");
- ConfigRequestParameters parameters = new ConfigRequestParameters();
-
- parameters.setPolicyName(".*");
- parameters.setOnapName(".*");
- parameters.setConfigName(".*");
-
- Map<String, String> configAttributes = new HashMap<>();
- configAttributes.put("java", "java");
- configAttributes.put("peach", "Tar");
- configAttributes.put("true", "false");
- configAttributes.put("small", "testPass");
- parameters.setConfigAttributes(configAttributes);
-
- parameters.setRequestID(UUID.randomUUID());
-
- Collection<String> response = policyEngine.listConfig(parameters);
- if(response!=null && !response.contains("PE300")){
- for(String configList : response){
- System.out.println(configList.toString()+"\n");
- }
- }else{
- System.out.println("Error! " +response);
- }
+ private static final Logger LOGGER = FlexLogger.getLogger(ListConfigPoliciesClient.class);
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ PolicyEngine policyEngine;
+
+ // List Config Policies Example
+ try {
+ policyEngine = new PolicyEngine("config.properties");
+ ConfigRequestParameters parameters = new ConfigRequestParameters();
+
+ parameters.setPolicyName(".*");
+ parameters.setOnapName(".*");
+ parameters.setConfigName(".*");
+
+ Map<String, String> configAttributes = new HashMap<>();
+ configAttributes.put("java", "java");
+ configAttributes.put("peach", "Tar");
+ configAttributes.put("true", "false");
+ configAttributes.put("small", "testPass");
+ parameters.setConfigAttributes(configAttributes);
+
+ parameters.setRequestID(UUID.randomUUID());
+
+ Collection<String> response = policyEngine.listConfig(parameters);
+ if (response != null && !response.contains("PE300")) {
+ for (String configList : response) {
+ System.out.println(configList.toString() + "\n");
+ }
+ } else {
+ System.out.println("Error! " + response);
+ }
+
+ } catch (PolicyConfigException e) {
+ LOGGER.error("Exception Occured" + e);
+ } catch (PolicyEngineException e) {
+ LOGGER.error("Exception Occured" + e);
+ }
+ }
- } catch (PolicyConfigException e) {
- LOGGER.error("Exception Occured"+e);
- } catch (PolicyEngineException e) {
- LOGGER.error("Exception Occured"+e);
- }
- }
-
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/ListPolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/ListPolicyClient.java
index 785c44d11..d2e6d706b 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/ListPolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/ListPolicyClient.java
@@ -21,6 +21,7 @@
package org.onap.policyengine;
import java.util.Collection;
+
import org.onap.policy.api.ConfigNameRequest;
import org.onap.policy.api.PolicyEngine;
@@ -30,6 +31,12 @@ import org.onap.policy.api.PolicyEngine;
* (active version)
*/
public class ListPolicyClient {
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
public static void main(String[] args) throws Exception {
PolicyEngine pe = new PolicyEngine("config.properties");
ConfigNameRequest listPolicyParams = new ConfigNameRequest();
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/MainClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/MainClient.java
index 210499ca1..dfd06e51e 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/MainClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/MainClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -46,80 +46,93 @@ import org.onap.policy.common.logging.flexlogger.Logger;
import org.w3c.dom.Document;
public class MainClient {
-
- private static final Logger LOGGER = FlexLogger.getLogger(MainClient.class);
-
- public static void main(String[] args) {
- PolicyEngine policyEngine;
- try {
- policyEngine = new PolicyEngine("config.properties");
- Map<String, String> configAttributes = new HashMap<>();
- configAttributes.put("java", "java");
- configAttributes.put("peach", "Tar");
- configAttributes.put("true", "false");
- configAttributes.put("small", "testPass");
- Map<String, String> eventAttributes = new HashMap<>();
- eventAttributes.put("true", "true");
- eventAttributes.put("cpu", "91");
- Map<String, String> decisionAttributes = new HashMap<>();
- decisionAttributes.put("Key", "Value");
-
- // Config Example
- try {
- @SuppressWarnings("deprecation")
- Collection<PolicyConfig> policyConfigs = policyEngine.getConfigByPolicyName(".*");//(onapComponentName, configName, configAttributes);
- if(policyConfigs!=null && !policyConfigs.isEmpty()){
- for(PolicyConfig policyConfig: policyConfigs){
- System.out.println("\nConfig Message: "+ policyConfig.getPolicyConfigMessage());
- System.out.println("Config Status: " + policyConfig.getPolicyConfigStatus());
- System.out.println("Policy Name: "+ policyConfig.getPolicyName());
- System.out.println("policy Version: " + policyConfig.getPolicyVersion());
- }
- }
- } catch (PolicyConfigException e) {
- LOGGER.error("Exception Occured"+e);
- }
-
- // Manual Notifications..
- policyEngine.setScheme(NotificationScheme.MANUAL_ALL_NOTIFICATIONS);
- if(policyEngine.getNotification()!=null){
- System.out.println(policyEngine.getNotification().getNotificationType());
- for(LoadedPolicy updated: policyEngine.getNotification().getLoadedPolicies()){
- System.out.println(updated.getPolicyName());
- System.out.println(updated.getVersionNo());
- System.out.println(updated.getMatches());
- }
- for(RemovedPolicy removed: policyEngine.getNotification().getRemovedPolicies()){
- System.out.println(removed.getPolicyName());
- System.out.println(removed.getVersionNo());
- }
- }
- // Auto Notifications..
- Handler handler = new Handler();
- policyEngine.setNotification(NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler);
- //
- System.out.println("Enter a any key to exit");
- try {
- System.in.read();
- } catch (IOException e) {
- System.err.println("Exception Occured"+e);
- }
-
- } catch (PolicyEngineException e1) {
- System.err.println("Exception Occured"+e1);
- }
- }
-
- public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException {
- TransformerFactory tf = TransformerFactory.newInstance();
- Transformer transformer = tf.newTransformer();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
- transformer.setOutputProperty(OutputKeys.METHOD, "xml");
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
- transformer.transform(new DOMSource(doc),
- new StreamResult(new OutputStreamWriter(out, "UTF-8")));
- }
+ private static final Logger LOGGER = FlexLogger.getLogger(MainClient.class);
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ PolicyEngine policyEngine;
+ try {
+ policyEngine = new PolicyEngine("config.properties");
+ Map<String, String> configAttributes = new HashMap<>();
+ configAttributes.put("java", "java");
+ configAttributes.put("peach", "Tar");
+ configAttributes.put("true", "false");
+ configAttributes.put("small", "testPass");
+ Map<String, String> eventAttributes = new HashMap<>();
+ eventAttributes.put("true", "true");
+ eventAttributes.put("cpu", "91");
+ Map<String, String> decisionAttributes = new HashMap<>();
+ decisionAttributes.put("Key", "Value");
+
+ // Config Example
+ try {
+ @SuppressWarnings("deprecation")
+ Collection<PolicyConfig> policyConfigs = policyEngine.getConfigByPolicyName(".*");
+ if (policyConfigs != null && !policyConfigs.isEmpty()) {
+ for (PolicyConfig policyConfig : policyConfigs) {
+ System.out.println("\nConfig Message: " + policyConfig.getPolicyConfigMessage());
+ System.out.println("Config Status: " + policyConfig.getPolicyConfigStatus());
+ System.out.println("Policy Name: " + policyConfig.getPolicyName());
+ System.out.println("policy Version: " + policyConfig.getPolicyVersion());
+ }
+ }
+ } catch (PolicyConfigException e) {
+ LOGGER.error("Exception Occured" + e);
+ }
+
+ // Manual Notifications..
+ policyEngine.setScheme(NotificationScheme.MANUAL_ALL_NOTIFICATIONS);
+ if (policyEngine.getNotification() != null) {
+ System.out.println(policyEngine.getNotification().getNotificationType());
+ for (LoadedPolicy updated : policyEngine.getNotification().getLoadedPolicies()) {
+ System.out.println(updated.getPolicyName());
+ System.out.println(updated.getVersionNo());
+ System.out.println(updated.getMatches());
+ }
+ for (RemovedPolicy removed : policyEngine.getNotification().getRemovedPolicies()) {
+ System.out.println(removed.getPolicyName());
+ System.out.println(removed.getVersionNo());
+ }
+ }
+ // Auto Notifications..
+ Handler handler = new Handler();
+ policyEngine.setNotification(NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler);
+ //
+ System.out.println("Enter a any key to exit");
+ try {
+ System.in.read();
+ } catch (IOException e) {
+ System.err.println("Exception Occured" + e);
+ }
+
+ } catch (PolicyEngineException e1) {
+ System.err.println("Exception Occured" + e1);
+ }
+ }
+
+ /**
+ * printDocument.
+ *
+ * @param doc Document
+ * @param out OutputStream
+ * @throws IOException IOException
+ * @throws TransformerException TransformerException
+ */
+ public static void printDocument(Document doc, OutputStream out)
+ throws IOException, TransformerException {
+ TransformerFactory tf = TransformerFactory.newInstance();
+ Transformer transformer = tf.newTransformer();
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
+ transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
+
+ transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8")));
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/MicroServicesPolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/MicroServicesPolicyClient.java
index b05e44726..d592e7c5a 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/MicroServicesPolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/MicroServicesPolicyClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -31,6 +31,7 @@ import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
+
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
@@ -40,88 +41,89 @@ import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyEngine;
import org.onap.policy.api.PolicyParameters;
import org.onap.policy.api.PolicyType;
+
public class MicroServicesPolicyClient {
-
-//For updating a Micro Services policy set the "isEdit" flag to true.
-//For creating a Micro Services policy set the "isEdit" flag to false.
-static Boolean isEdit = false;
-
-//Builds JSONObject from File
-private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException {
- JsonObject json = null;;
- JsonReader jsonReader = null;
- if (jsonString != null && jsonInput == null) {
- StringReader in = null;
+
+ // For updating a Micro Services policy set the "isEdit" flag to true.
+ // For creating a Micro Services policy set the "isEdit" flag to false.
+ static Boolean isEdit = false;
+
+ // Builds JSONObject from File
+ private static JsonObject buildJson(File jsonInput, String jsonString) throws FileNotFoundException {
+ JsonObject json = null;;
+ JsonReader jsonReader = null;
+ if (jsonString != null && jsonInput == null) {
+ StringReader in = null;
in = new StringReader(jsonString);
jsonReader = Json.createReader(in);
json = jsonReader.readObject();
in.close();
+ } else {
+ InputStream in = null;
+ in = new FileInputStream(jsonInput);
+ jsonReader = Json.createReader(in);
+ json = jsonReader.readObject();
+ try {
+ in.close();
+ } catch (IOException e) {
+ System.err.println("Exception Occured while closing input stream" + e);
+ }
+ }
+ jsonReader.close();
+ return json;
}
- else {
- InputStream in = null;
- in = new FileInputStream(jsonInput);
- jsonReader = Json.createReader(in);
- json = jsonReader.readObject();
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
try {
- in.close();
- } catch (IOException e) {
- System.err.println("Exception Occured while closing input stream"+e);
- }
- }
- jsonReader.close();
- return json;
-}
-public static void main(String[] args) {
- try {
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- PolicyParameters policyParameters = new PolicyParameters();
- // Set Policy Type
- policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
- policyParameters.setPolicyName("Katrina.configuration_dcae_microservice_stringmatcher");
- //policyParameters.setPolicyDescription("This is a sample Micro Service policy Create example");
- policyParameters.setOnapName("DCAE");
- //policyParameters.setConfigName("Collector");
- //policyParameters.setPriority("1");
- //policyParameters.setPolicyScope("service=vSCP;resource=F5;type=configuration;closedLoopControlName=vSCP_F5_Firewall_d925ed73-8231-4d02-9545-db4e113213abab322");
-
- // Set up Micro Services Attributes
- File jsonFile = null;
- String MSjsonString= null;
- Path file = Paths.get("C:\\policyAPI\\MicroServicesJSON\\testStringMatching.json");
- jsonFile = file.toFile();
-
- policyParameters.setConfigBody(buildJSON(jsonFile, MSjsonString).toString());
- policyParameters.setConfigBodyType(PolicyType.JSON);
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ PolicyParameters policyParameters = new PolicyParameters();
+ // Set Policy Type
+ policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
+ policyParameters.setPolicyName("Katrina.configuration_dcae_microservice_stringmatcher");
+ policyParameters.setOnapName("DCAE");
+
+ // Set up Micro Services Attributes
+ File jsonFile = null;
+ String msJsonString = null;
+ Path file = Paths.get("C:\\policyAPI\\MicroServicesJSON\\testStringMatching.json");
+ jsonFile = file.toFile();
- policyParameters.setRequestID(UUID.randomUUID());
+ policyParameters.setConfigBody(buildJson(jsonFile, msJsonString).toString());
+ policyParameters.setConfigBodyType(PolicyType.JSON);
+
+ policyParameters.setRequestID(UUID.randomUUID());
+ // Set Safe Policy value for Risk Type
+ SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateformat3.parse("15/10/2016");
+ policyParameters.setTtlDate(date);
+ // Set Safe Policy value for Guard
+ policyParameters.setGuard(true);
+ // Set Safe Policy value for Risk Level
+ policyParameters.setRiskLevel("5");
// Set Safe Policy value for Risk Type
- SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateformat3.parse("15/10/2016");
- policyParameters.setTtlDate(date);
- // Set Safe Policy value for Guard
- policyParameters.setGuard(true);
- // Set Safe Policy value for Risk Level
- policyParameters.setRiskLevel("5");
- // Set Safe Policy value for Risk Type
- policyParameters.setRiskType("PROD");
-
- // API method to create or update Policy.
- PolicyChangeResponse response = null;
- if (!isEdit) {
- response = policyEngine.createPolicy(policyParameters);
- }
- else {
- response = policyEngine.updatePolicy(policyParameters);
- }
-
- if(response.getResponseCode()==200){
- System.out.println(response.getResponseMessage());
- System.out.println("Policy Created Successfully!");
- }else{
- System.out.println("Error! " + response.getResponseMessage());
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- }
+ policyParameters.setRiskType("PROD");
+
+ // API method to create or update Policy.
+ PolicyChangeResponse response = null;
+ if (!isEdit) {
+ response = policyEngine.createPolicy(policyParameters);
+ } else {
+ response = policyEngine.updatePolicy(policyParameters);
+ }
+
+ if (response.getResponseCode() == 200) {
+ System.out.println(response.getResponseMessage());
+ System.out.println("Policy Created Successfully!");
+ } else {
+ System.out.println("Error! " + response.getResponseMessage());
+ }
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/OptimizationPolicyJavaAPIClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/OptimizationPolicyJavaAPIClient.java
index 090ec39de..1d765c3c9 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/OptimizationPolicyJavaAPIClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/OptimizationPolicyJavaAPIClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -31,6 +31,7 @@ import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
+
import javax.json.Json;
import javax.json.JsonObject;
import javax.json.JsonReader;
@@ -40,89 +41,94 @@ import org.onap.policy.api.PolicyConfigType;
import org.onap.policy.api.PolicyEngine;
import org.onap.policy.api.PolicyParameters;
import org.onap.policy.api.PolicyType;
+
public class OptimizationPolicyJavaAPIClient {
-
-/*
- * THIS IS AN EXAMPLE JAVA CLIENT API FOR CREATE/UPDATE Optimization Policies
- */
-//For updating a Optmization policy set the "isEdit" flag to true.
-//For creating a Optmization policy set the "isEdit" flag to false.
-static Boolean isEdit = false;
-
-//Builds JSONObject from File
-private static JsonObject buildJSON(File jsonInput, String jsonString) throws FileNotFoundException {
- JsonObject json = null;;
- JsonReader jsonReader = null;
- if (jsonString != null && jsonInput == null) {
- StringReader in = null;
+
+ /*
+ * THIS IS AN EXAMPLE JAVA CLIENT API FOR CREATE/UPDATE Optimization Policies
+ */
+ // For updating a Optmization policy set the "isEdit" flag to true.
+ // For creating a Optmization policy set the "isEdit" flag to false.
+ static Boolean isEdit = false;
+
+ // Builds JSONObject from File
+ private static JsonObject buildJson(File jsonInput, String jsonString) throws FileNotFoundException {
+ JsonObject json = null;;
+ JsonReader jsonReader = null;
+ if (jsonString != null && jsonInput == null) {
+ StringReader in = null;
in = new StringReader(jsonString);
jsonReader = Json.createReader(in);
json = jsonReader.readObject();
in.close();
+ } else {
+ InputStream in = null;
+ in = new FileInputStream(jsonInput);
+ jsonReader = Json.createReader(in);
+ json = jsonReader.readObject();
+ try {
+ in.close();
+ } catch (IOException e) {
+ System.err.println("Exception Occured while closing input stream" + e);
+ }
+ }
+ jsonReader.close();
+ return json;
}
- else {
- InputStream in = null;
- in = new FileInputStream(jsonInput);
- jsonReader = Json.createReader(in);
- json = jsonReader.readObject();
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
try {
- in.close();
- } catch (IOException e) {
- System.err.println("Exception Occured while closing input stream"+e);
- }
- }
- jsonReader.close();
- return json;
-}
-public static void main(String[] args) {
- try {
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- PolicyParameters policyParameters = new PolicyParameters();
- // Set Policy Type
- policyParameters.setPolicyConfigType(PolicyConfigType.Optimization);
- policyParameters.setPolicyName("Mike.testOOFPolicyFromJavaClient");
- policyParameters.setPolicyDescription("This is a sample Optimization policy");
- policyParameters.setOnapName("OOF");
+ PolicyEngine policyEngine = new PolicyEngine("config.properties");
+ PolicyParameters policyParameters = new PolicyParameters();
+ // Set Policy Type
+ policyParameters.setPolicyConfigType(PolicyConfigType.Optimization);
+ policyParameters.setPolicyName("Mike.testOOFPolicyFromJavaClient");
+ policyParameters.setPolicyDescription("This is a sample Optimization policy");
+ policyParameters.setOnapName("OOF");
+
+ File jsonFile = null;
+ String oofJsonString = null;
+
+ // path where you store the json payload
+ Path file = Paths.get("/home/users/PolicyEngine/json/optimizationPolicy.json");
+ jsonFile = file.toFile();
- File jsonFile = null;
- String OOFjsonString= null;
-
- //path where you store the json payload
- Path file = Paths.get("/home/users/PolicyEngine/json/optimizationPolicy.json");
- jsonFile = file.toFile();
-
- policyParameters.setConfigBody(buildJSON(jsonFile, OOFjsonString).toString());
- policyParameters.setConfigBodyType(PolicyType.JSON);
+ policyParameters.setConfigBody(buildJson(jsonFile, oofJsonString).toString());
+ policyParameters.setConfigBodyType(PolicyType.JSON);
- policyParameters.setRequestID(UUID.randomUUID());
+ policyParameters.setRequestID(UUID.randomUUID());
// Set Safe Policy value for Risk Type
- SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
- Date date = dateformat3.parse("15/10/2016");
- policyParameters.setTtlDate(date);
- // Set Safe Policy value for Guard
- policyParameters.setGuard(false);
- // Set Safe Policy value for Risk Level
- policyParameters.setRiskLevel("5");
- // Set Safe Policy value for Risk Type
- policyParameters.setRiskType("TEST");
-
- // API method to create or update Policy.
- PolicyChangeResponse response = null;
- if (!isEdit) {
- response = policyEngine.createPolicy(policyParameters);
- }
- else {
- response = policyEngine.updatePolicy(policyParameters);
- }
-
- if(response.getResponseCode()==200){
- System.out.println(response.getResponseMessage());
- System.out.println("Policy Created Successfully!");
- }else{
- System.out.println("Error! " + response.getResponseMessage());
- }
- } catch (Exception e) {
- System.err.println(e.getMessage());
- }
- }
+ SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
+ Date date = dateformat3.parse("15/10/2016");
+ policyParameters.setTtlDate(date);
+ // Set Safe Policy value for Guard
+ policyParameters.setGuard(false);
+ // Set Safe Policy value for Risk Level
+ policyParameters.setRiskLevel("5");
+ // Set Safe Policy value for Risk Type
+ policyParameters.setRiskType("TEST");
+
+ // API method to create or update Policy.
+ PolicyChangeResponse response = null;
+ if (!isEdit) {
+ response = policyEngine.createPolicy(policyParameters);
+ } else {
+ response = policyEngine.updatePolicy(policyParameters);
+ }
+
+ if (response.getResponseCode() == 200) {
+ System.out.println(response.getResponseMessage());
+ System.out.println("Policy Created Successfully!");
+ } else {
+ System.out.println("Error! " + response.getResponseMessage());
+ }
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/PolicyEngineTestClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/PolicyEngineTestClient.java
index 9ce4a2a22..9e055ebb1 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/PolicyEngineTestClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/PolicyEngineTestClient.java
@@ -7,9 +7,9 @@
* Licensed 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.
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.policyengine;
import java.io.IOException;
@@ -39,155 +40,143 @@ import org.onap.policy.api.RemovedPolicy;
/**
* Class contains static functions which make call to policy engine using API.
* This class is used by generalTestClient.java
- *
- *
+ *
+ *
* @version 1.0
*
*/
public class PolicyEngineTestClient {
- /**
- * This fuction make API call to policy engine to get config. And returns
- * policy name, policy version and policy configStatus
- *
- * @param org.onap.policyEngine
- * @param onapComponentName
- * @param configName
- * @param configAttributes
- * @return
- */
+ /**
+ * This function make API call to policy engine to get config. And returns
+ * policy name, policy version and policy configStatus
+ *
+ * @param policyEngine Policy Engine object
+ * @param onapComponentName String
+ * @param configName String
+ * @param configAttributes Map of String to String
+ * @return ArrayList of String
+ */
+
+ @SuppressWarnings("deprecation")
+ public static ArrayList<String> getConfig(PolicyEngine policyEngine, String onapComponentName, String configName,
+ Map<String, String> configAttributes) {
+ ArrayList<String> resultReceived = new ArrayList<>();
+ try {
+ UUID requestID = UUID.randomUUID();
+ Collection<PolicyConfig> policyConfigs;
+ if (configName == null) {
+ policyConfigs = policyEngine.getConfig(onapComponentName, requestID);
+ } else {
+ if (configAttributes == null) {
+ policyConfigs = policyEngine.getConfig(onapComponentName, configName, requestID);
+ } else {
- @SuppressWarnings("deprecation")
- public static ArrayList<String> getConfig(PolicyEngine policyEngine,
- String onapComponentName, String configName,
- Map<String, String> configAttributes) {
- ArrayList<String> resultReceived = new ArrayList<>();
- try {
- UUID requestID = UUID.randomUUID();
- Collection<PolicyConfig> policyConfigs;
- if (configName == null) {
- policyConfigs = policyEngine.getConfig(onapComponentName, requestID);
- } else {
- if (configAttributes == null) {
- policyConfigs = policyEngine.getConfig(onapComponentName,
- configName, requestID);
- } else {
-
- policyConfigs = policyEngine.getConfig(onapComponentName,
- configName, configAttributes, requestID);
- }
- }
- if (policyConfigs != null && !policyConfigs.isEmpty()) {
- for (PolicyConfig policyConfig : policyConfigs) {
- resultReceived.add("Policy Name: "
- + policyConfig.getPolicyName()
- + " Policy version: "
- + policyConfig.getPolicyVersion() + " - "
- + policyConfig.getPolicyConfigStatus());
- }
- }
- } catch (PolicyConfigException e) {
-// logger.error("Exception Occured"+e);
- resultReceived.add(""+e);
- }
- return resultReceived;
- }
+ policyConfigs = policyEngine.getConfig(onapComponentName, configName, configAttributes, requestID);
+ }
+ }
+ if (policyConfigs != null && !policyConfigs.isEmpty()) {
+ for (PolicyConfig policyConfig : policyConfigs) {
+ resultReceived.add("Policy Name: " + policyConfig.getPolicyName() + " Policy version: "
+ + policyConfig.getPolicyVersion() + " - " + policyConfig.getPolicyConfigStatus());
+ }
+ }
+ } catch (PolicyConfigException e) {
+ // logger.error("Exception Occured"+e);
+ resultReceived.add("" + e);
+ }
+ return resultReceived;
+ }
- /**
- * This functions make API call to policy engine to get decision. And
- * returns policy Decision
- *
- * @param org.onap.policyEngine
- * @param onapComponentName
- * @param decisionAttributes
- * @return
- */
- public static ArrayList<String> getDecision(PolicyEngine policyEngine,
- String onapComponentName, Map<String, String> decisionAttributes) {
- ArrayList<String> resultReceived = new ArrayList<>();
- // Decision example
- try {
- UUID requestID = UUID.randomUUID();
- @SuppressWarnings("deprecation")
- DecisionResponse policyDecision = policyEngine.getDecision(
- onapComponentName, decisionAttributes, requestID);
- resultReceived.add(policyDecision.getDecision().toString());
- } catch (PolicyDecisionException e) {
-// logger.error("Exception Occured"+e);
- resultReceived.add(""+e);
- }
- return resultReceived;
- }
+ /**
+ * This functions make API call to policy engine to get decision. And
+ * returns policy Decision
+ *
+ * @param policyEngine Policy Engine
+ * @param onapComponentName String
+ * @param decisionAttributes Map of String
+ * @return List of String
+ */
+ public static ArrayList<String> getDecision(PolicyEngine policyEngine, String onapComponentName,
+ Map<String, String> decisionAttributes) {
+ ArrayList<String> resultReceived = new ArrayList<>();
+ // Decision example
+ try {
+ UUID requestID = UUID.randomUUID();
+ @SuppressWarnings("deprecation")
+ DecisionResponse policyDecision =
+ policyEngine.getDecision(onapComponentName, decisionAttributes, requestID);
+ resultReceived.add(policyDecision.getDecision().toString());
+ } catch (PolicyDecisionException e) {
+ // logger.error("Exception Occured"+e);
+ resultReceived.add("" + e);
+ }
+ return resultReceived;
+ }
- /**
- * This function makes API call to policy engine to get action. And returns
- * responseMessage and responseStatus
- *
- * @param org.onap.policyEngine
- * @param eventAttributes
- * @return
- */
- public static ArrayList<String> getAction(PolicyEngine policyEngine,
- Map<String, String> eventAttributes) {
- ArrayList<String> resultReceived = new ArrayList<>();
- try {
- UUID requestID = UUID.randomUUID();
- @SuppressWarnings("deprecation")
- Collection<PolicyResponse> policyResponses = policyEngine
- .sendEvent(eventAttributes, requestID);
- if (policyResponses != null && !policyResponses.isEmpty()) {
- for (PolicyResponse policyResponse : policyResponses) {
- resultReceived.add(policyResponse
- .getPolicyResponseMessage()
- + " : "
- + policyResponse.getPolicyResponseStatus());
- }
- }
- } catch (PolicyEventException e) {
-// logger.error("Exception Occured"+e);
- resultReceived.add(""+e);
- }
- return resultReceived;
- }
+ /**
+ * This function makes API call to policy engine to get action. And returns
+ * responseMessage and responseStatus
+ *
+ * @param policyEngine Policy Engine object
+ * @param eventAttributes Map of String
+ * @return List of String
+ */
+ public static ArrayList<String> getAction(PolicyEngine policyEngine, Map<String, String> eventAttributes) {
+ ArrayList<String> resultReceived = new ArrayList<>();
+ try {
+ UUID requestID = UUID.randomUUID();
+ @SuppressWarnings("deprecation")
+ Collection<PolicyResponse> policyResponses = policyEngine.sendEvent(eventAttributes, requestID);
+ if (policyResponses != null && !policyResponses.isEmpty()) {
+ for (PolicyResponse policyResponse : policyResponses) {
+ resultReceived.add(policyResponse.getPolicyResponseMessage() + " : "
+ + policyResponse.getPolicyResponseStatus());
+ }
+ }
+ } catch (PolicyEventException e) {
+ // logger.error("Exception Occured"+e);
+ resultReceived.add("" + e);
+ }
+ return resultReceived;
+ }
- /**
- * This function makes API call to policy engine to get manual
- * notifications.
- *
- * @param org.onap.policyEngine
- */
+ /**
+ * This function makes API call to policy engine to get manual
+ * notifications.
+ *
+ * @param policyEngine Policy Engine object
+ */
- public static void getManualNotifications(PolicyEngine policyEngine) {
- policyEngine.setScheme(NotificationScheme.MANUAL_ALL_NOTIFICATIONS);
- System.out.println(policyEngine.getNotification().getNotificationType());
- for (LoadedPolicy updated : policyEngine.getNotification().getLoadedPolicies()) {
- System.out.println(updated.getPolicyName());
- System.out.println(updated.getVersionNo());
- System.out.println(updated.getMatches());
- }
- for (RemovedPolicy removed : policyEngine.getNotification()
- .getRemovedPolicies()) {
- System.out.println(removed.getPolicyName());
- System.out.println(removed.getVersionNo());
- }
- }
+ public static void getManualNotifications(PolicyEngine policyEngine) {
+ policyEngine.setScheme(NotificationScheme.MANUAL_ALL_NOTIFICATIONS);
+ System.out.println(policyEngine.getNotification().getNotificationType());
+ for (LoadedPolicy updated : policyEngine.getNotification().getLoadedPolicies()) {
+ System.out.println(updated.getPolicyName());
+ System.out.println(updated.getVersionNo());
+ System.out.println(updated.getMatches());
+ }
+ for (RemovedPolicy removed : policyEngine.getNotification().getRemovedPolicies()) {
+ System.out.println(removed.getPolicyName());
+ System.out.println(removed.getVersionNo());
+ }
+ }
- /**
- * This function makes API call to policy engine to get automatic
- * notifications.
- *
- * @param org.onap.policyEngine
- */
- public static void getAutoNotifications(PolicyEngine policyEngine) {
- Handler handler = new Handler();
- policyEngine.setNotification(NotificationScheme.AUTO_ALL_NOTIFICATIONS,
- handler);
- //
- System.out.println("Enter a any key to exit");
- try {
- System.in.read();
- } catch (IOException e) {
- //
- }
- }
+ /**
+ * This function makes API call to policy engine to get automatic
+ * notifications.
+ *
+ * @param policyEngine Policy Engine object
+ */
+ public static void getAutoNotifications(PolicyEngine policyEngine) {
+ Handler handler = new Handler();
+ policyEngine.setNotification(NotificationScheme.AUTO_ALL_NOTIFICATIONS, handler);
+ //
+ System.out.println("Enter a any key to exit");
+ try {
+ System.in.read();
+ } catch (IOException e) {
+ //
+ }
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/PushPoliciesToPDP.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/PushPoliciesToPDP.java
index 880af0610..3a3b9e704 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/PushPoliciesToPDP.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/PushPoliciesToPDP.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2019 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.
* 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.
@@ -25,35 +25,39 @@ import org.onap.policy.api.PolicyEngine;
import org.onap.policy.api.PushPolicyParameters;
public class PushPoliciesToPDP {
- public static void main(String[] args) {
- try {
-
- PolicyEngine policyEngine = new PolicyEngine("config.properties");
- PushPolicyParameters policyParameters = new PushPolicyParameters();
-
- //Parameter arguments
- policyParameters.setPolicyName("Mike.testCase1");
- policyParameters.setPolicyType("Base");
- //policyParameters.setPolicyScope("MikeAPItesting");
- policyParameters.setPdpGroup("default");
- policyParameters.setRequestID(null);
-
+
+ /**
+ * main.
+ *
+ * @param args String[] args
+ */
+ public static void main(String[] args) {
+ try {
+ PushPolicyParameters policyParameters = new PushPolicyParameters();
+
+ // Parameter arguments
+ policyParameters.setPolicyName("Mike.testCase1");
+ policyParameters.setPolicyType("Base");
+ // policyParameters.setPolicyScope("MikeAPItesting");
+ policyParameters.setPdpGroup("default");
+ policyParameters.setRequestID(null);
+
// API method to Push Policy to PDP
PolicyChangeResponse response = null;
- response = policyEngine.pushPolicy(policyParameters);
+ response = new PolicyEngine("config.properties").pushPolicy(policyParameters);
- if(response.getResponseCode()==204){
+ if (response.getResponseCode() == 204) {
System.out.println(response.getResponseMessage());
System.out.println("Policy Pushed Successfully!");
- }else{
+ } else {
System.out.println("Error! " + response.getResponseMessage());
}
- } catch (Exception e) {
- System.err.println(e.getMessage());
-
- }
-
- }
+ } catch (Exception e) {
+ System.err.println(e.getMessage());
+
+ }
+
+ }
}
diff --git a/PolicyEngineClient/src/test/java/org/onap/policyengine/RawDecisionPolicyClient.java b/PolicyEngineClient/src/test/java/org/onap/policyengine/RawDecisionPolicyClient.java
index 5f0e74fc6..de28ae8e9 100644
--- a/PolicyEngineClient/src/test/java/org/onap/policyengine/RawDecisionPolicyClient.java
+++ b/PolicyEngineClient/src/test/java/org/onap/policyengine/RawDecisionPolicyClient.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineClient
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
* 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.
@@ -21,6 +21,7 @@
package org.onap.policyengine;
import java.util.UUID;
+
import org.onap.policy.api.PolicyChangeResponse;
import org.onap.policy.api.PolicyClass;
import org.onap.policy.api.PolicyEngine;
@@ -29,15 +30,16 @@ import org.onap.policy.api.RuleProvider;
public class RawDecisionPolicyClient {
/*
- *
+ *
* To Create a Decision Policy Use case. User need provide valid PolicySet or Policy Type xacml. On Setting below
* required attributes the Decision Raw policy will be created successfully.
- *
+ *
*/
static Boolean isEdit = true;
/**
* Sample code to create Decison Raw Policy.
+ *
* @param args with policy parameters
*/
public static void main(String[] args) {