2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.rest.util;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotSame;
27 import java.text.SimpleDateFormat;
28 import java.util.Date;
29 import java.util.UUID;
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.api.PolicyConfigType;
35 import org.onap.policy.api.PolicyParameters;
36 import org.onap.policy.rest.adapter.PolicyRestAdapter;
38 public class PolicyValidationTest {
41 public void setUp() throws Exception {
45 public void tearDown() throws Exception {
49 public void microServicePolicyTests() throws Exception {
50 PolicyParameters policyParameters = new PolicyParameters();
52 policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
53 policyParameters.setPolicyName("Test.junitPolicy");
54 policyParameters.setPolicyDescription("This is a sample Micro Service policy Create example");
55 policyParameters.setOnapName("DCAE");
56 policyParameters.setPriority("1");
57 String msJsonString = "{\"service\":\"TOSCA_namingJenny\",\"location\":\"Test DictMSLoc\","
58 + "\"uuid\":\"testDict DCAEUIID\",\"policyName\":\"testModelValidation\","
59 + "\"description\":\"test\",\"configName\":\"testDict MSConfName\","
60 + "\"templateVersion\":\"1607\",\"version\":\"gw12181031\",\"priority\":\"5\","
61 + "\"policyScope\":\"resource=ResourcetypeVenktest1,service=ServiceName1707,type=Name1707,"
62 + "closedLoopControlName=Retest_retest1\",\"riskType\":\"Test\",\"riskLevel\":\"3\","
63 + "\"guard\":\"True\",\"content\":{\"police-instance-name\":\"testing\","
64 + "\"naming-models\":[{\"naming-properties\":[{\"property-value\":\"test\","
65 + "\"source-endpoint\":\"test\",\"property-name\":\"testPropertyname\","
66 + "\"increment-sequence\":{\"scope\":\"VNF\",\"start-value\":\"1\",\"length\":\"3\","
67 + "\"increment\":\"2\"},\"source-system\":\"TOSCA\"}],\"naming-type\":\"testNamingType\","
68 + "\"naming-recipe\":\"testNamingRecipe\"}]}}";
70 policyParameters.setConfigBody(msJsonString);
71 policyParameters.setRequestID(UUID.randomUUID());
72 SimpleDateFormat dateformat3 = new SimpleDateFormat("dd/MM/yyyy");
73 Date date = dateformat3.parse("15/10/2016");
74 policyParameters.setTtlDate(date);
75 policyParameters.setGuard(true);
76 policyParameters.setRiskLevel("5");
77 policyParameters.setRiskType("TEST");
78 policyParameters.setRequestID(UUID.randomUUID());
80 PolicyValidationRequestWrapper wrapper = new PolicyValidationRequestWrapper();
81 PolicyRestAdapter policyData = wrapper.populateRequestParameters(policyParameters);
82 PolicyValidation validation = new PolicyValidation();
83 StringBuilder responseString = validation.validatePolicy(policyData);
85 assertNotSame("success", responseString.toString());
90 public final void testEmailValidation() {
91 PolicyValidation validation = new PolicyValidation();
92 String result = validation.emailValidation("testemail@test.com", "SUCCESS");
93 assertEquals("success", result);