diff --git a/source/test-java/org/alfresco/repo/dictionary/DictionaryModelTypeTest.java b/source/test-java/org/alfresco/repo/dictionary/DictionaryModelTypeTest.java index 17a7029f69..1551761d74 100644 --- a/source/test-java/org/alfresco/repo/dictionary/DictionaryModelTypeTest.java +++ b/source/test-java/org/alfresco/repo/dictionary/DictionaryModelTypeTest.java @@ -1142,8 +1142,59 @@ public class DictionaryModelTypeTest extends BaseSpringTest // 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() { + 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() { + public Object execute() throws Exception { + // Delete the model + DictionaryModelTypeTest.this.nodeService.deleteNode(modelNode); + return null; + } + }); + } } public void testCircularDependencyDetected() throws Exception @@ -1225,73 +1276,3 @@ public class DictionaryModelTypeTest extends BaseSpringTest return modelNode; } } - - /* 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() { - 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() { - 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; - } -}