Package com.atlassian.jira.rest.client.domain

Examples of com.atlassian.jira.rest.client.domain.BasicComponent


import org.codehaus.jettison.json.JSONObject;

public class ComponentJsonParser implements JsonObjectParser<Component> {
  @Override
  public Component parse(JSONObject json) throws JSONException {
    final BasicComponent basicComponent = BasicComponentJsonParser.parseBasicComponent(json);
    final JSONObject leadJson = json.optJSONObject("lead");
    final BasicUser lead = leadJson != null ? JsonParseUtil.parseBasicUser(leadJson) : null;
    final String assigneeTypeStr = JsonParseUtil.getOptionalString(json, "assigneeType");
    final Component.AssigneeInfo assigneeInfo;
    if (assigneeTypeStr != null) {
      final AssigneeType assigneeType = parseAssigneeType(assigneeTypeStr);
      final JSONObject assigneeJson = json.optJSONObject("assignee");
      final BasicUser assignee = assigneeJson != null ? JsonParseUtil.parseBasicUser(assigneeJson) : null;
      final AssigneeType realAssigneeType = parseAssigneeType(json.getString("realAssigneeType"));
      final JSONObject realAssigneeJson = json.optJSONObject("realAssignee");
      final BasicUser realAssignee = realAssigneeJson != null ? JsonParseUtil.parseBasicUser(realAssigneeJson) : null;
      final boolean isAssigneeTypeValid = json.getBoolean("isAssigneeTypeValid");
      assigneeInfo = new Component.AssigneeInfo(assignee, assigneeType, realAssignee, realAssigneeType, isAssigneeTypeValid);
    } else {
      assigneeInfo = null;
    }

    return new Component(basicComponent.getSelf(), basicComponent.getId(), basicComponent.getName(), basicComponent.getDescription(), lead, assigneeInfo);
  }
View Full Code Here


  static BasicComponent parseBasicComponent(JSONObject json) throws JSONException {
    final URI selfUri = JsonParseUtil.getSelfUri(json);
    final String name = json.getString("name");
    final Long id = JsonParseUtil.getOptionalLong(json, "id");
    final String description = JsonParseUtil.getOptionalString(json, "description");
    return new BasicComponent(selfUri, id, name, description);
  }
View Full Code Here

public class ComponentJsonParserTest {
  @Test
  public void testParseBasicComponent() throws Exception {
    BasicComponentJsonParser parser = new BasicComponentJsonParser();
    final BasicComponent component = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/component/basic-valid.json"));
    assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/component/10000"), component.getSelf());
    assertEquals("Component A", component.getName());
    assertEquals("this is some description of component A", component.getDescription());
  }
View Full Code Here

  }

  @Test
  public void testParseBasicComponentWithNoDescription() throws Exception {
    BasicComponentJsonParser parser = new BasicComponentJsonParser();
    final BasicComponent component = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/component/basic-no-description-valid.json"));
    assertEquals(new URI("http://localhost:8090/jira/rest/api/latest/component/10000"), component.getSelf());
    assertEquals("Component A", component.getName());
    assertNull(component.getDescription());
  }
View Full Code Here

@Restore(TestConstants.DEFAULT_JIRA_DUMP_FILE)
public class JerseyComponentRestClientTest extends AbstractJerseyRestClientTest {

  @Test
  public void testGetComponent() throws Exception {
    final BasicComponent basicComponent = findEntityByName(client.getProjectClient().getProject("TST", pm).getComponents(), "Component A");
    final Component component = client.getComponentClient().getComponent(basicComponent.getSelf(), pm);
    assertEquals("Component A", component.getName());
    assertEquals("this is some description of component A", component.getDescription());
    assertEquals(IntegrationTestUtil.USER_ADMIN_LATEST, component.getLead());
  }
View Full Code Here

  }

  @Test
  @JiraBuildNumberDependent(BN_JIRA_4_4)
  public void testGetComponentOnJira4xOrNewerShouldContainNotNullId() throws Exception {
    final BasicComponent basicComponent = findEntityByName(client.getProjectClient().getProject("TST", pm).getComponents(), "Component A");
    final Component component = client.getComponentClient().getComponent(basicComponent.getSelf(), pm);
    assertEquals("Component A", component.getName());
    assertEquals("this is some description of component A", component.getDescription());
    assertEquals(Long.valueOf(10000), component.getId());
    assertEquals(IntegrationTestUtil.USER_ADMIN_LATEST, component.getLead());
  }
View Full Code Here

    assertEquals(IntegrationTestUtil.USER_ADMIN_LATEST, component.getLead());
  }

  @Test
  public void testGetInvalidComponent() throws Exception {
    final BasicComponent basicComponent = Iterables.get(client.getProjectClient().getProject("TST", pm).getComponents(), 0);
    final String uriForUnexistingComponent = basicComponent.getSelf().toString() + "1234";
    TestUtil.assertErrorCode(Response.Status.NOT_FOUND,  "The component with id "
        + TestUtil.getLastPathSegment(basicComponent.getSelf()) + "1234 does not exist.", new Runnable() {
      @Override
      public void run() {
        client.getComponentClient().getComponent(TestUtil.toUri(uriForUnexistingComponent), pm);
      }
    });
View Full Code Here

    });
  }

  @Test
  public void testGetComponentFromRestrictedProject() throws Exception {
    final BasicComponent basicComponent = Iterables.getOnlyElement(client.getProjectClient().getProject("RST", pm).getComponents());
    assertEquals("One Great Component", client.getComponentClient().getComponent(basicComponent.getSelf(), pm).getName());

    // now as unauthorized user
    setClient(TestConstants.USER2_USERNAME, TestConstants.USER2_PASSWORD);
    TestUtil.assertErrorCode(Response.Status.NOT_FOUND, IntegrationTestUtil.TESTING_JIRA_5_OR_NEWER ?
                "The component with id 10010 does not exist." : "The user user does not have permission to complete this operation.", new Runnable() {
      @Override
      public void run() {
        client.getComponentClient().getComponent(basicComponent.getSelf(), pm).getName();
      }
    });

    setAnonymousMode();
    TestUtil.assertErrorCode(Response.Status.NOT_FOUND, IntegrationTestUtil.TESTING_JIRA_5_OR_NEWER ?
                "The component with id 10010 does not exist." : "This user does not have permission to complete this operation.", new Runnable() {
      @Override
      public void run() {
        client.getComponentClient().getComponent(basicComponent.getSelf(), pm).getName();
      }
    });
  }
View Full Code Here

  @Test
  @JiraBuildNumberDependent(BN_JIRA_4_4)
  public void testCreateAndRemoveComponent() {
    final Iterable<BasicComponent> components = client.getProjectClient().getProject("TST", pm).getComponents();
    assertEquals(2, Iterables.size(components));
    final BasicComponent basicComponent = Iterables.get(components, 0);
    final BasicComponent basicComponent2 = Iterables.get(components, 1);
    final String componentName = "my component";
    final ComponentInput componentInput = new ComponentInput(componentName, "a description", null, null);
    final Component component = client.getComponentClient().createComponent("TST", componentInput, pm);
    assertEquals(componentInput.getName(), component.getName());
    assertEquals(componentInput.getDescription(), component.getDescription());
    assertNull(component.getLead());
    assertProjectHasComponents(basicComponent.getName(), basicComponent2.getName(), componentName);

    client.getComponentClient().removeComponent(basicComponent.getSelf(), null, pm);
    assertProjectHasComponents(basicComponent2.getName(), componentName);
    client.getComponentClient().removeComponent(basicComponent2.getSelf(), null, pm);
    assertProjectHasComponents(componentName);
    client.getComponentClient().removeComponent(component.getSelf(), null, pm);
    assertProjectHasComponents();

  }
View Full Code Here

  @Test
  @JiraBuildNumberDependent(BN_JIRA_4_4)
  public void testCreateAndRemoveComponentAsUnauthorizedUsers() {
    final Iterable<BasicComponent> components = client.getProjectClient().getProject("TST", pm).getComponents();
    assertEquals(2, Iterables.size(components));
    final BasicComponent basicComponent = Iterables.get(components, 0);

    final ComponentInput componentInput = new ComponentInput("my component", "a description", null, null);
    setUser1();

    final Response.Status expectedForbiddenErrorCode = (doesJiraReturnCorrectErrorCodeForForbiddenOperation()) ? Response.Status.FORBIDDEN : Response.Status.UNAUTHORIZED;
    TestUtil.assertErrorCode(expectedForbiddenErrorCode, "The user wseliga does not have permission to complete this operation.", new Runnable() {
      @Override
      public void run() {
        client.getComponentClient().removeComponent(basicComponent.getSelf(), null, pm);
      }
    });
    TestUtil.assertErrorCode(expectedForbiddenErrorCode, "You cannot edit the configuration of this project.", new Runnable() {
      @Override
      public void run() {
        client.getComponentClient().createComponent("TST", componentInput, pm);
      }
    });

    setAnonymousMode();
    TestUtil.assertErrorCode(Response.Status.NOT_FOUND, IntegrationTestUtil.TESTING_JIRA_5_OR_NEWER ?
                "The component with id 10000 does not exist." : "This user does not have permission to complete this operation.", new Runnable() {
      @Override
      public void run() {
        client.getComponentClient().removeComponent(basicComponent.getSelf(), null, pm);
      }
    });

    if (IntegrationTestUtil.TESTING_JIRA_5_OR_NEWER) {
      TestUtil.assertErrorCode(Response.Status.NOT_FOUND, "No project could be found with key 'TST'.", new Runnable() {
        @Override
        public void run() {
          client.getComponentClient().createComponent("TST", componentInput, pm);
        }
      });
    } else {
      // IMO for anonymous access still Response.Status.UNAUTHORIZED should be returned - JRADEV-7671
      TestUtil.assertErrorCode(expectedForbiddenErrorCode, "You cannot edit the configuration of this project.", new Runnable() {
        @Override
        public void run() {
          client.getComponentClient().createComponent("TST", componentInput, pm);
        }
      });
    }


    setAdmin();
    // now let's try to add a component with colliding name
    final ComponentInput dupeComponentInput = new ComponentInput(basicComponent.getName(), "a description", null, null);
    TestUtil.assertErrorCode(Response.Status.BAD_REQUEST, "A component with the name Component A already exists in this project.", new Runnable() {
      @Override
      public void run() {
        client.getComponentClient().createComponent("TST", dupeComponentInput, pm);
      }
View Full Code Here

TOP

Related Classes of com.atlassian.jira.rest.client.domain.BasicComponent

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.