7b8b99a259be6568443757f9e86b5961435c7274
[policy/drools-applications.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020 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
21 package org.onap.policy.controlloop;
22
23 import org.junit.After;
24 import org.junit.AfterClass;
25 import org.junit.Before;
26 import org.junit.BeforeClass;
27 import org.junit.runner.RunWith;
28 import org.onap.policy.controlloop.common.rules.test.BaseRuleTest;
29 import org.onap.policy.controlloop.common.rules.test.Listener;
30 import org.onap.policy.controlloop.common.rules.test.NamedRunner;
31 import org.onap.policy.controlloop.common.rules.test.TestNames;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
33 import org.onap.policy.simulators.Util;
34
35 /**
36  * Tests use cases using Frankfurt rules.
37  *
38  * <p/>
39  * Note: this runs ALL tests (i.e., any whose names start with "test").
40  */
41 @RunWith(NamedRunner.class)
42 @TestNames(prefixes = {"test"})
43
44 public class FrankfurtTest extends BaseRuleTest {
45     protected static final String CONTROLLER_NAME = "frankfurt";
46
47
48     /**
49      * Sets up statics.
50      */
51     @BeforeClass
52     public static void setUpBeforeClass() {
53         initStatics(CONTROLLER_NAME);
54
55         rules.configure("src/main/resources");
56         rules.start();
57         httpClients.addClients("frankfurt");
58         simulators.start(Util::buildAaiSim, Util::buildSoSim, Util::buildVfcSim, Util::buildGuardSim,
59                         Util::buildSdncSim);
60     }
61
62     /**
63      * Cleans up statics.
64      */
65     @AfterClass
66     public static void tearDownAfterClass() {
67         finishStatics();
68     }
69
70     /**
71      * Sets up.
72      */
73     @Before
74     public void setUp() {
75         init();
76     }
77
78     /**
79      * Tears down.
80      */
81     @After
82     public void tearDown() {
83         finish();
84     }
85
86     @Override
87     protected void waitForLockAndPermit(ToscaPolicy policy, Listener<VirtualControlLoopNotification> policyClMgt) {
88         String policyName = policy.getIdentifier().getName();
89
90         policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.ACTIVE
91                         && (policyName + ".EVENT").equals(notif.getPolicyName()));
92
93         policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION
94                         && (policyName + ".EVENT.MANAGER.PROCESSING").equals(notif.getPolicyName())
95                         && notif.getMessage().startsWith("Sending guard query"));
96
97         policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION
98                         && (policyName + ".EVENT.MANAGER.PROCESSING").equals(notif.getPolicyName())
99                         && notif.getMessage().startsWith("Guard result") && notif.getMessage().endsWith("Permit"));
100
101         policyClMgt.await(notif -> notif.getNotification() == ControlLoopNotificationType.OPERATION
102                         && (policyName + ".EVENT.MANAGER.PROCESSING").equals(notif.getPolicyName())
103                         && notif.getMessage().startsWith("actor="));
104     }
105
106     @Override
107     protected VirtualControlLoopNotification waitForFinal(ToscaPolicy policy,
108                     Listener<VirtualControlLoopNotification> policyClMgt, ControlLoopNotificationType finalType) {
109
110         return policyClMgt.await(notif -> notif.getNotification() == finalType
111                         && (policy.getIdentifier().getName() + ".EVENT.MANAGER.FINAL").equals(notif.getPolicyName()));
112     }
113 }