mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-15 15:02:20 +00:00
Merged 5.2.N (5.2.1) to HEAD (5.2)
127392 rmunteanu: Merged 5.1.N (5.1.2) to 5.2.N (5.2.1) 127369 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 127276 aleahu: MNT-15345 : Dynamic Deployment of Models can cause a stack overlow error that causes excessive logging - checking if a model's namespace is also imported, if so throwing a compilation error git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@127884 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1095,4 +1095,124 @@ public class DictionaryModelTypeTest extends BaseSpringTest
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* MNT-15345 test */
|
||||
public void testImportingSameNamespaceFails() throws Exception
|
||||
{
|
||||
// Create model
|
||||
txn = transactionService.getUserTransaction();
|
||||
txn.begin();
|
||||
final NodeRef modelNode = createActiveModel("dictionary/testModel.xml");
|
||||
txn.commit();
|
||||
|
||||
// add second model to introduce self referencing dependency
|
||||
txn = transactionService.getUserTransaction();
|
||||
txn.begin();
|
||||
PropertyMap properties = new PropertyMap(1);
|
||||
properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
|
||||
final NodeRef modelNode2 = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "dictionaryModels"),
|
||||
ContentModel.TYPE_DICTIONARY_MODEL,
|
||||
properties).getChildRef();
|
||||
txn.commit();
|
||||
|
||||
try
|
||||
{
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
|
||||
public Void execute() throws Exception {
|
||||
ContentWriter contentWriter = DictionaryModelTypeTest.this.contentService.getWriter(modelNode2, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.putContent(Thread.currentThread().getContextClassLoader().getResourceAsStream("dictionary/testModel2.xml"));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
fail("Validation should fail as a circular dependency was introduced");
|
||||
} catch(AlfrescoRuntimeException e)
|
||||
{
|
||||
assertTrue(e.getCause().getMessage().contains("URI mage.model cannot be imported as it is already contained in the model's namespaces"));
|
||||
}
|
||||
|
||||
//delete model
|
||||
finally
|
||||
{
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||
new RetryingTransactionCallback<Object>() {
|
||||
public Object execute() throws Exception {
|
||||
// Delete the model
|
||||
DictionaryModelTypeTest.this.nodeService.deleteNode(modelNode);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* MNT-15345 test */
|
||||
public void testImportingSameNamespaceFailsWithinSingleModel() throws Exception
|
||||
{
|
||||
// Create model
|
||||
txn = transactionService.getUserTransaction();
|
||||
txn.begin();
|
||||
PropertyMap properties = new PropertyMap(1);
|
||||
properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
|
||||
final NodeRef modelNode = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "dictionaryModels"),
|
||||
ContentModel.TYPE_DICTIONARY_MODEL,
|
||||
properties).getChildRef();
|
||||
assertNotNull(modelNode);
|
||||
txn.commit();
|
||||
|
||||
// update model to introduce self referencing dependency
|
||||
try
|
||||
{
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>() {
|
||||
public Void execute() throws Exception {
|
||||
|
||||
ContentWriter contentWriter = contentService.getWriter(modelNode, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.setEncoding("UTF-8");
|
||||
contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
|
||||
contentWriter.putContent(Thread.currentThread().getContextClassLoader().getResourceAsStream("dictionary/modelWithCurrentNamespaceImported.xml"));
|
||||
return null;
|
||||
}
|
||||
});
|
||||
fail("Validation should fail as a circular dependency was introduced");
|
||||
} catch(AlfrescoRuntimeException e)
|
||||
{
|
||||
assertTrue(e.getCause().getMessage().contains("URI http://www.alfresco.org/model/dictionary/1.0 cannot be imported as it is already contained in the model's namespaces"));
|
||||
}
|
||||
|
||||
//delete model
|
||||
finally
|
||||
{
|
||||
transactionService.getRetryingTransactionHelper().doInTransaction(
|
||||
new RetryingTransactionCallback<Object>() {
|
||||
public Object execute() throws Exception {
|
||||
// Delete the model
|
||||
DictionaryModelTypeTest.this.nodeService.deleteNode(modelNode);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private NodeRef createActiveModel(String contentFile)
|
||||
{
|
||||
PropertyMap properties = new PropertyMap(1);
|
||||
properties.put(ContentModel.PROP_MODEL_ACTIVE, true);
|
||||
NodeRef modelNode = this.nodeService.createNode(
|
||||
this.rootNodeRef,
|
||||
ContentModel.ASSOC_CHILDREN,
|
||||
QName.createQName(NamespaceService.ALFRESCO_URI, "dictionaryModels"),
|
||||
ContentModel.TYPE_DICTIONARY_MODEL,
|
||||
properties).getChildRef();
|
||||
assertNotNull(modelNode);
|
||||
|
||||
ContentWriter contentWriter = this.contentService.getWriter(modelNode, ContentModel.PROP_CONTENT, true);
|
||||
contentWriter.setEncoding("UTF-8");
|
||||
contentWriter.setMimetype(MimetypeMap.MIMETYPE_XML);
|
||||
contentWriter.putContent(Thread.currentThread().getContextClassLoader().getResourceAsStream(contentFile));
|
||||
return modelNode;
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.alfresco.org/model/dictionary/1.0 ../../../../webapps/alfresco/WEB-INF/classes/alfresco/model/modelSchema.xsd"
|
||||
xmlns="http://www.alfresco.org/model/dictionary/1.0" name="d:modelextended">
|
||||
|
||||
<description>Mage-Ml Metadata Model</description>
|
||||
<author>Sergio D'Ascia</author>
|
||||
<version>1.0</version>
|
||||
<imports>
|
||||
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
|
||||
</imports>
|
||||
<namespaces>
|
||||
<namespace uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
|
||||
</namespaces>
|
||||
<types>
|
||||
</types>
|
||||
</model>
|
18
source/test-resources/dictionary/testModel.xml
Normal file
18
source/test-resources/dictionary/testModel.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.alfresco.org/model/dictionary/1.0 ../../../../webapps/alfresco/WEB-INF/classes/alfresco/model/modelSchema.xsd"
|
||||
xmlns="http://www.alfresco.org/model/dictionary/1.0" name="mage:model">
|
||||
|
||||
<description>Mage-Ml Metadata Model</description>
|
||||
<author>Sergio D'Ascia</author>
|
||||
<version>1.0</version>
|
||||
<imports>
|
||||
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
|
||||
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
|
||||
</imports>
|
||||
<namespaces>
|
||||
<namespace uri="mage.model" prefix="mage"/>
|
||||
</namespaces>
|
||||
<types>
|
||||
</types>
|
||||
</model>
|
19
source/test-resources/dictionary/testModel2.xml
Normal file
19
source/test-resources/dictionary/testModel2.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.alfresco.org/model/dictionary/1.0 ../../../../webapps/alfresco/WEB-INF/classes/alfresco/model/modelSchema.xsd"
|
||||
xmlns="http://www.alfresco.org/model/dictionary/1.0" name="mage:modelextended">
|
||||
|
||||
<description>Mage-Ml Metadata Model</description>
|
||||
<author>Sergio D'Ascia</author>
|
||||
<version>1.0</version>
|
||||
<imports>
|
||||
<import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d"/>
|
||||
<import uri="http://www.alfresco.org/model/content/1.0" prefix="cm"/>
|
||||
<import uri="mage.model" prefix="mage"/>
|
||||
</imports>
|
||||
<namespaces>
|
||||
<namespace uri="mage.model" prefix="mage"/>
|
||||
</namespaces>
|
||||
<types>
|
||||
</types>
|
||||
</model>
|
Reference in New Issue
Block a user