Migrate sdc-sdc-workflow-designer docs
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-be / src / test / java / org / onap / sdc / workflow / api / types / SortingTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.sdc.workflow.api.types;
18
19 import static org.junit.Assert.assertEquals;
20
21 import java.util.Arrays;
22 import java.util.Collections;
23 import org.junit.Test;
24 import org.junit.runner.RunWith;
25 import org.mockito.InjectMocks;
26 import org.onap.sdc.workflow.services.types.Sort;
27 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
28
29 @RunWith(SpringJUnit4ClassRunner.class)
30 public class SortingTest {
31
32     @InjectMocks
33     private Sorting sorting;
34
35     @Test
36     public void setSortInvalid() {
37         sorting.setSort("name:asc:a,:,");
38         assertEquals(Collections.emptyList(), sorting.getSorts());
39     }
40
41     @Test
42     public void setSortAscByDefault() {
43         sorting.setSort("name");
44         assertEquals(Collections.singletonList(new Sort("name", true)), sorting.getSorts());
45     }
46
47     @Test
48     public void setSortAsc() {
49         sorting.setSort("name:asc");
50         assertEquals(Collections.singletonList(new Sort("name", true)), sorting.getSorts());
51     }
52
53     @Test
54     public void setSortDesc() {
55         sorting.setSort("name:desc");
56         assertEquals(Collections.singletonList(new Sort("name", false)), sorting.getSorts());
57     }
58
59     @Test
60     public void setSortMoreThanOne() {
61         sorting.setSort("name:asc,type,date:desc");
62         assertEquals(Arrays.asList(
63                 new Sort("name", true),
64                 new Sort("type", true),
65                 new Sort("date", false)), sorting.getSorts());
66     }
67 }