3ff85c898499f539778b70cf5eda1e56b3e11e34
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2020 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.policymodel.handling;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26
27 import org.junit.Test;
28 import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
29
30 public class PolicyAnalyserTest {
31     @Test
32     public void test() {
33         final AxPolicyModel apexModel = new SupportApexPolicyModelCreator().getModel();
34
35         final PolicyAnalyser policyAnalyser = new PolicyAnalyser();
36         final PolicyAnalysisResult analysisResult = policyAnalyser.analyse(apexModel);
37
38         assertEquals(EXPECTED_ANALYSIS_RESULT, analysisResult.toString());
39
40         assertNotNull(analysisResult.getUsedContextAlbums());
41         assertNotNull(analysisResult.getUsedContextSchemas());
42         assertNotNull(analysisResult.getUsedEvents());
43         assertNotNull(analysisResult.getUsedTasks());
44         assertNotNull(analysisResult.getUnusedContextAlbums());
45         assertNotNull(analysisResult.getUnusedContextSchemas());
46         assertNotNull(analysisResult.getUnusedEvents());
47         assertNotNull(analysisResult.getUnusedTasks());
48     }
49
50     private static final String EXPECTED_ANALYSIS_RESULT = "" + "Context Schema usage\n" + " MapType:0.0.1\n"
51             + "  contextAlbum0:0.0.1\n" + " StringType:0.0.1\n" + "  contextAlbum1:0.0.1\n"
52             + " eventContextItem0:0.0.1\n" + "  inEvent:0.0.1\n" + "  outEvent0:0.0.1\n" + "  outEvent1:0.0.1\n"
53             + "  task:0.0.1\n" + " eventContextItem1:0.0.1\n" + "  inEvent:0.0.1\n" + "  outEvent0:0.0.1\n"
54             + "  outEvent1:0.0.1\n" + "  task:0.0.1\n" + "Context Album usage\n" + " contextAlbum0:0.0.1\n"
55             + "  task:0.0.1\n" + "  policy:0.0.1:NULL:state\n" + " contextAlbum1:0.0.1\n" + "  task:0.0.1\n"
56             + "  policy:0.0.1:NULL:state\n" + "Event usage\n" + " inEvent:0.0.1\n" + "  policy:0.0.1:NULL:state\n"
57             + " outEvent0:0.0.1\n" + "  policy:0.0.1:NULL:state\n" + " outEvent1:0.0.1 (unused)\n" + "Task usage\n"
58             + " task:0.0.1\n" + "  policy:0.0.1:NULL:state\n";
59 }