2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.validationpolicy;
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;
34 import java.io.IOException;
35 import java.net.URISyntaxException;
36 import java.util.stream.Collectors;
37 import java.util.stream.Stream;
39 public class TestRuleExecutor {
41 RuleExecutor ruleExecutor;
44 public void setup() throws IOException, URISyntaxException {
45 RequestValidationPolicy requestValidationPolicy = new MockRequestValidationPolicy();
46 requestValidationPolicy.initialize();
47 ruleExecutor = requestValidationPolicy.getInProgressRuleExecutor();
51 public void testAcceptRule(){
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);
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);
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);
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);
71 public void testRejectRule(){
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);
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);
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);
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);