Search in sources :

Example 36 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.

the class CustomModelImportTest method testValidUpload_ModelAndExtModule.

public void testValidUpload_ModelAndExtModule() throws Exception {
    File zipFile = getResourceFile("validModelAndExtModule.zip");
    PostRequest postRequest = buildMultipartPostRequest(zipFile);
    AuthenticationUtil.setFullyAuthenticatedUser(NON_ADMIN_USER);
    Response response = sendRequest(postRequest, 403);
    AuthenticationUtil.setFullyAuthenticatedUser(CUSTOM_MODEL_ADMIN);
    response = sendRequest(postRequest, 200);
    JSONObject json = new JSONObject(new JSONTokener(response.getContentAsString()));
    String importedModelName = json.getString("modelName");
    importedModels.add(importedModelName);
    String extModule = json.getString("shareExtModule");
    Document document = XMLUtil.parse(extModule);
    NodeList nodes = document.getElementsByTagName("id");
    assertEquals(1, nodes.getLength());
    assertNotNull(nodes.item(0).getTextContent());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) NodeList(org.w3c.dom.NodeList) Document(org.w3c.dom.Document) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 37 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.

the class CustomModelImportTest method testUploadModel_Invalid.

public void testUploadModel_Invalid() throws Exception {
    long timestamp = System.currentTimeMillis();
    final String modelName = getClass().getSimpleName() + timestamp;
    final String prefix = "prefix" + timestamp;
    final String uri = "uriNamespace" + timestamp;
    M2Model model = M2Model.createModel(prefix + QName.NAMESPACE_PREFIX + modelName);
    model.setAuthor("Admin");
    model.setDescription("Desc");
    ByteArrayOutputStream xml = new ByteArrayOutputStream();
    model.toXML(xml);
    ZipEntryContext context = new ZipEntryContext(modelName + ".xml", xml.toByteArray());
    File zipFile = createZip(context);
    PostRequest postRequest = buildMultipartPostRequest(zipFile);
    // no namespace has been defined
    sendRequest(postRequest, 409);
    // Create two namespaces
    model.createNamespace(uri, prefix);
    model.createNamespace(uri + "anotherUri", prefix + "anotherPrefix");
    xml = new ByteArrayOutputStream();
    model.toXML(xml);
    context = new ZipEntryContext(modelName + ".xml", xml.toByteArray());
    zipFile = createZip(context);
    postRequest = buildMultipartPostRequest(zipFile);
    // custom model can only have one namespace
    sendRequest(postRequest, 409);
}
Also used : PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) M2Model(org.alfresco.repo.dictionary.M2Model) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 38 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.

the class DiscussionRestApiTest method doCreatePost.

private JSONObject doCreatePost(String url, String title, String content, int expectedStatus) throws Exception {
    JSONObject post = new JSONObject();
    post.put("title", title);
    post.put("content", content);
    Response response = sendRequest(new PostRequest(url, post.toString(), "application/json"), expectedStatus);
    if (expectedStatus != Status.STATUS_OK) {
        return null;
    }
    JSONObject result = new JSONObject(response.getContentAsString());
    JSONObject item = result.getJSONObject("item");
    posts.add(item.getString("name"));
    return item;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject)

Example 39 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.

the class DownloadRestApiTest method testCreateAndGetDownload.

@Test
public void testCreateAndGetDownload() throws UnsupportedEncodingException, IOException, JSONException {
    // CReate the download
    String postData = "[{ \"nodeRef\": \"" + rootFile + "\"}, { \"nodeRef\": \"" + rootFolder + "\"}]";
    Response response = sendRequest(new PostRequest(URL_DOWNLOADS, postData, "application/json"), 200);
    // Parse the response
    JSONObject result = new JSONObject(response.getContentAsString());
    NodeRef downloadNodeRef = new NodeRef(result.getString("nodeRef"));
    // Get the status
    String statusUrl = MessageFormat.format(URL_DOWNLOAD_STATUS, downloadNodeRef.getStoreRef().getProtocol(), downloadNodeRef.getStoreRef().getIdentifier(), downloadNodeRef.getId());
    Response statusResponse = sendRequest(new GetRequest(statusUrl), 200);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) NodeRef(org.alfresco.service.cmr.repository.NodeRef) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) BaseWebScriptTest(org.alfresco.repo.web.scripts.BaseWebScriptTest) Test(org.junit.Test)

Example 40 with PostRequest

use of org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest in project alfresco-remote-api by Alfresco.

the class FacetRestApiTest method testNonSearchAdminUserCannotCreateUpdateSolrFacets.

public void testNonSearchAdminUserCannotCreateUpdateSolrFacets() throws Exception {
    // Create a filter
    final JSONObject filter = new JSONObject();
    final String filterName = "filter" + System.currentTimeMillis();
    filters.add(filterName);
    filter.put("filterID", filterName);
    filter.put("facetQName", "cm:test1");
    filter.put("displayName", "facet-menu.facet.test1");
    filter.put("displayControl", "alfresco/search/FacetFilters/test1");
    filter.put("maxFilters", 5);
    filter.put("hitThreshold", 1);
    filter.put("minFilterValueLength", 4);
    filter.put("sortBy", "ALPHABETICALLY");
    // Non-Search-Admin tries to create a filter
    AuthenticationUtil.runAs(new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            // Post the filter
            sendRequest(new PostRequest(POST_FACETS_URL, filter.toString(), "application/json"), 403);
            return null;
        }
    }, NON_SEARCH_ADMIN_USER);
    // Search-Admin creates a filter
    AuthenticationUtil.runAs(new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            // Post the filter
            sendRequest(new PostRequest(POST_FACETS_URL, filter.toString(), "application/json"), 200);
            return null;
        }
    }, SEARCH_ADMIN_USER);
    // Non-Search-Admin tries to modify the filter
    AuthenticationUtil.runAs(new RunAsWork<Void>() {

        @Override
        public Void doWork() throws Exception {
            Response response = sendRequest(new GetRequest(GET_FACETS_URL + "/" + filterName), 200);
            JSONObject jsonRsp = new JSONObject(new JSONTokener(response.getContentAsString()));
            assertEquals(filterName, jsonRsp.getString("filterID"));
            assertEquals(5, jsonRsp.getInt("maxFilters"));
            // Now change the maxFilters value and try to update
            jsonRsp.put("maxFilters", 10);
            sendRequest(new PutRequest(PUT_FACETS_URL, jsonRsp.toString(), "application/json"), 403);
            return null;
        }
    }, NON_SEARCH_ADMIN_USER);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONTokener(org.json.JSONTokener) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) PutRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest) JSONException(org.json.JSONException) IOException(java.io.IOException)

Aggregations

PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)110 JSONObject (org.json.JSONObject)90 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)84 JSONArray (org.json.JSONArray)28 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)25 JSONTokener (org.json.JSONTokener)23 NodeRef (org.alfresco.service.cmr.repository.NodeRef)22 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)14 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)10 JSONStringer (org.json.JSONStringer)9 File (java.io.File)8 ZipFile (java.util.zip.ZipFile)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 JSONObject (org.json.simple.JSONObject)5 IOException (java.io.IOException)4 UserTransaction (javax.transaction.UserTransaction)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)4 ChildAssociationRef (org.alfresco.service.cmr.repository.ChildAssociationRef)4 JSONException (org.json.JSONException)4 Serializable (java.io.Serializable)3