Search in sources :

Example 76 with PostRequest

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

the class CommentsApiTest method testConsumerCanNotComment.

/**
 * MNT-12082
 */
public void testConsumerCanNotComment() throws Exception {
    // Authenticate as consumer
    authenticationService.authenticate(USER_ONE, USER_ONE.toCharArray());
    String uri = MessageFormat.format(URL_POST_COMMENT, new Object[] { sitePage.getStoreRef().getProtocol(), sitePage.getStoreRef().getIdentifier(), sitePage.getId() });
    Response response = sendRequest(new PostRequest(uri, requestBodyJson, JSON), Status.STATUS_INTERNAL_SERVER_ERROR);
    assertEquals(Status.STATUS_INTERNAL_SERVER_ERROR, response.getStatus());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)

Example 77 with PostRequest

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

the class CommentsApiTest method addComment.

/**
 * add a comment to given node ref
 *
 * @param nodeRef
 * @param user
 * @param status
 * @return
 * @throws Exception
 */
private Response addComment(NodeRef nodeRef, String user, int status) throws Exception {
    Response response = null;
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    // Not allowed if you're not an admin
    AuthenticationUtil.setFullyAuthenticatedUser(user);
    // add comment and save response (comment nodeRef)
    StringBuilder body = new StringBuilder("{");
    body.append("\"itemTitle\" : \"Test Title\", ");
    body.append("\"content\" : \"Test Comment\", ");
    body.append("\"pageParams\" : \"{\\\"nodeRef\\\" : \\\"");
    body.append(nodeRef.getStoreRef().getProtocol());
    body.append(":\\/\\/");
    body.append(nodeRef.getStoreRef().getIdentifier());
    body.append("\\/");
    body.append(nodeRef.getId());
    body.append("\\\"}");
    if (nodeRef.equals(sitePage)) {
        body.append("\",\"site\" : \"");
        body.append(SITE_SHORT_NAME);
    }
    body.append("\"}");
    response = sendRequest(new PostRequest(MessageFormat.format(URL_POST_COMMENT, new Object[] { nodeRef.getStoreRef().getProtocol(), nodeRef.getStoreRef().getIdentifier(), nodeRef.getId() }), body.toString(), JSON), status);
    assertEquals(status, response.getStatus());
    // around the calls.  if the WebScript fails, then we should rollback.
    if (response.getStatus() == 500) {
        txn.rollback();
    } else {
        txn.commit();
    }
    return response;
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) UserTransaction(javax.transaction.UserTransaction) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest) JSONObject(org.json.simple.JSONObject)

Example 78 with PostRequest

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

the class CommentsApiTest method testContributorCanComment.

/**
 * MNT-12082
 */
public void testContributorCanComment() throws Exception {
    // Authenticate as contributor
    authenticationService.authenticate(USER_TWO, USER_TWO.toCharArray());
    String uri = MessageFormat.format(URL_POST_COMMENT, new Object[] { sitePage.getStoreRef().getProtocol(), sitePage.getStoreRef().getIdentifier(), sitePage.getId() });
    Response response = sendRequest(new PostRequest(uri, requestBodyJson, JSON), Status.STATUS_OK);
    assertEquals(Status.STATUS_OK, response.getStatus());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) PostRequest(org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)

Example 79 with PostRequest

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

the class CustomModelImportTest method testUploadModel_UnsupportedModelElements.

public void testUploadModel_UnsupportedModelElements() throws Exception {
    // Note: here we only test a couple of not-supported model elements to check for the correct status code.
    // This test should be removed when we implement the required support
    long timestamp = System.currentTimeMillis();
    final String modelName = getClass().getSimpleName() + timestamp;
    final String prefix = "prefix" + timestamp;
    final String uri = "uriNamespace" + timestamp;
    final String aspectName = prefix + QName.NAMESPACE_PREFIX + "testAspec";
    final String typeName = prefix + QName.NAMESPACE_PREFIX + "testType";
    final String associationName = prefix + QName.NAMESPACE_PREFIX + "testAssociation";
    M2Model model = M2Model.createModel(prefix + QName.NAMESPACE_PREFIX + modelName);
    model.createNamespace(uri, prefix);
    model.setAuthor("John Doe");
    model.createAspect(aspectName);
    model.createImport(NamespaceService.CONTENT_MODEL_1_0_URI, NamespaceService.CONTENT_MODEL_PREFIX);
    M2Type type = model.createType(typeName);
    // Add 'association' not supported yet.
    M2Association association = type.createAssociation(associationName);
    association.setSourceMandatory(false);
    association.setSourceMany(false);
    association.setTargetMandatory(false);
    association.setTargetClassName("cm:content");
    ByteArrayOutputStream xml = new ByteArrayOutputStream();
    model.toXML(xml);
    ZipEntryContext context = new ZipEntryContext(modelName + ".xml", xml.toByteArray());
    File zipFile = createZip(context);
    PostRequest postRequest = buildMultipartPostRequest(zipFile);
    // <associations> element is not supported yet
    sendRequest(postRequest, 409);
    type.removeAssociation(associationName);
    // Add 'mandatory-aspect' not supported yet.
    type.addMandatoryAspect(aspectName);
    xml = new ByteArrayOutputStream();
    model.toXML(xml);
    context = new ZipEntryContext(modelName + ".xml", xml.toByteArray());
    zipFile = createZip(context);
    postRequest = buildMultipartPostRequest(zipFile);
    // <mandatory-aspects> element is not supported yet
    sendRequest(postRequest, 409);
}
Also used : M2Association(org.alfresco.repo.dictionary.M2Association) M2Type(org.alfresco.repo.dictionary.M2Type) 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 80 with PostRequest

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

the class CustomModelImportTest method testInvalidNumberOfZipEntries.

public void testInvalidNumberOfZipEntries() throws Exception {
    long timestamp = System.currentTimeMillis();
    String modelName = getClass().getSimpleName() + timestamp;
    String prefix = "prefix" + timestamp;
    String uri = "uriNamespace" + timestamp;
    // Model one
    M2Model modelOne = M2Model.createModel(prefix + QName.NAMESPACE_PREFIX + modelName);
    modelOne.createNamespace(uri, prefix);
    modelOne.setDescription("Model 1");
    ByteArrayOutputStream xml = new ByteArrayOutputStream();
    modelOne.toXML(xml);
    ZipEntryContext contextOne = new ZipEntryContext(modelName + ".xml", xml.toByteArray());
    // Model two
    modelName += "two";
    prefix += "two";
    uri += "two";
    M2Model modelTwo = M2Model.createModel(prefix + QName.NAMESPACE_PREFIX + modelName);
    modelTwo.createNamespace(uri, prefix);
    modelTwo.setDescription("Model 2");
    xml = new ByteArrayOutputStream();
    modelTwo.toXML(xml);
    ZipEntryContext contextTwo = new ZipEntryContext(modelName + ".xml", xml.toByteArray());
    // Model three
    modelName += "three";
    prefix += "three";
    uri += "three";
    M2Model modelThree = M2Model.createModel(prefix + QName.NAMESPACE_PREFIX + modelName);
    modelThree.createNamespace(uri, prefix);
    modelThree.setDescription("Model 3");
    xml = new ByteArrayOutputStream();
    modelThree.toXML(xml);
    ZipEntryContext contextThree = new ZipEntryContext(modelName + ".xml", xml.toByteArray());
    File zipFile = createZip(contextOne, contextTwo, contextThree);
    PostRequest postRequest = buildMultipartPostRequest(zipFile);
    // more than two zip entries
    sendRequest(postRequest, 400);
}
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)

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