Search in sources :

Example 1 with M2Association

use of org.alfresco.repo.dictionary.M2Association 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)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ZipFile (java.util.zip.ZipFile)1 M2Association (org.alfresco.repo.dictionary.M2Association)1 M2Model (org.alfresco.repo.dictionary.M2Model)1 M2Type (org.alfresco.repo.dictionary.M2Type)1 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)1