Esempio 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);
  }
Esempio n. 2
0
  /**
   * Test retrieving the resources of a Role without providing a role id.
   *
   * @throws Exception If anything fails.
   */
  @Test
  public void testAARrr3_rest() throws Exception {

    try {
      retrieveResources(null);
      EscidocRestSoapTestBase.failMissingException(MissingMethodParameterException.class);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.assertExceptionType(MissingMethodParameterException.class, e);
    }
  }
Esempio n. 3
0
  /**
   * Test retrieving the resources of a Role with providing an id of an existing resource of another
   * resource type.
   *
   * @throws Exception If anything fails.
   */
  @Test
  public void testAARrr2_2_rest() throws Exception {

    try {
      retrieveResources(CONTEXT_ID);
      EscidocRestSoapTestBase.failMissingException(RoleNotFoundException.class);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.assertExceptionType(RoleNotFoundException.class, e);
    }
  }
  /**
   * Update with empty XML.
   *
   * @throws Exception Thrown if no or wrong exception is thrown
   */
  @Test
  public void testUpdateWithEmptyXML() throws Exception {

    try {
      update(this.relationId, "");
    } catch (final Exception e) {
      Class<?> ec = MissingMethodParameterException.class;
      EscidocRestSoapTestBase.assertExceptionType(ec.getName() + " expected.", ec, e);
    }
  }
Esempio n. 5
0
  /**
   * Test declining creation of Role with providing objid.
   *
   * @throws Exception If anything fails.
   */
  @Test
  public void testAACro9_rest() throws Exception {

    Document toBeCreatedDocument =
        EscidocRestSoapTestBase.getTemplateAsDocument(TEMPLATE_ROLE_PATH, "role_for_create.xml");
    addAttribute(
        toBeCreatedDocument,
        XPATH_ROLE,
        createAttributeNode(
            toBeCreatedDocument, XLINK_NS_URI, null, EscidocTestBase.NAME_OBJID, "escidoc:42"));
    insertUniqueRoleName(toBeCreatedDocument);

    try {
      create(toString(toBeCreatedDocument, false));
      EscidocRestSoapTestBase.failMissingException(XmlSchemaValidationException.class);
    } catch (final Exception e) {
      EscidocRestSoapTestBase.assertExceptionType(XmlSchemaValidationException.class, e);
    }
  }
Esempio n. 6
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);
  }
Esempio n. 8
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 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);
  }
  /**
   * 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);
  }
Esempio n. 12
0
  /**
   * Test successful creation of Role with set read-only values.
   *
   * @throws Exception If anything fails.
   */
  @Test
  public void testAACro19_rest() throws Exception {

    EscidocRestSoapTestBase.getTemplateAsDocument(
        TEMPLATE_ROLE_PATH, "role_for_create_rest_read_only.xml");
    Document createdDocument = createSuccessfully("role_for_create_rest_read_only.xml");

    assertEquals(
        "Creation date and last modification date are different. ",
        assertCreationDateExists("", createdDocument),
        getLastModificationDateValue(createdDocument));

    final String objid = getObjidValue(createdDocument);
    Document retrievedDocument = retrieveSuccessfully(objid);
    assertXmlEquals(
        "Retrieved document not the same like the created one", createdDocument, retrievedDocument);
  }
Esempio n. 13
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);
    }
  }
  /**
   * Test to add a second md-record.
   *
   * @throws Exception Thrown if adding of additional md-record failed.
   */
  @Test
  public void testAddSecondEscidocMdRecord() throws Exception {
    Document relationCreated = getDocument(relationXml);

    Element mdRecord =
        relationCreated.createElementNS(
            "http://www.escidoc.de/schemas/metadatarecords/0.5",
            "escidocMetadataRecords:md-record");
    mdRecord.setAttribute("name", "escidoc");
    mdRecord.setAttribute("schema", "bla");
    Element mdRecordContent = relationCreated.createElement("md");
    mdRecord.appendChild(mdRecordContent);
    mdRecordContent.setTextContent("updated");
    selectSingleNode(relationCreated, "/content-relation/md-records").appendChild(mdRecord);
    String relationWithNewMdRecord = toString(relationCreated, false);

    try {
      update(this.relationId, relationWithNewMdRecord);
      fail("No exception on update content relation with" + " two md-records with the same name.");
    } catch (final Exception e) {
      Class<?> ec = InvalidContentException.class;
      EscidocRestSoapTestBase.assertExceptionType(ec.getName() + " expected.", ec, e);
    }
  }
Esempio n. 15
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);
  }