View Javadoc

1   /*
2    * Copyright (C) 2010 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.internal.json;
18  
19  import com.atlassian.jira.rest.client.api.domain.BasicComponent;
20  import com.atlassian.jira.rest.client.api.domain.Component;
21  import org.junit.Assert;
22  import org.junit.Test;
23  
24  import java.net.URI;
25  
26  public class ComponentJsonParserTest {
27      @Test
28      public void testParseBasicComponent() throws Exception {
29          BasicComponentJsonParser parser = new BasicComponentJsonParser();
30          final BasicComponent component = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/component/basic-valid.json"));
31          Assert.assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/component/10000"), component.getSelf());
32          Assert.assertEquals("Component A", component.getName());
33          Assert.assertEquals("this is some description of component A", component.getDescription());
34      }
35  
36      @Test
37      public void testParseBasicComponentWithNoDescription() throws Exception {
38          BasicComponentJsonParser parser = new BasicComponentJsonParser();
39          final BasicComponent component = parser.parse(ResourceUtil
40                  .getJsonObjectFromResource("/json/component/basic-no-description-valid.json"));
41          Assert.assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/component/10000"), component.getSelf());
42          Assert.assertEquals("Component A", component.getName());
43          Assert.assertNull(component.getDescription());
44      }
45  
46      @Test
47      public void testParseComponent() throws Exception {
48          ComponentJsonParser parser = new ComponentJsonParser();
49          final Component component = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/component/complete-valid.json"));
50          Assert.assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/component/10001"), component.getSelf());
51          Assert.assertEquals("Component B", component.getName());
52          Assert.assertEquals(TestConstants.USER1_BASIC_DEPRECATED, component.getLead());
53          Assert.assertEquals("another description", component.getDescription());
54      }
55  
56      @Test
57      public void testParseComponenWithNoLead() throws Exception {
58          ComponentJsonParser parser = new ComponentJsonParser();
59          final Component component = parser.parse(ResourceUtil
60                  .getJsonObjectFromResource("/json/component/complete-no-lead-valid.json"));
61          Assert.assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/component/10001"), component.getSelf());
62          Assert.assertEquals("Component B", component.getName());
63          Assert.assertNull(component.getLead());
64          Assert.assertEquals("another description", component.getDescription());
65      }
66  
67      @Test
68      public void testParseComponentWithId() throws Exception {
69          ComponentJsonParser parser = new ComponentJsonParser();
70          final Component component = parser.parse(ResourceUtil
71                  .getJsonObjectFromResource("/json/component/complete-valid-with-id.json"));
72          Assert.assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/component/10001"), component.getSelf());
73          Assert.assertEquals("Component B", component.getName());
74          Assert.assertEquals(TestConstants.USER1_BASIC_DEPRECATED, component.getLead());
75          Assert.assertEquals("another description", component.getDescription());
76          Assert.assertEquals(Long.valueOf(10001), component.getId());
77      }
78  
79  }