Fix macro flow resource blocks processing order
[so.git] / bpmn / so-bpmn-tasks / src / test / java / org / onap / so / bpmn / infrastructure / workflow / tasks / ResourceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2021 Bell Canada. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2021 Orange
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  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.workflow.tasks;
24
25 import static org.junit.Assert.assertEquals;
26 import java.util.Arrays;
27 import java.util.List;
28 import java.util.stream.Collectors;
29 import org.junit.Test;
30
31 public class ResourceTest {
32
33     @Test
34     public void testBaseFirstComparator() {
35         Resource r1 = new Resource(null, "1", false, null);
36         Resource r2 = new Resource(null, "2", false, null);
37         r2.setBaseVfModule(true);
38
39         List<Resource> sorted =
40                 Arrays.asList(r1, r2).stream().sorted(Resource.sortByPriorityAsc).collect(Collectors.toList());
41
42         assertEquals("2", sorted.get(0).getResourceId());
43     }
44
45     @Test
46     public void testPriorityAscComparator() {
47         Resource r1 = new Resource(null, "1", false, null);
48         Resource r2 = new Resource(null, "2", false, null);
49         Resource r3 = new Resource(null, "3", false, null);
50         Resource r4 = new Resource(null, "4", false, null);
51         r1.setProcessingPriority(4);
52         r2.setBaseVfModule(true);
53         r3.setProcessingPriority(2);
54         r4.setProcessingPriority(1);
55
56         List<Resource> sorted =
57                 Arrays.asList(r1, r2, r3, r4).stream().sorted(Resource.sortByPriorityAsc).collect(Collectors.toList());
58
59         assertEquals("2", sorted.get(0).getResourceId());
60         assertEquals("4", sorted.get(1).getResourceId());
61         assertEquals("3", sorted.get(2).getResourceId());
62     }
63
64     @Test
65     public void testBaseLastComparator() {
66         Resource r1 = new Resource(null, "1", false, null);
67         Resource r2 = new Resource(null, "2", false, null);
68         r1.setBaseVfModule(true);
69
70         List<Resource> sorted =
71                 Arrays.asList(r1, r2).stream().sorted(Resource.sortByPriorityDesc).collect(Collectors.toList());
72
73         assertEquals("1", sorted.get(1).getResourceId());
74     }
75
76     @Test
77     public void testPriorityDescComparator() {
78         Resource r1 = new Resource(null, "1", false, null);
79         Resource r2 = new Resource(null, "2", false, null);
80         Resource r3 = new Resource(null, "3", false, null);
81         Resource r4 = new Resource(null, "4", false, null);
82         r1.setProcessingPriority(4);
83         r2.setBaseVfModule(true);
84         r3.setProcessingPriority(2);
85         r4.setProcessingPriority(1);
86
87         List<Resource> sorted =
88                 Arrays.asList(r1, r2, r3, r4).stream().sorted(Resource.sortByPriorityDesc).collect(Collectors.toList());
89
90         assertEquals("1", sorted.get(0).getResourceId());
91         assertEquals("3", sorted.get(1).getResourceId());
92         assertEquals("4", sorted.get(2).getResourceId());
93     }
94
95     @Test
96     public void testPriorityReplaceBase() {
97         Resource r1 = new Resource(null, "1", false, null);
98         Resource r2 = new Resource(null, "2", false, null);
99         Resource r3 = new Resource(null, "3", false, null);
100         Resource r4 = new Resource(null, "4", false, null);
101         r1.setProcessingPriority(4);
102         r2.setBaseVfModule(true);
103         r2.setProcessingPriority(6);
104         r3.setProcessingPriority(2);
105         r4.setProcessingPriority(1);
106
107         List<Resource> sorted =
108                 Arrays.asList(r1, r2, r3, r4).stream().sorted(Resource.sortByPriorityAsc).collect(Collectors.toList());
109
110         assertEquals("4", sorted.get(0).getResourceId());
111         assertEquals("3", sorted.get(1).getResourceId());
112         assertEquals("1", sorted.get(2).getResourceId());
113     }
114
115 }