コード例 #1
0
    protected String callMetadataService(String nodeString) throws ConnectorServiceException {
      GetRequest request =
          new GetRequest("/api/metadata?nodeRef=" + nodeString + "&shortQNames=true");
      Response response = null;
      String jsonResponse = null;
      try {
        response =
            server.submitRequest(
                request.getMethod(),
                request.getFullUri(),
                request.getHeaders(),
                request.getBody(),
                request.getEncoding(),
                request.getType());

        if (response != null) {
          jsonResponse = response.getContentAsString();
        }
      } catch (UnsupportedEncodingException e) {
        throw new AlfrescoRuntimeException(e.getMessage());
      } catch (IOException e) {
        throw new AlfrescoRuntimeException(e.getMessage());
      }

      assertNotNull("Response /api/metadata is null", jsonResponse);

      log.info("Response /api/metadata json is: " + jsonResponse);

      return jsonResponse;
    }
コード例 #2
0
ファイル: WikiRestApiTest.java プロジェクト: naifshmri/share
  /** Deletes the page */
  private JSONObject deletePage(String title, int expectedStatus) throws Exception {
    String name = title.replace(' ', '_');

    Response response = sendRequest(new DeleteRequest(URL_WIKI_DELETE + name), expectedStatus);
    if (expectedStatus == Status.STATUS_OK) {
      JSONObject result = new JSONObject(response.getContentAsString());
      return result;
    } else {
      return null;
    }
  }
コード例 #3
0
ファイル: WikiRestApiTest.java プロジェクト: naifshmri/share
 /** Fetches the content of a page at a given version Note - not JSON based. */
 private String getPageAtVersion(String name, String version, int expectedStatus)
     throws Exception {
   Response response =
       sendRequest(new GetRequest(URL_WIKI_VERSION + name + "/" + version), expectedStatus);
   if (expectedStatus == Status.STATUS_OK) {
     return response.getContentAsString();
   } else if (expectedStatus == Status.STATUS_NOT_FOUND) {
     return response.getContentAsString();
   } else {
     return null;
   }
 }
コード例 #4
0
ファイル: WikiRestApiTest.java プロジェクト: naifshmri/share
 private JSONObject getPage(String name, int expectedStatus) throws Exception {
   Response response = sendRequest(new GetRequest(URL_WIKI_FETCH + name), expectedStatus);
   if (expectedStatus == Status.STATUS_OK) {
     JSONObject result = new JSONObject(response.getContentAsString());
     if (result.has("page")) {
       return result.getJSONObject("page");
     }
     return result;
   } else if (expectedStatus == Status.STATUS_NOT_FOUND) {
     JSONObject result = new JSONObject(response.getContentAsString());
     return result;
   } else {
     return null;
   }
 }
コード例 #5
0
ファイル: WikiRestApiTest.java プロジェクト: naifshmri/share
  /** Creates a single wiki page based on the supplied details */
  private JSONObject createOrUpdatePage(
      String pageName, String title, String contents, String version, int expectedStatus)
      throws Exception {
    String name = null;
    if (pageName == null) {
      name = title.replace(' ', '_');
    } else {
      name = pageName;
    }

    JSONObject json = new JSONObject();
    json.put("site", SITE_SHORT_NAME_WIKI);
    json.put("title", title);
    json.put("pagecontent", contents);
    json.put("tags", "");
    json.put("page", "wiki-page"); // TODO Is this really needed?

    if (version == null || "force".equals(version)) {
      // Allow the save as-is, no versioning check
      json.put("forceSave", "true"); // Allow the save as-is
    } else {
      if ("none".equals(version)) {
        // No versioning
      } else {
        json.put("currentVersion", version);
      }
    }

    Response response =
        sendRequest(
            new PutRequest(URL_WIKI_UPDATE + name, json.toString(), "application/json"),
            expectedStatus);
    if (expectedStatus == Status.STATUS_OK) {
      JSONObject result = new JSONObject(response.getContentAsString());
      if (result.has("page")) {
        return result.getJSONObject("page");
      }
      return result;
    } else {
      return null;
    }
  }
コード例 #6
0
ファイル: WikiRestApiTest.java プロジェクト: naifshmri/share
  /** Renames the page */
  private JSONObject renamePage(String oldTitle, String newTitle, int expectedStatus)
      throws Exception {
    String name = oldTitle.replace(' ', '_');

    JSONObject json = new JSONObject();
    json.put("site", SITE_SHORT_NAME_WIKI);
    json.put("name", newTitle);
    json.put("page", "wiki-page"); // TODO Is this really needed?

    Response response =
        sendRequest(
            new PostRequest(URL_WIKI_RENAME + name, json.toString(), "application/json"),
            expectedStatus);
    if (expectedStatus == Status.STATUS_OK) {
      JSONObject result = new JSONObject(response.getContentAsString());
      return result;
    } else {
      return null;
    }
  }
コード例 #7
0
ファイル: WikiRestApiTest.java プロジェクト: naifshmri/share
  private JSONObject getPages(String filter, String username) throws Exception {
    String origUser = this.authenticationComponent.getCurrentUserName();
    if (username != null) {
      this.authenticationComponent.setCurrentUser(username);
      filter = "myPages";
    }

    String url = URL_WIKI_LIST;
    if (filter == null) {
      filter = "all";
    }
    url += "?filter=" + filter;
    url += "&startIndex=0&page=1&pageSize=4";

    Response response = sendRequest(new GetRequest(url), 200);
    JSONObject result = new JSONObject(response.getContentAsString());

    if (username != null) {
      this.authenticationComponent.setCurrentUser(origUser);
    }

    return result;
  }
コード例 #8
0
  public void testMNT11660() throws Exception {
    FormUIGet formUIGet =
        (FormUIGetExtend) ctx.getBean("webscript.org.alfresco.test.components.form.form.get");
    assertNotNull("'FormUIGetExtend' bean for test is null.", formUIGet);

    ConfigSource configSource = new ClassPathConfigSource("test-config-custom-forms.xml");
    XMLConfigService svc = new XMLConfigService(configSource);
    svc.initConfig();

    formUIGet.setConfigService(svc);

    GetRequest requestWithAspect =
        new GetRequest(
            "/test/components/form?htmlid=template_default-formContainer&itemKind=node&itemId="
                + folderWithAspect.toString()
                + "&formId=null&mode=view");
    Response rspFormWithAspect =
        server.submitRequest(
            requestWithAspect.getMethod(),
            requestWithAspect.getFullUri(),
            requestWithAspect.getHeaders(),
            requestWithAspect.getBody(),
            requestWithAspect.getEncoding(),
            requestWithAspect.getType());

    assertEquals(
        "The status of response is " + rspFormWithAspect.getStatus(),
        200,
        rspFormWithAspect.getStatus());

    String contentWithAspect = rspFormWithAspect.getContentAsString();
    log.info(
        "Response form for node with dublincore aspect status is "
            + rspFormWithAspect.getStatus()
            + " content is "
            + contentWithAspect);
    assertNotNull("Response content for 'contentWithAspect' is null", contentWithAspect);
    assertTrue(
        "Return the following content: " + contentWithAspect, contentWithAspect.contains("My Set"));

    GetRequest requestWithoutAspect =
        new GetRequest(
            "/test/components/form?htmlid=template_default-formContainer&itemKind=node&itemId="
                + folderWithoutAspect.toString()
                + "&formId=null&mode=view");
    Response rspFormWithoutAspect =
        server.submitRequest(
            requestWithoutAspect.getMethod(),
            requestWithoutAspect.getFullUri(),
            requestWithoutAspect.getHeaders(),
            requestWithoutAspect.getBody(),
            requestWithoutAspect.getEncoding(),
            requestWithoutAspect.getType());

    assertEquals(
        "The status of response is " + rspFormWithoutAspect.getStatus(),
        200,
        rspFormWithoutAspect.getStatus());

    String contentWithoutAspect = rspFormWithoutAspect.getContentAsString();
    log.info(
        "Response form for node without aspect status is "
            + rspFormWithoutAspect.getStatus()
            + " content is "
            + contentWithoutAspect);
    assertNotNull("Response content for 'contentWithoutAspect' is null", contentWithoutAspect);
    assertFalse(
        "Return the following content: " + contentWithoutAspect,
        contentWithoutAspect.contains("My Set"));
  }
コード例 #9
0
ファイル: WikiRestApiTest.java プロジェクト: naifshmri/share
  public void test_MNT11595() throws Exception {
    final String user = "******";

    try {
      // admin authentication
      this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());

      MutableAuthenticationService mas =
          (MutableAuthenticationService)
              getServer().getApplicationContext().getBean("authenticationService");

      // create user
      createUser(user, SiteModel.SITE_MANAGER);

      assertTrue(personService.personExists(user));

      // invite user to a site with 'Manager' role
      siteService.setMembership(SITE_SHORT_NAME_WIKI, user, SiteRole.SiteManager.toString());

      // user authentication
      this.authenticationComponent.setCurrentUser(user);

      // create wiki page by user ('Manager' role)
      WikiPageInfo wikiPage =
          this.wikiService.createWikiPage(
              SITE_SHORT_NAME_WIKI,
              "test wiki page",
              "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals. Sir Winston Churchill");

      String uri =
          "/slingshot/wiki/page/"
              + SITE_SHORT_NAME_WIKI
              + "/Main_Page?alf_ticket="
              + mas.getCurrentTicket()
              + "application/json";

      Response responseManagerRole = sendRequest(new GetRequest(uri), 404);
      JSONObject resultManagerRole = new JSONObject(responseManagerRole.getContentAsString());
      JSONObject permissionsManagerRole = resultManagerRole.getJSONObject("permissions");
      assertTrue(permissionsManagerRole.getBoolean("create"));
      assertTrue(permissionsManagerRole.getBoolean("edit"));

      // admin authentication
      this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());

      // change user role - 'Consumer' role
      siteService.setMembership(SITE_SHORT_NAME_WIKI, user, SiteRole.SiteConsumer.toString());

      // user authentication
      this.authenticationComponent.setCurrentUser(user);

      Response responseConsumerRole = sendRequest(new GetRequest(uri), 404);
      JSONObject resultConsumerRole = new JSONObject(responseConsumerRole.getContentAsString());
      JSONObject permissionsConsumerRole = resultConsumerRole.getJSONObject("permissions");
      assertFalse(permissionsConsumerRole.getBoolean("create"));
      assertFalse(permissionsConsumerRole.getBoolean("edit"));
    } finally {
      this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());

      if (personService.personExists(user)) {
        personService.deletePerson(user);
      }

      if (this.authenticationService.authenticationExists(user)) {
        this.authenticationService.deleteAuthentication(user);
      }
    }
  }