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  package com.atlassian.jira.rest.client.internal.json;
17  
18  import com.atlassian.jira.rest.client.api.domain.Permission;
19  import com.atlassian.jira.rest.client.api.domain.Permissions;
20  import org.junit.Test;
21  
22  import static org.hamcrest.Matchers.is;
23  import static org.hamcrest.Matchers.notNullValue;
24  import static org.junit.Assert.assertThat;
25  
26  public class PermissionsJsonParserTest {
27  
28      @Test
29      public void testParse() throws Exception {
30          final PermissionsJsonParser parser = new PermissionsJsonParser();
31          final Permissions permissions = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/mypermission/valid.json"));
32  
33          assertThat(permissions.havePermission("WORKLOG_EDIT_OWN"), is(true));
34          assertThat(permissions.havePermission("WORKLOG_DELETE_OWN"), is(false));
35          Permission worklogDeleteOwn = permissions.getPermission("WORKLOG_DELETE_OWN");
36          assertThat(worklogDeleteOwn, notNullValue());
37          assertThat(worklogDeleteOwn.getId(), is(42));
38          assertThat(worklogDeleteOwn.getKey(), is("WORKLOG_DELETE_OWN"));
39          assertThat(worklogDeleteOwn.getName(), is("Delete Own Worklogs"));
40          assertThat(worklogDeleteOwn.getDescription(), is("Ability to delete own worklogs made on issues."));
41          assertThat(worklogDeleteOwn.havePermission(), is(false));
42      }
43  }