use of org.apache.sling.jcr.contentloader.ContentImportListener in project sling by apache.
the class DefaultContentCreatorTest method createReferenceProperty.
@Test
public void createReferenceProperty() throws RepositoryException, NoSuchFieldException {
final String propName = uniqueId();
final String[] propValues = { uniqueId(), uniqueId() };
final ContentImportListener listener = mockery.mock(ContentImportListener.class);
final Map<String, String[]> delayedMultipleReferences = (Map<String, String[]>) PrivateAccessor.getField(contentCreator, "delayedMultipleReferences");
this.mockery.checking(new Expectations() {
{
oneOf(listener).onCreate(with(any(String.class)));
}
});
contentCreator.init(ImportOptionsFactory.createImportOptions(false, false, false, false, false), new HashMap<String, ContentReader>(), null, listener);
contentCreator.prepareParsing(parentNode, DEFAULT_NAME);
contentCreator.createProperty(propName, PropertyType.REFERENCE, propValues);
assertTrue(parentNode.hasProperty(propName));
assertTrue(parentNode.getProperty(propName).isNew());
String referencesKey = parentNode.getPath() + "/" + propName;
String[] uuidsOrPaths = delayedMultipleReferences.get(referencesKey);
assertNotNull(uuidsOrPaths);
assertEquals(propValues.length, uuidsOrPaths.length);
mockery.assertIsSatisfied();
}
use of org.apache.sling.jcr.contentloader.ContentImportListener in project sling by apache.
the class DefaultContentCreatorTest method testCreateReferenceProperty.
@Test
public void testCreateReferenceProperty() throws RepositoryException {
final String propertyName = "foo";
final String propertyValue = "bar";
final String rootNodeName = uniqueId();
final String uuid = "1b8c88d37f0000020084433d3af4941f";
final Session session = mockery.mock(Session.class);
final ContentImportListener listener = mockery.mock(ContentImportListener.class);
parentNode = mockery.mock(Node.class);
prop = mockery.mock(Property.class);
this.mockery.checking(new Expectations() {
{
oneOf(session).itemExists(with(any(String.class)));
will(returnValue(true));
oneOf(session).getItem(with(any(String.class)));
will(returnValue(parentNode));
exactly(2).of(parentNode).getPath();
will(returnValue("/" + rootNodeName));
oneOf(parentNode).isNode();
will(returnValue(true));
oneOf(parentNode).isNodeType("mix:referenceable");
will(returnValue(true));
oneOf(parentNode).getUUID();
will(returnValue(uuid));
oneOf(parentNode).getSession();
will(returnValue(session));
oneOf(parentNode).hasProperty(with(any(String.class)));
oneOf(parentNode).setProperty(propertyName, uuid, PropertyType.REFERENCE);
oneOf(parentNode).getProperty(with(any(String.class)));
oneOf(listener).onCreate(with(any(String.class)));
}
});
contentCreator.init(ImportOptionsFactory.createImportOptions(false, false, false, false, false), new HashMap<String, ContentReader>(), null, listener);
contentCreator.prepareParsing(parentNode, null);
contentCreator.createProperty(propertyName, PropertyType.REFERENCE, propertyValue);
//The only way I found how to test this method is to check numbers of methods calls
mockery.assertIsSatisfied();
}
use of org.apache.sling.jcr.contentloader.ContentImportListener in project sling by apache.
the class DefaultContentCreatorTest method createNodeWithOverwrite.
@Test
public void createNodeWithOverwrite() throws RepositoryException {
final String newNodeName = uniqueId();
final String propertyName = uniqueId();
final String propertyValue = uniqueId();
final ContentImportListener listener = mockery.mock(ContentImportListener.class);
this.mockery.checking(new Expectations() {
{
oneOf(listener).onCreate(with(any(String.class)));
}
});
contentCreator.init(ImportOptionsFactory.createImportOptions(true, false, true, false, false), new HashMap<String, ContentReader>(), null, listener);
contentCreator.prepareParsing(parentNode, DEFAULT_NAME);
Node nodeToOverwrite = parentNode.addNode(newNodeName);
nodeToOverwrite.setProperty(propertyName, propertyValue);
assertTrue(parentNode.getNode(newNodeName).hasProperty(propertyName));
contentCreator.createNode(newNodeName, null, null);
//If node was overwritten(as we expect) it will not contain this property
assertFalse(parentNode.getNode(newNodeName).hasProperty(propertyName));
mockery.assertIsSatisfied();
}
use of org.apache.sling.jcr.contentloader.ContentImportListener in project sling by apache.
the class DefaultContentCreatorTest method finishNodeWithMultipleProperty.
//------DefaultContentCreator#finishNode()------//
@Test
public void finishNodeWithMultipleProperty() throws RepositoryException, NoSuchFieldException {
final String propName = uniqueId();
final String underTestNodeName = uniqueId();
final Map<String, List<String>> delayedMultipleReferences = (Map<String, List<String>>) PrivateAccessor.getField(contentCreator, "delayedMultipleReferences");
final ContentImportListener listener = mockery.mock(ContentImportListener.class);
this.mockery.checking(new Expectations() {
{
exactly(3).of(listener).onCreate(with(any(String.class)));
}
});
contentCreator.init(ImportOptionsFactory.createImportOptions(false, false, false, false, false), new HashMap<String, ContentReader>(), null, listener);
contentCreator.prepareParsing(parentNode, null);
contentCreator.createProperty(propName, PropertyType.REFERENCE, new String[] { underTestNodeName });
contentCreator.createNode(underTestNodeName, null, null);
assertEquals(1, delayedMultipleReferences.size());
Node underTest = parentNode.getNode(underTestNodeName);
underTest.addMixin("mix:referenceable");
contentCreator.finishNode();
assertEquals(0, delayedMultipleReferences.size());
mockery.assertIsSatisfied();
}
use of org.apache.sling.jcr.contentloader.ContentImportListener in project sling by apache.
the class DefaultContentCreatorTest method createUndefinedProperty.
@Test
public void createUndefinedProperty() throws RepositoryException {
final String propName = uniqueId();
final ContentImportListener listener = mockery.mock(ContentImportListener.class);
this.mockery.checking(new Expectations() {
{
oneOf(listener).onCreate(with(any(String.class)));
}
});
contentCreator.init(ImportOptionsFactory.createImportOptions(false, false, false, false, false), new HashMap<String, ContentReader>(), null, listener);
contentCreator.prepareParsing(parentNode, null);
assertFalse(parentNode.hasProperty(propName));
contentCreator.createProperty(propName, PropertyType.UNDEFINED, new String[] {});
assertTrue(parentNode.hasProperty(propName));
mockery.assertIsSatisfied();
}
Aggregations