Include impacted changes for APPC-346,APPC-348
[appc.git] / appc-dispatcher / appc-request-handler / appc-request-handler-core / src / test / java / org / onap / appc / validationpolicy / TestRuleExecutor.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
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  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25 package org.onap.appc.validationpolicy;
26
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.onap.appc.domainmodel.lcm.VNFOperation;
31 import org.onap.appc.validationpolicy.executors.RuleExecutor;
32 import org.onap.appc.validationpolicy.objects.RuleResult;
33
34 import java.io.IOException;
35 import java.net.URISyntaxException;
36 import java.util.stream.Collectors;
37 import java.util.stream.Stream;
38
39 public class TestRuleExecutor {
40
41     RuleExecutor ruleExecutor;
42
43     @Before
44     public void setup() throws IOException, URISyntaxException {
45         RequestValidationPolicy requestValidationPolicy = new MockRequestValidationPolicy();
46         requestValidationPolicy.initialize();
47         ruleExecutor = requestValidationPolicy.getInProgressRuleExecutor();
48     }
49
50     @Test
51     public void testAcceptRule(){
52         RuleResult result;
53         result = ruleExecutor.executeRule("Sync", Stream.of("HealthCheck", "Stop","Start")
54                 .map(s -> VNFOperation.findByString(s)).collect(Collectors.toList()));
55         Assert.assertEquals(result,RuleResult.REJECT);
56
57         result = ruleExecutor.executeRule("Sync", Stream.of("Start", "Stop","Restart")
58                 .map(s -> VNFOperation.findByString(s)).collect(Collectors.toList()));
59         Assert.assertEquals(result,RuleResult.ACCEPT);
60
61         result = ruleExecutor.executeRule("Stop", Stream.of("HealthCheck","Test","CheckLock")
62                 .map(s -> VNFOperation.findByString(s)).collect(Collectors.toList()));
63         Assert.assertEquals(result,RuleResult.ACCEPT);
64
65         result = ruleExecutor.executeRule("Stop", Stream.of("HealthCheck","Start","CheckLock")
66                 .map(s -> VNFOperation.findByString(s)).collect(Collectors.toList()));
67         Assert.assertEquals(result,RuleResult.REJECT);
68     }
69
70     @Test
71     public void testRejectRule(){
72         RuleResult result;
73         result = ruleExecutor.executeRule("Audit", Stream.of("HealthCheck","Test","CheckLock")
74                 .map(s -> VNFOperation.findByString(s)).collect(Collectors.toList()));
75         Assert.assertEquals(result,RuleResult.ACCEPT);
76
77         result = ruleExecutor.executeRule("Audit", Stream.of("HealthCheck", "Test","Restart")
78                 .map(s -> VNFOperation.findByString(s)).collect(Collectors.toList()));
79         Assert.assertEquals(result,RuleResult.REJECT);
80
81         result = ruleExecutor.executeRule("Start", Stream.of("Restart","Start","Stop")
82                 .map(s -> VNFOperation.findByString(s)).collect(Collectors.toList()));
83         Assert.assertEquals(result,RuleResult.ACCEPT);
84
85         result = ruleExecutor.executeRule("Start", Stream.of("HealthCheck","Test","CheckLock")
86                 .map(s -> VNFOperation.findByString(s)).collect(Collectors.toList()));
87         Assert.assertEquals(result,RuleResult.REJECT);
88     }
89
90
91
92 }