Reformat ONAP-PDP-REST test cases
[policy/engine.git] / ONAP-PDP-REST / src / test / java / org / onap / policy / pdp / rest / api / services / ClosedLoopFaultPolicyServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PDP-REST
4  * ================================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (C) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22 package org.onap.policy.pdp.rest.api.services;
23
24 import static org.junit.Assert.*;
25 import java.io.FileInputStream;
26 import java.text.SimpleDateFormat;
27 import java.util.Arrays;
28 import java.util.Date;
29 import java.util.List;
30 import java.util.Properties;
31 import java.util.UUID;
32 import org.junit.After;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.policy.api.PolicyConfigType;
36 import org.onap.policy.api.PolicyException;
37 import org.onap.policy.api.PolicyParameters;
38
39 public class ClosedLoopFaultPolicyServiceTest {
40
41     ClosedLoopFaultPolicyService service = null;
42
43     @Before
44     public void setUp() throws Exception {
45         Properties prop = new Properties();
46         prop.load(new FileInputStream("src/test/resources/pass.xacml.pdp.properties"));
47         String succeeded = prop.getProperty("xacml.rest.pap.url");
48         List<String> paps = Arrays.asList(succeeded.split(","));
49         PAPServices.setPaps(paps);
50         PAPServices.setJunit(true);
51
52         PolicyParameters policyParameters = new PolicyParameters();
53         policyParameters.setPolicyConfigType(PolicyConfigType.ClosedLoop_Fault);
54         policyParameters.setPolicyName("Test.testCLFaultPolicy");
55         policyParameters.setRequestID(UUID.randomUUID());
56         SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
57         Date date = dateformat3.parse("15/10/2016");
58         policyParameters.setTtlDate(date);
59         policyParameters.setGuard(true);
60         policyParameters.setRiskLevel("5");
61         policyParameters.setRiskType("TEST");
62         policyParameters.setConfigBody(
63                 "{\"trinity\":true,"
64                 + "\"vUSP\":false,"
65                 + "\"mcr\":true,"
66                 + "\"gamma\":true,"
67                 + "\"vDNS\":false,"
68                 + "\"geoLink\":\"testing\","
69                 + "\"emailAddress\":\"mm117s@att.com\","
70                 + "\"serviceTypePolicyName\":\"Registration Failure(Trinity)\","
71                 + "\"attributes\":{\"Window\":\"200\","
72                 + "\"Training\":\"123\","
73                 + "\"ConsecutiveIntervalOnset\":\"300\","
74                 + "\"FractionSamplePerDay\":\"30\","
75                 + "\"OnsetMessage\":\"test\","
76                 + "\"PtileLimit\":\"300\","
77                 + "\"PolicyName\":\"testD2ServicesView\","
78                 + "\"AbatementMessage\":\"test\","
79                 + "\"RetryTimer\":\"30\","
80                 + "\"ConsecutiveIntervalAbatement\":\"300\","
81                 + "\"Threshold\":\"120\"},"
82                 + "\"templateVersion\":\"1604\","
83                 + "\"onapname\":\"java\"}");
84
85         String policyName = "testCLFaultPolicy";
86         String policyScope = "Test";
87         service = new ClosedLoopFaultPolicyService(policyName, policyScope, policyParameters, date.toString());
88     }
89
90     @After
91     public void tearDown() throws Exception {
92         PAPServices.setPaps(null);
93         PAPServices.setJunit(false);
94     }
95
96     @Test
97     public final void testFirewallPolicyService() {
98         assertNotNull(service);
99     }
100
101     @Test
102     public final void testGetValidation() {
103         assertTrue(service.getValidation());
104     }
105
106     @Test
107     public final void testGetMessage() {
108         String message = service.getMessage();
109         assertNull(message);
110     }
111
112     @Test
113     public final void testGetResult() throws PolicyException {
114         service.getValidation();
115         String result = service.getResult(false);
116         assertEquals("success", result);
117     }
118 }