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());
}
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;
}
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());
}
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);
}
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);
}
Aggregations