Update css file name in conf.py
[policy/engine.git] / PolicyEngineClient / src / test / java / org / onap / policyengine / ConfigBasePolicyClient.java
1 /*-
2 * ============LICENSE_START=======================================================
3 * PolicyEngineClient
4 * ================================================================================
5 * Copyright (C) 2017, 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 *      http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
19 */
20
21 package org.onap.policyengine;
22
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.HashMap;
26 import java.util.Map;
27 import java.util.UUID;
28
29 import org.onap.policy.api.AttributeType;
30 import org.onap.policy.api.PolicyChangeResponse;
31 import org.onap.policy.api.PolicyConfigType;
32 import org.onap.policy.api.PolicyEngine;
33 import org.onap.policy.api.PolicyParameters;
34 import org.onap.policy.api.PolicyType;
35
36 public class ConfigBasePolicyClient {
37     static Boolean isEdit = false;
38
39     /**
40      * main.
41      *
42      * @param args String[] args
43      */
44     public static void main(String[] args) {
45         try {
46             PolicyEngine policyEngine = new PolicyEngine("config.properties");
47             PolicyParameters policyParameters = new PolicyParameters();
48             // Set Policy Type
49             policyParameters.setPolicyConfigType(PolicyConfigType.Base); // required
50             policyParameters.setPolicyName("MikeConsole.testDeleteAPI6"); // required
51             policyParameters.setPolicyDescription("This is a sample Config Base policy creation example"); // optional
52             policyParameters.setOnapName("DCAE"); // required
53             policyParameters.setConfigName("testBase"); // required
54             policyParameters.setConfigBodyType(PolicyType.OTHER); // required
55             policyParameters.setConfigBody("testing"); // required
56
57             // Set the Config Attributes... These are Optional
58             Map<String, String> configAttributes = new HashMap<>();
59             configAttributes.put("Template", "SampleTemplate");
60             configAttributes.put("controller", "default");
61             configAttributes.put("SamPoll", "30");
62             configAttributes.put("value", "abcd");
63             Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
64             attributes.put(AttributeType.MATCHING, configAttributes);
65             policyParameters.setAttributes(attributes);
66             policyParameters.setRequestID(UUID.randomUUID());
67             // Set Safe Policy value for Risk Type
68             SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
69             Date date = dateformat3.parse("15/10/2016");
70             policyParameters.setTtlDate(date);
71             // Set Safe Policy value for Guard
72             policyParameters.setGuard(true);
73             // Set Safe Policy value for Risk Level
74             policyParameters.setRiskLevel("5");
75             // Set Safe Policy value for Risk Type
76             policyParameters.setRiskType("PROD");
77
78             // API method to create Policy or update policy
79             PolicyChangeResponse response = null;
80             if (!isEdit) {
81                 response = policyEngine.createPolicy(policyParameters);
82             } else {
83                 response = policyEngine.updatePolicy(policyParameters);
84             }
85
86             if (response.getResponseCode() == 200) {
87                 System.out.println(response.getResponseMessage());
88                 System.out.println("Policy Created Successfully!");
89             } else {
90                 System.out.println("Error! " + response.getResponseMessage());
91             }
92         } catch (Exception e) {
93             System.err.println(e.getMessage());
94         }
95     }
96
97 }