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:
Philippe Dubois
2011-08-19 14:23:51 +00:00
parent 021a93f5c3
commit 696db9924d

View File

@@ -36,6 +36,7 @@ import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
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.ContentData;
import org.alfresco.service.cmr.repository.ContentService;
@@ -56,27 +57,29 @@ import org.alfresco.util.TempFileProvider;
*
* @author Mark Rogers
*/
public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
{
private TransferService transferService;
private PermissionService permissionService;
private ContentService contentService;
private DictionaryService dictionaryService;
private NodeService mlAwareNodeService;
/**
* Called during the transaction setup
*/
protected void onSetUpInTransaction() throws Exception
{
super.onSetUpInTransaction();
// Get the required services
this.transferService = (TransferService)this.applicationContext.getBean("TransferService");
this.contentService = (ContentService)this.applicationContext.getBean("ContentService");
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
{
// Snapshot a transfer node
@@ -85,7 +88,7 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
String CONTENT_TITLE = "the title";
String CONTENT_NAME = "&the name <\\*"; // nasty name for XML
String CONTENT_ASSOC_NAME = "&hell+-1we";
String snapshotMe = "snapshotMe";
String title = "title";
String description = "description";
@@ -95,42 +98,43 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
String endpointPath = "rhubarb";
String username = "admin";
char[] password = "password".toCharArray();
Map<NodeRef, TransferManifestNode> sentNodes = new HashMap<NodeRef, TransferManifestNode>();
TransferManifestNodeFactoryImpl nodeFactory = new TransferManifestNodeFactoryImpl();
nodeFactory.setNodeService(nodeService);
nodeFactory.setPermissionService(permissionService);
nodeFactory.setDictionaryService(dictionaryService);
nodeFactory.setMlAwareNodeService(mlAwareNodeService);
/**
* Create our transfer target
*/
TransferTarget target = transferService.createAndSaveTransferTarget(snapshotMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
File snapshotFile = null;
try
{
/**
* 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);
NodeRef childNodeRef = child.getChildRef();
ContentWriter writer = contentService.getWriter(childNodeRef, ContentModel.PROP_CONTENT, true);
writer.setLocale(CONTENT_LOCALE);
writer.putContent(CONTENT_STRING);
nodeService.setProperty(childNodeRef, ContentModel.PROP_TITLE, CONTENT_TITLE);
nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, CONTENT_NAME);
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>();
/**
* Write three nodes
* 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(target.getNodeRef());
nodes.add(childNodeRef);
TransferManifestWriter formatter = new XMLTransferManifestWriter();
TransferManifestHeader header = new TransferManifestHeader();
header.setNodeCount(nodes.size());
@@ -155,26 +159,26 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
}
formatter.endTransferManifest();
snapshotWriter.close();
// Show the snapshot file (For dev purposes)
outputFile(snapshotFile);
/**
* Now read the snapshot file
*/
TestTransferManifestProcessor processor = new TestTransferManifestProcessor();
TestTransferManifestProcessor processor = new TestTransferManifestProcessor();
XMLTransferManifestReader reader = new XMLTransferManifestReader(processor);
SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
SAXParser parser = saxParserFactory.newSAXParser();
parser.parse(snapshotFile, reader);
/**
* 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());
assertNotNull("header is null", processor.getHeader());
for(NodeRef nodeId : nodes)
{
System.out.println("Processing node:" + nodeId);
@@ -182,7 +186,7 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
TransferManifestNormalNode writeNode = (TransferManifestNormalNode)sentNodes.get(nodeId);
assertNotNull("readNode is null", readNode);
assertNotNull("writeNode is null", writeNode);
assertEquals("type is different", writeNode.getType(), readNode.getType());
assertEquals("nodeRef is different", writeNode.getNodeRef(), readNode.getNodeRef());
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));
}
assertEquals("properties array different size", writeNode.getProperties().size(), readNode.getProperties().size());
for(QName prop : writeNode.getProperties().keySet())
{
assertTrue("missing property", readNode.getProperties().containsKey(prop));
}
assertEquals("child assocs different", writeNode.getChildAssocs().size(), readNode.getChildAssocs().size());
assertEquals("parent assocs different", writeNode.getParentAssocs().size(), readNode.getParentAssocs().size());
assertEquals("source assocs different", writeNode.getSourceAssocs().size(), readNode.getSourceAssocs().size());
assertEquals("target assocs different", writeNode.getTargetAssocs().size(), readNode.getTargetAssocs().size());
if(readNode.getNodeRef().equals(childNodeRef))
{
/**
@@ -216,13 +220,13 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
ContentData data = (ContentData)readNode.getProperties().get(ContentModel.PROP_CONTENT);
assertEquals("content data wrong size", data.getSize(), CONTENT_STRING.length());
assertEquals("content locale wrong", data.getLocale(), CONTENT_LOCALE);
String childTitle = ((MLText)readNode.getProperties().get(ContentModel.PROP_TITLE)).getDefaultValue();
assertEquals("content title wrong", childTitle, CONTENT_TITLE);
String childName = (String)readNode.getProperties().get(ContentModel.PROP_NAME);
assertEquals("content name wrong", childName, CONTENT_NAME);
/**
* 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("child node ref", readNode.getParentAssocs().get(0).getChildRef(), childNodeRef);
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
*/
assertEquals(readNode.getParentAssocs().get(0), TransferManifestNodeHelper.getPrimaryParentAssoc(readNode));
Set<ContentData> content = TransferManifestNodeHelper.getContentData(readNode);
assertEquals("content not found", content.size(), 1);
}
@@ -253,7 +257,7 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
transferService.deleteTransferTarget(snapshotMe);
}
}
/**
* Utility to dump the contents of a file to the console
* @param file