View Javadoc

1   /*
2    * Copyright (C) 2014 Atlassian
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 com.atlassian.jira.rest.client.api.domain;
18  
19  import org.junit.Test;
20  
21  import java.util.Collections;
22  
23  import static com.atlassian.jira.rest.client.TestUtil.EMPTY_GROUPS;
24  import static com.atlassian.jira.rest.client.TestUtil.EMPTY_LINKS;
25  import static org.hamcrest.Matchers.allOf;
26  import static org.hamcrest.Matchers.hasProperty;
27  import static org.hamcrest.Matchers.instanceOf;
28  import static org.hamcrest.Matchers.is;
29  import static org.junit.Assert.assertThat;
30  
31  public class OperationsTest {
32  
33      @Test
34      public void testGetLinkById() throws Exception {
35          Operations operations = new Operations(Collections.singleton(new OperationGroup(
36                  null,
37                  Collections.singleton(new OperationLink("action_id_4", null, "Start", null, "/start", null, null)),
38                  EMPTY_GROUPS,
39                  null,
40                  null
41          )));
42  
43          Operation operation = operations.getOperationById("action_id_4");
44  
45          assertThat(operation, allOf(
46                  instanceOf(OperationLink.class),
47                  hasProperty("id", is("action_id_4"))
48                  )
49          );
50      }
51  
52      @Test
53      public void testGetSelfGroupById() throws Exception {
54          Operations operations = new Operations(Collections.singleton(new OperationGroup(
55                  "group_self",
56                  EMPTY_LINKS,
57                  EMPTY_GROUPS,
58                  null,
59                  null
60          )));
61  
62          Operation operation = operations.getOperationById("group_self");
63  
64          assertThat(operation, allOf(
65                  instanceOf(OperationGroup.class),
66                  hasProperty("id", is("group_self"))
67                  )
68          );
69      }
70  
71      @Test
72      public void testGetGroupById() throws Exception {
73          Operations operations = new Operations(Collections.singleton(new OperationGroup(
74                  null,
75                  EMPTY_LINKS,
76                  Collections.singleton(new OperationGroup("group_5", EMPTY_LINKS, EMPTY_GROUPS, null, null)),
77                  null,
78                  null
79          )));
80  
81          Operation operation = operations.getOperationById("group_5");
82  
83          assertThat(operation, allOf(
84                  instanceOf(OperationGroup.class),
85                  hasProperty("id", is("group_5"))
86                  )
87          );
88      }
89  
90      @Test
91      public void testGetHeaderById() throws Exception {
92          Operations operations = new Operations(Collections.singleton(new OperationGroup(
93                  null,
94                  EMPTY_LINKS,
95                  EMPTY_GROUPS,
96                  new OperationHeader("header_6", "header_6", null, null),
97                  null
98          )));
99  
100         Operation operation = operations.getOperationById("header_6");
101 
102         assertThat(operation, allOf(
103                 instanceOf(OperationHeader.class),
104                 hasProperty("id", is("header_6"))
105                 )
106         );
107     }
108 }