Merge "Convert tabs to spaces basic refactoring"
[policy/engine.git] / ONAP-REST / src / test / java / org / onap / policy / rest / util / PolicyValidationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-REST
4  * ================================================================================
5  * Copyright (C) 2018 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 package org.onap.policy.rest.util;
21
22 import static org.junit.Assert.*;
23 import java.text.SimpleDateFormat;
24 import java.util.Date;
25 import java.util.UUID;
26 import org.junit.After;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.onap.policy.api.PolicyConfigType;
30 import org.onap.policy.api.PolicyParameters;
31 import org.onap.policy.rest.adapter.PolicyRestAdapter;
32
33 public class PolicyValidationTest {
34
35     @Before
36     public void setUp() throws Exception {
37     }
38
39     @After
40     public void tearDown() throws Exception {
41     }
42
43     @Test
44     public void microServicePolicyTests() throws Exception{
45         PolicyValidation validation = new PolicyValidation();
46         PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
47         PolicyParameters policyParameters = new PolicyParameters();
48
49         policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
50         policyParameters.setPolicyName("Test.junitPolicy");
51         policyParameters.setPolicyDescription("This is a sample Micro Service policy Create example");
52         policyParameters.setOnapName("DCAE");
53         policyParameters.setPriority("1");
54         String MSjsonString = "{\"service\":\"TOSCA_namingJenny\",\"location\":\"Test  DictMSLoc\",\"uuid\":\"testDict  DCAEUIID\",\"policyName\":\"testModelValidation\",\"description\":\"test\",\"configName\":\"testDict  MSConfName\",\"templateVersion\":\"1607\",\"version\":\"gw12181031\",\"priority\":\"5\",\"policyScope\":\"resource=ResourcetypeVenktest1,service=ServiceName1707,type=Name1707,closedLoopControlName=Retest_retest1\",\"riskType\":\"Test\",\"riskLevel\":\"3\",\"guard\":\"True\",\"content\":{\"police-instance-name\":\"testing\",\"naming-models\":[{\"naming-properties\":[{\"property-value\":\"test\",\"source-endpoint\":\"test\",\"property-name\":\"testPropertyname\",\"increment-sequence\":{\"scope\":\"VNF\",\"start-value\":\"1\",\"length\":\"3\",\"increment\":\"2\"},\"source-system\":\"TOSCA\"}],\"naming-type\":\"testNamingType\",\"naming-recipe\":\"testNamingRecipe\"}]}}";;
55         policyParameters.setConfigBody(MSjsonString);
56         policyParameters.setRequestID(UUID.randomUUID());
57         SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
58         Date date = dateformat3.parse("15/10/2016");
59         policyParameters.setTtlDate(date);
60         policyParameters.setGuard(true);
61         policyParameters.setRiskLevel("5");
62         policyParameters.setRiskType("TEST");
63         policyParameters.setRequestID(UUID.randomUUID());
64
65
66         PolicyRestAdapter policyData = wrapper.populateRequestParameters(policyParameters);
67         StringBuilder responseString = validation.validatePolicy(policyData);
68
69         assertNotSame("success", responseString.toString());
70
71     }
72
73     @Test
74     public final void testEmailValidation() {
75         PolicyValidation validation = new PolicyValidation();
76         String result = validation.emailValidation("testemail@test.com", "SUCCESS");
77         assertEquals("success", result);
78     }
79
80 }