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