mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fix for java.lang.NullPointerException in org.alfresco.repo.transfer.manifest.ManifestIntegrationTest.testSnapshot, DictionaryService injected
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29924 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -36,6 +36,7 @@ import javax.xml.parsers.SAXParser;
|
|||||||
import javax.xml.parsers.SAXParserFactory;
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
|
|
||||||
import org.alfresco.model.ContentModel;
|
import org.alfresco.model.ContentModel;
|
||||||
|
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.ContentData;
|
import org.alfresco.service.cmr.repository.ContentData;
|
||||||
import org.alfresco.service.cmr.repository.ContentService;
|
import org.alfresco.service.cmr.repository.ContentService;
|
||||||
@@ -56,27 +57,29 @@ import org.alfresco.util.TempFileProvider;
|
|||||||
*
|
*
|
||||||
* @author Mark Rogers
|
* @author Mark Rogers
|
||||||
*/
|
*/
|
||||||
public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
||||||
{
|
{
|
||||||
private TransferService transferService;
|
private TransferService transferService;
|
||||||
private PermissionService permissionService;
|
private PermissionService permissionService;
|
||||||
private ContentService contentService;
|
private ContentService contentService;
|
||||||
|
private DictionaryService dictionaryService;
|
||||||
private NodeService mlAwareNodeService;
|
private NodeService mlAwareNodeService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called during the transaction setup
|
* Called during the transaction setup
|
||||||
*/
|
*/
|
||||||
protected void onSetUpInTransaction() throws Exception
|
protected void onSetUpInTransaction() throws Exception
|
||||||
{
|
{
|
||||||
super.onSetUpInTransaction();
|
super.onSetUpInTransaction();
|
||||||
|
|
||||||
// Get the required services
|
// Get the required services
|
||||||
this.transferService = (TransferService)this.applicationContext.getBean("TransferService");
|
this.transferService = (TransferService)this.applicationContext.getBean("TransferService");
|
||||||
this.contentService = (ContentService)this.applicationContext.getBean("ContentService");
|
this.contentService = (ContentService)this.applicationContext.getBean("ContentService");
|
||||||
this.permissionService = (PermissionService)this.applicationContext.getBean("PermissionService");
|
this.permissionService = (PermissionService)this.applicationContext.getBean("PermissionService");
|
||||||
this.mlAwareNodeService = (NodeService) this.applicationContext.getBean("mlAwareNodeService");
|
this.dictionaryService = (DictionaryService)this.applicationContext.getBean("DictionaryService");
|
||||||
|
this.mlAwareNodeService = (NodeService) this.applicationContext.getBean("mlAwareNodeService");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSnapshot() throws Exception
|
public void testSnapshot() throws Exception
|
||||||
{
|
{
|
||||||
// Snapshot a transfer node
|
// Snapshot a transfer node
|
||||||
@@ -85,7 +88,7 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
String CONTENT_TITLE = "the title";
|
String CONTENT_TITLE = "the title";
|
||||||
String CONTENT_NAME = "&the name <\\*"; // nasty name for XML
|
String CONTENT_NAME = "&the name <\\*"; // nasty name for XML
|
||||||
String CONTENT_ASSOC_NAME = "&hell+-1we";
|
String CONTENT_ASSOC_NAME = "&hell+-1we";
|
||||||
|
|
||||||
String snapshotMe = "snapshotMe";
|
String snapshotMe = "snapshotMe";
|
||||||
String title = "title";
|
String title = "title";
|
||||||
String description = "description";
|
String description = "description";
|
||||||
@@ -95,42 +98,43 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
String endpointPath = "rhubarb";
|
String endpointPath = "rhubarb";
|
||||||
String username = "admin";
|
String username = "admin";
|
||||||
char[] password = "password".toCharArray();
|
char[] password = "password".toCharArray();
|
||||||
|
|
||||||
Map<NodeRef, TransferManifestNode> sentNodes = new HashMap<NodeRef, TransferManifestNode>();
|
Map<NodeRef, TransferManifestNode> sentNodes = new HashMap<NodeRef, TransferManifestNode>();
|
||||||
|
|
||||||
TransferManifestNodeFactoryImpl nodeFactory = new TransferManifestNodeFactoryImpl();
|
TransferManifestNodeFactoryImpl nodeFactory = new TransferManifestNodeFactoryImpl();
|
||||||
nodeFactory.setNodeService(nodeService);
|
nodeFactory.setNodeService(nodeService);
|
||||||
nodeFactory.setPermissionService(permissionService);
|
nodeFactory.setPermissionService(permissionService);
|
||||||
|
nodeFactory.setDictionaryService(dictionaryService);
|
||||||
nodeFactory.setMlAwareNodeService(mlAwareNodeService);
|
nodeFactory.setMlAwareNodeService(mlAwareNodeService);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create our transfer target
|
* Create our transfer target
|
||||||
*/
|
*/
|
||||||
TransferTarget target = transferService.createAndSaveTransferTarget(snapshotMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
|
TransferTarget target = transferService.createAndSaveTransferTarget(snapshotMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
|
||||||
|
|
||||||
File snapshotFile = null;
|
File snapshotFile = null;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Create a test node that we will read and write
|
* Create a test node that we will read and write
|
||||||
*/
|
*/
|
||||||
ChildAssociationRef child = nodeService.createNode(target.getNodeRef(), ContentModel.ASSOC_CONTAINS, QName.createQName(CONTENT_ASSOC_NAME), ContentModel.TYPE_CONTENT);
|
ChildAssociationRef child = nodeService.createNode(target.getNodeRef(), ContentModel.ASSOC_CONTAINS, QName.createQName(CONTENT_ASSOC_NAME), ContentModel.TYPE_CONTENT);
|
||||||
|
|
||||||
NodeRef childNodeRef = child.getChildRef();
|
NodeRef childNodeRef = child.getChildRef();
|
||||||
ContentWriter writer = contentService.getWriter(childNodeRef, ContentModel.PROP_CONTENT, true);
|
ContentWriter writer = contentService.getWriter(childNodeRef, ContentModel.PROP_CONTENT, true);
|
||||||
writer.setLocale(CONTENT_LOCALE);
|
writer.setLocale(CONTENT_LOCALE);
|
||||||
writer.putContent(CONTENT_STRING);
|
writer.putContent(CONTENT_STRING);
|
||||||
|
|
||||||
nodeService.setProperty(childNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);
|
nodeService.setProperty(childNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);
|
||||||
|
|
||||||
nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, CONTENT_NAME);
|
nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, CONTENT_NAME);
|
||||||
|
|
||||||
snapshotFile = TempFileProvider.createTempFile("xxx", ".xml");
|
snapshotFile = TempFileProvider.createTempFile("xxx", ".xml");
|
||||||
Writer snapshotWriter = new OutputStreamWriter(new FileOutputStream(snapshotFile), "UTF-8");
|
Writer snapshotWriter = new OutputStreamWriter(new FileOutputStream(snapshotFile), "UTF-8");
|
||||||
|
|
||||||
Set<NodeRef> nodes = new HashSet<NodeRef>();
|
Set<NodeRef> nodes = new HashSet<NodeRef>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write three nodes
|
* Write three nodes
|
||||||
* a: the root node of the workspace store
|
* a: the root node of the workspace store
|
||||||
@@ -140,7 +144,7 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
nodes.add(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE));
|
nodes.add(nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE));
|
||||||
nodes.add(target.getNodeRef());
|
nodes.add(target.getNodeRef());
|
||||||
nodes.add(childNodeRef);
|
nodes.add(childNodeRef);
|
||||||
|
|
||||||
TransferManifestWriter formatter = new XMLTransferManifestWriter();
|
TransferManifestWriter formatter = new XMLTransferManifestWriter();
|
||||||
TransferManifestHeader header = new TransferManifestHeader();
|
TransferManifestHeader header = new TransferManifestHeader();
|
||||||
header.setNodeCount(nodes.size());
|
header.setNodeCount(nodes.size());
|
||||||
@@ -155,26 +159,26 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
}
|
}
|
||||||
formatter.endTransferManifest();
|
formatter.endTransferManifest();
|
||||||
snapshotWriter.close();
|
snapshotWriter.close();
|
||||||
|
|
||||||
// Show the snapshot file (For dev purposes)
|
// Show the snapshot file (For dev purposes)
|
||||||
outputFile(snapshotFile);
|
outputFile(snapshotFile);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now read the snapshot file
|
* Now read the snapshot file
|
||||||
*/
|
*/
|
||||||
TestTransferManifestProcessor processor = new TestTransferManifestProcessor();
|
TestTransferManifestProcessor processor = new TestTransferManifestProcessor();
|
||||||
XMLTransferManifestReader reader = new XMLTransferManifestReader(processor);
|
XMLTransferManifestReader reader = new XMLTransferManifestReader(processor);
|
||||||
|
|
||||||
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
|
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
|
||||||
SAXParser parser = saxParserFactory.newSAXParser();
|
SAXParser parser = saxParserFactory.newSAXParser();
|
||||||
parser.parse(snapshotFile, reader);
|
parser.parse(snapshotFile, reader);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Now validate that we read back what we write out
|
* Now validate that we read back what we write out
|
||||||
*/
|
*/
|
||||||
assertEquals("did not get back the same number of nodes", nodes.size(), processor.getNodes().size());
|
assertEquals("did not get back the same number of nodes", nodes.size(), processor.getNodes().size());
|
||||||
assertNotNull("header is null", processor.getHeader());
|
assertNotNull("header is null", processor.getHeader());
|
||||||
|
|
||||||
for(NodeRef nodeId : nodes)
|
for(NodeRef nodeId : nodes)
|
||||||
{
|
{
|
||||||
System.out.println("Processing node:" + nodeId);
|
System.out.println("Processing node:" + nodeId);
|
||||||
@@ -182,7 +186,7 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
TransferManifestNormalNode writeNode = (TransferManifestNormalNode)sentNodes.get(nodeId);
|
TransferManifestNormalNode writeNode = (TransferManifestNormalNode)sentNodes.get(nodeId);
|
||||||
assertNotNull("readNode is null", readNode);
|
assertNotNull("readNode is null", readNode);
|
||||||
assertNotNull("writeNode is null", writeNode);
|
assertNotNull("writeNode is null", writeNode);
|
||||||
|
|
||||||
assertEquals("type is different", writeNode.getType(), readNode.getType());
|
assertEquals("type is different", writeNode.getType(), readNode.getType());
|
||||||
assertEquals("nodeRef is different", writeNode.getNodeRef(), readNode.getNodeRef());
|
assertEquals("nodeRef is different", writeNode.getNodeRef(), readNode.getNodeRef());
|
||||||
assertEquals("parent node ref is different", writeNode.getPrimaryParentAssoc(), readNode.getPrimaryParentAssoc());
|
assertEquals("parent node ref is different", writeNode.getPrimaryParentAssoc(), readNode.getPrimaryParentAssoc());
|
||||||
@@ -196,18 +200,18 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
{
|
{
|
||||||
assertTrue("missing aspect", readNode.getAspects().contains(aspect));
|
assertTrue("missing aspect", readNode.getAspects().contains(aspect));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals("properties array different size", writeNode.getProperties().size(), readNode.getProperties().size());
|
assertEquals("properties array different size", writeNode.getProperties().size(), readNode.getProperties().size());
|
||||||
for(QName prop : writeNode.getProperties().keySet())
|
for(QName prop : writeNode.getProperties().keySet())
|
||||||
{
|
{
|
||||||
assertTrue("missing property", readNode.getProperties().containsKey(prop));
|
assertTrue("missing property", readNode.getProperties().containsKey(prop));
|
||||||
}
|
}
|
||||||
|
|
||||||
assertEquals("child assocs different", writeNode.getChildAssocs().size(), readNode.getChildAssocs().size());
|
assertEquals("child assocs different", writeNode.getChildAssocs().size(), readNode.getChildAssocs().size());
|
||||||
assertEquals("parent assocs different", writeNode.getParentAssocs().size(), readNode.getParentAssocs().size());
|
assertEquals("parent assocs different", writeNode.getParentAssocs().size(), readNode.getParentAssocs().size());
|
||||||
assertEquals("source assocs different", writeNode.getSourceAssocs().size(), readNode.getSourceAssocs().size());
|
assertEquals("source assocs different", writeNode.getSourceAssocs().size(), readNode.getSourceAssocs().size());
|
||||||
assertEquals("target assocs different", writeNode.getTargetAssocs().size(), readNode.getTargetAssocs().size());
|
assertEquals("target assocs different", writeNode.getTargetAssocs().size(), readNode.getTargetAssocs().size());
|
||||||
|
|
||||||
if(readNode.getNodeRef().equals(childNodeRef))
|
if(readNode.getNodeRef().equals(childNodeRef))
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
@@ -216,13 +220,13 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
ContentData data = (ContentData)readNode.getProperties().get(ContentModel.PROP_CONTENT);
|
ContentData data = (ContentData)readNode.getProperties().get(ContentModel.PROP_CONTENT);
|
||||||
assertEquals("content data wrong size", data.getSize(), CONTENT_STRING.length());
|
assertEquals("content data wrong size", data.getSize(), CONTENT_STRING.length());
|
||||||
assertEquals("content locale wrong", data.getLocale(), CONTENT_LOCALE);
|
assertEquals("content locale wrong", data.getLocale(), CONTENT_LOCALE);
|
||||||
|
|
||||||
String childTitle = ((MLText)readNode.getProperties().get(ContentModel.PROP_TITLE)).getDefaultValue();
|
String childTitle = ((MLText)readNode.getProperties().get(ContentModel.PROP_TITLE)).getDefaultValue();
|
||||||
assertEquals("content title wrong", childTitle, CONTENT_TITLE);
|
assertEquals("content title wrong", childTitle, CONTENT_TITLE);
|
||||||
|
|
||||||
String childName = (String)readNode.getProperties().get(ContentModel.PROP_NAME);
|
String childName = (String)readNode.getProperties().get(ContentModel.PROP_NAME);
|
||||||
assertEquals("content name wrong", childName, CONTENT_NAME);
|
assertEquals("content name wrong", childName, CONTENT_NAME);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check the parent associations, there should be only one primary
|
* Check the parent associations, there should be only one primary
|
||||||
*/
|
*/
|
||||||
@@ -232,13 +236,13 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
assertEquals("parent type q name", readNode.getParentAssocs().get(0).getTypeQName(), ContentModel.ASSOC_CONTAINS);
|
assertEquals("parent type q name", readNode.getParentAssocs().get(0).getTypeQName(), ContentModel.ASSOC_CONTAINS);
|
||||||
assertEquals("child node ref", readNode.getParentAssocs().get(0).getChildRef(), childNodeRef);
|
assertEquals("child node ref", readNode.getParentAssocs().get(0).getChildRef(), childNodeRef);
|
||||||
assertEquals("parent node ref", readNode.getParentAssocs().get(0).getParentRef(), target.getNodeRef());
|
assertEquals("parent node ref", readNode.getParentAssocs().get(0).getParentRef(), target.getNodeRef());
|
||||||
assertTrue("zero child assoc", readNode.getChildAssocs().size() == 0);
|
assertTrue("zero child assoc", readNode.getChildAssocs().size() == 0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Node Helper
|
* Test Node Helper
|
||||||
*/
|
*/
|
||||||
assertEquals(readNode.getParentAssocs().get(0), TransferManifestNodeHelper.getPrimaryParentAssoc(readNode));
|
assertEquals(readNode.getParentAssocs().get(0), TransferManifestNodeHelper.getPrimaryParentAssoc(readNode));
|
||||||
|
|
||||||
Set<ContentData> content = TransferManifestNodeHelper.getContentData(readNode);
|
Set<ContentData> content = TransferManifestNodeHelper.getContentData(readNode);
|
||||||
assertEquals("content not found", content.size(), 1);
|
assertEquals("content not found", content.size(), 1);
|
||||||
}
|
}
|
||||||
@@ -253,7 +257,7 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
|
|||||||
transferService.deleteTransferTarget(snapshotMe);
|
transferService.deleteTransferTarget(snapshotMe);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility to dump the contents of a file to the console
|
* Utility to dump the contents of a file to the console
|
||||||
* @param file
|
* @param file
|
||||||
|
Reference in New Issue
Block a user