1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package it;
18
19 import com.atlassian.jira.rest.client.IntegrationTestUtil;
20 import com.atlassian.jira.rest.client.TestUtil;
21 import com.atlassian.jira.rest.client.domain.BasicComponent;
22 import com.atlassian.jira.rest.client.domain.Component;
23 import com.atlassian.jira.rest.client.internal.json.TestConstants;
24 import com.google.common.collect.Iterables;
25
26 import javax.ws.rs.core.Response;
27
28 public class JerseyComponentRestClientTest extends AbstractRestoringJiraStateJerseyRestClientTest {
29 public void testGetComponent() throws Exception {
30 final BasicComponent basicComponent = Iterables.get(client.getProjectClient().getProject("TST", pm).getComponents(), 0);
31 final Component component = client.getComponentClient().getComponent(basicComponent.getSelf(), pm);
32 assertEquals("Component A", component.getName());
33 assertEquals("this is some description of component A", component.getDescription());
34 assertEquals(IntegrationTestUtil.USER_ADMIN, component.getLead());
35 }
36
37 public void testGetInvalidComponent() throws Exception {
38 final BasicComponent basicComponent = Iterables.get(client.getProjectClient().getProject("TST", pm).getComponents(), 0);
39 final String uriForUnexistingComponent = basicComponent.getSelf().toString() + "1234";
40 TestUtil.assertErrorCode(Response.Status.NOT_FOUND, "The component with id "
41 + TestUtil.getLastPathSegment(basicComponent.getSelf()) + "1234 does not exist.", new Runnable() {
42 @Override
43 public void run() {
44 client.getComponentClient().getComponent(TestUtil.toUri(uriForUnexistingComponent), pm);
45 }
46 });
47 }
48
49 public void testGetComponentFromRestrictedProject() throws Exception {
50 final BasicComponent basicComponent = Iterables.get(client.getProjectClient().getProject("RST", pm).getComponents(), 0);
51 assertEquals("One Great Component", client.getComponentClient().getComponent(basicComponent.getSelf(), pm).getName());
52
53
54 setClient(TestConstants.USER2_USERNAME, TestConstants.USER2_PASSWORD);
55 TestUtil.assertErrorCode(Response.Status.NOT_FOUND, "The user user does not have permission to complete this operation.", new Runnable() {
56 @Override
57 public void run() {
58 client.getComponentClient().getComponent(basicComponent.getSelf(), pm).getName();
59 }
60 });
61
62 setAnonymousMode();
63 TestUtil.assertErrorCode(Response.Status.NOT_FOUND, "This user does not have permission to complete this operation.", new Runnable() {
64 @Override
65 public void run() {
66 client.getComponentClient().getComponent(basicComponent.getSelf(), pm).getName();
67 }
68 });
69 }
70 }