Exemplo n.º 1
0
  /**
   * Test successful update of Role without read-only values.
   *
   * @throws Exception If anything fails.
   */
  @Test
  public void testAAUro32_rest() throws Exception {

    Document toBeUpdatedDocument = createSuccessfully("role_for_create.xml");
    final String id = getObjidValue(toBeUpdatedDocument);

    final Node resourceTypeAttr =
        selectSingleNode(toBeUpdatedDocument, XPATH_ROLE_SCOPE_DEF_RESOURCE_TYPE);
    resourceTypeAttr.setTextContent("user-account");

    final Node policySetIdAttr = selectSingleNode(toBeUpdatedDocument, XPATH_ROLE_POLICY_SET_ID);
    policySetIdAttr.setTextContent("changedId");

    // remove read only values

    // root attributes
    toBeUpdatedDocument = (Document) deleteAttribute(toBeUpdatedDocument, XPATH_ROLE_XLINK_HREF);
    deleteAttribute(toBeUpdatedDocument, XPATH_ROLE_XLINK_TITLE);
    deleteAttribute(toBeUpdatedDocument, XPATH_ROLE_XLINK_TYPE);
    deleteAttribute(toBeUpdatedDocument, XPATH_ROLE_XML_BASE);

    // resources do not exist in role

    // properties do not have xlink attributes

    // creation-date
    deleteNodes(toBeUpdatedDocument, XPATH_ROLE_CREATION_DATE);

    // created-by
    deleteNodes(toBeUpdatedDocument, XPATH_ROLE_CREATED_BY);

    // modified-by
    deleteNodes(toBeUpdatedDocument, XPATH_ROLE_MODIFIED_BY);

    // unlimited flag
    deleteAttribute(toBeUpdatedDocument, XPATH_ROLE_SCOPE_UNLIMITED);

    final String toBeUpdatedXml = toString(toBeUpdatedDocument, false);

    final String timestampBeforeLastModification = getNowAsTimestamp();
    String updatedXml = null;
    try {
      updatedXml = update(id, toBeUpdatedXml);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException(e);
    }
    assertXmlValidRetrievedRole(
        updatedXml, toBeUpdatedXml, startTimestamp, timestampBeforeLastModification, true);

    String retrievedXml = null;
    try {
      retrievedXml = retrieve(id);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException("Retrieve of updated role failed. ", e);
    }

    assertEquals("Retrieved differs from updated. ", updatedXml, retrievedXml);
  }
Exemplo n.º 2
0
  /**
   * Test declining retrieving the resources of a Role that is forbidden to be accessed.
   *
   * @throws Exception If anything fails.
   */
  @Test
  public void testAARrr4_rest() throws Exception {

    final String id = "escidoc:role-default-user";

    try {
      retrieveResources(id);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException(
          "retrieving resources for role default-user fails with exception. ", e);
    }
  }
  /**
   * Test successfully retrieving an explain response.
   *
   * @throws Exception If anything fails.
   */
  @Test
  public void explainTest() throws Exception {
    final Map<String, String[]> filterParams = new HashMap<String, String[]>();

    filterParams.put(EscidocRestSoapTestBase.FILTER_PARAMETER_EXPLAIN, new String[] {""});

    String result = null;

    try {
      result = retrieveSetDefinitions(filterParams);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException(e);
    }
    assertXmlValidSrwResponse(result);
  }
Exemplo n.º 4
0
  /**
   * Test successfully updating a Role without providing modified-by xlink type.
   *
   * @throws Exception If anything fails.
   */
  @Test
  public void testAAUro27_rest() throws Exception {

    Document toBeUpdatedDocument = createSuccessfully("role_for_create.xml");
    deleteAttribute(
        toBeUpdatedDocument,
        XPATH_ROLE_MODIFIED_BY,
        XLINK_PREFIX_ESCIDOC + ":" + EscidocTestBase.NAME_TYPE);

    final String toBeUpdatedXml = toString(toBeUpdatedDocument, false);

    try {
      update(getObjidValue(toBeUpdatedDocument), toBeUpdatedXml);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException(
          "Updating without set read only element fails with exception. ", e);
    }
  }
Exemplo n.º 5
0
  /**
   * Test successfully retrieving resources of a Role.
   *
   * @throws Exception If anything fails.
   */
  @Test
  public void testAARrr1_rest() throws Exception {

    String resourcesXml = null;
    try {
      resourcesXml = retrieveResources("escidoc:role-depositor");
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException("Retrieval of role failed.", e);
    }
    assertNotNull("No virtual resources of role retrieved.", resourcesXml);
    Document retrievedDocument = EscidocRestSoapTestBase.getDocument(resourcesXml);
    assertXmlExists("No resources element", retrievedDocument, XPATH_RESOURCES);
    assertXmlExists("No xlink title", retrievedDocument, XPATH_RESOURCES_XLINK_TITLE);
    assertXmlExists("No xlink href", retrievedDocument, XPATH_RESOURCES_HREF);
    assertXmlExists("No xlink type", retrievedDocument, XPATH_RESOURCES_XLINK_TYPE);
    assertXmlNotExists("Found unexpected objid", retrievedDocument, XPATH_RESOURCES_OBJID);
    NodeList children = selectSingleNode(retrievedDocument, XPATH_RESOURCES).getChildNodes();
    assertEquals("Unexpected number of children of resources element", 0, children.getLength());
  }
  /**
   * Test successful retrieving existing set definitions without filter.
   *
   * @throws Exception e
   */
  @Test
  public void testRetrieveSetDefinitionsCQL() throws Exception {
    final Map<String, String[]> filterParams = new HashMap<String, String[]>();
    filterParams.put(FILTER_PARAMETER_MAXIMUMRECORDS, new String[] {"6"});
    String retrievedSetDefinitionsXml = null;

    try {
      retrievedSetDefinitionsXml = retrieveSetDefinitions(filterParams);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException("Retrieving of list of set definitions failed. ", e);
    }
    assertXmlValidSrwResponse(retrievedSetDefinitionsXml);
    final Document retrievedDocument =
        EscidocRestSoapTestBase.getDocument(retrievedSetDefinitionsXml);
    final NodeList setDefinitionNodes =
        selectNodeList(retrievedDocument, XPATH_SRW_SET_DEFINITION_LIST_SET_DEFINITION);
    int length = setDefinitionNodes.getLength();
    boolean moreThenOne = length >= 1;
    assertEquals("Wrong number in the list", true, moreThenOne);
  }
  /**
   * Test successful retrieving one existing set definition resource using filter set specification.
   *
   * @throws Exception e
   */
  @Test
  public void testRetrieveBySetSpecificationCQL() throws Exception {
    Document createdSetDefinitionDocument =
        createSuccessfully("escidoc_setdefinition_for_create.xml");
    String objid = getObjidValue(createdSetDefinitionDocument);
    String setSpecValue =
        selectSingleNode(createdSetDefinitionDocument, "/set-definition/specification")
            .getTextContent();
    final Map<String, String[]> filterParams = new HashMap<String, String[]>();
    filterParams.put(
        FILTER_PARAMETER_QUERY,
        new String[] {"\"" + FILTER_SET_SPECIFICATION + "\"=\"" + setSpecValue});
    String retrievedSetDefinitionsXml = null;

    try {
      retrievedSetDefinitionsXml = retrieveSetDefinitions(filterParams);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException("Retrieving of list of set definitions failed. ", e);
    }
    assertXmlValidSrwResponse(retrievedSetDefinitionsXml);
    final Document retrievedDocument =
        EscidocRestSoapTestBase.getDocument(retrievedSetDefinitionsXml);
    final NodeList setDefinitionNodes =
        selectNodeList(retrievedDocument, XPATH_SRW_SET_DEFINITION_LIST_SET_DEFINITION);
    assertEquals("Unexpected number of set definitions.", 1, setDefinitionNodes.getLength());
    String objidInTheList = null;
    if (getTransport() == Constants.TRANSPORT_REST) {
      String href =
          selectSingleNode(
                  retrievedDocument, XPATH_SRW_SET_DEFINITION_LIST_SET_DEFINITION + "/@href")
              .getNodeValue();
      objidInTheList = getIdFromHrefValue(href);
    } else {
      objidInTheList =
          selectSingleNode(
                  retrievedDocument, XPATH_SRW_SET_DEFINITION_LIST_SET_DEFINITION + "/@objid")
              .getNodeValue();
    }
    assertEquals("objid of the set definition is wrong", objid, objidInTheList);
  }
  /**
   * Test successful retrieving existing set definitions resource using filter set specification
   * pattern.
   *
   * @throws Exception e
   */
  @Test
  public void testRetrieveBySetSpecificationLikeCQL() throws Exception {
    createSuccessfully("escidoc_setdefinition_for_create.xml");
    final Map<String, String[]> filterParams = new HashMap<String, String[]>();
    filterParams.put(
        FILTER_PARAMETER_QUERY, new String[] {"\"" + FILTER_SET_SPECIFICATION + "\"=\"%Set1%"});
    String retrievedSetDefinitionsXml = null;

    try {
      retrievedSetDefinitionsXml = retrieveSetDefinitions(filterParams);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException("Retrieving of list of set definitions failed. ", e);
    }
    assertXmlValidSrwResponse(retrievedSetDefinitionsXml);
    final Document retrievedDocument =
        EscidocRestSoapTestBase.getDocument(retrievedSetDefinitionsXml);
    final NodeList setDefinitionNodes =
        selectNodeList(retrievedDocument, XPATH_SRW_SET_DEFINITION_LIST_SET_DEFINITION);
    int length = setDefinitionNodes.getLength();
    boolean moreThenOne = length > 1;
    assertEquals("Wrong number in the list", true, moreThenOne);
  }
Exemplo n.º 9
0
  /**
   * Test successful update of Role with changed read-only values.
   *
   * @throws Exception If anything fails.
   */
  @Test
  public void testAAUro31_rest() throws Exception {

    final Document createdDocument = createSuccessfully("role_for_create.xml");
    final String id = getObjidValue(createdDocument);

    // change some values
    final Node resourceTypeAttr =
        selectSingleNode(createdDocument, XPATH_ROLE_SCOPE_DEF_RESOURCE_TYPE);
    resourceTypeAttr.setTextContent("user-account");

    final Node policySetIdAttr = selectSingleNode(createdDocument, XPATH_ROLE_POLICY_SET_ID);
    policySetIdAttr.setTextContent("changedId");

    final String createdXml = toString(createdDocument, false);

    // change read only values

    // root attributes
    final Document toBeUpdatedDocument =
        (Document) substitute(createdDocument, XPATH_ROLE_XLINK_HREF, "Some Href");
    substitute(toBeUpdatedDocument, XPATH_ROLE_XLINK_TITLE, "Some Title");
    substitute(toBeUpdatedDocument, XPATH_ROLE_XLINK_TYPE, "simple");
    substitute(toBeUpdatedDocument, XPATH_ROLE_XML_BASE, "http://some.base.uri");

    // resources do not exist in role

    // properties do not have xlink attributes

    // creation-date
    substitute(toBeUpdatedDocument, XPATH_ROLE_CREATION_DATE, getNowAsTimestamp());

    // created-by
    substitute(toBeUpdatedDocument, XPATH_ROLE_CREATED_BY_XLINK_HREF, "Some Href");
    substitute(toBeUpdatedDocument, XPATH_ROLE_CREATED_BY_XLINK_TITLE, "Some Title");
    // type is fixed to simple, cannot be changed

    // modified-by
    substitute(toBeUpdatedDocument, XPATH_ROLE_MODIFIED_BY_XLINK_HREF, "Some Href");
    substitute(toBeUpdatedDocument, XPATH_ROLE_MODIFIED_BY_XLINK_TITLE, "Some Title");
    // type is fixed to simple, cannot be changed

    // unlimited flag
    substitute(toBeUpdatedDocument, XPATH_ROLE_SCOPE_UNLIMITED, "true");

    final String toBeUpdatedXml = toString(toBeUpdatedDocument, false);

    final String timestampBeforeLastModification = getNowAsTimestamp();
    String updatedXml = null;
    try {
      updatedXml = update(id, toBeUpdatedXml);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException(e);
    }
    assertXmlValidRetrievedRole(
        updatedXml, createdXml, startTimestamp, timestampBeforeLastModification, true);

    String retrievedXml = null;
    try {
      retrievedXml = retrieve(id);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.failException("Retrieve of updated role failed. ", e);
    }

    assertEquals("Retrieved differs from updated. ", updatedXml, retrievedXml);
  }