use of org.apache.sling.jcr.contentloader.ContentReader in project sling by apache.
the class DefaultContentCreatorTest method testDoesNotCreateProperty.
@Test
public void testDoesNotCreateProperty() throws RepositoryException {
final String propertyName = "foo";
prop = mockery.mock(Property.class);
parentNode = mockery.mock(Node.class);
this.mockery.checking(new Expectations() {
{
oneOf(parentNode).hasProperty(propertyName);
will(returnValue(true));
oneOf(parentNode).getProperty(propertyName);
will(returnValue(prop));
oneOf(prop).isNew();
will(returnValue(false));
}
});
contentCreator.init(ImportOptionsFactory.createImportOptions(false, false, false, false, false), new HashMap<String, ContentReader>(), null, null);
contentCreator.prepareParsing(parentNode, null);
//By calling this method we expect that it will returns on first if-statement
contentCreator.createProperty("foo", PropertyType.REFERENCE, "bar");
//Checking that
mockery.assertIsSatisfied();
}
use of org.apache.sling.jcr.contentloader.ContentReader 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();
}
use of org.apache.sling.jcr.contentloader.ContentReader in project sling by apache.
the class DefaultContentCreatorTest method createNodeWithPrimaryType.
@Test
public void createNodeWithPrimaryType() throws RepositoryException {
final String newNodeName = uniqueId();
final List<String> createdNodes = new ArrayList<String>();
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>(), createdNodes, listener);
contentCreator.prepareParsing(parentNode, DEFAULT_NAME);
int createdNodesSize = createdNodes.size();
contentCreator.createNode(newNodeName, NodeType.NT_UNSTRUCTURED, null);
assertEquals(createdNodesSize + 1, createdNodes.size());
Node createdNode = parentNode.getNode(newNodeName);
assertNotNull(createdNode);
assertTrue(createdNode.getPrimaryNodeType().isNodeType(NodeType.NT_UNSTRUCTURED));
mockery.assertIsSatisfied();
}
use of org.apache.sling.jcr.contentloader.ContentReader in project sling by apache.
the class DefaultContentCreatorTest method createDateProperty.
@Test
public void createDateProperty() throws RepositoryException, ParseException {
final String propName = "dateProp";
final String[] propValues = { "2012-10-01T09:45:00.000+02:00", "2011-02-13T09:45:00.000+02:00" };
final ContentImportListener listener = mockery.mock(ContentImportListener.class);
this.mockery.checking(new Expectations() {
{
oneOf(listener).onCreate(with(any(String.class)));
}
});
parentNode.addMixin("mix:versionable");
contentCreator.init(ImportOptionsFactory.createImportOptions(false, false, true, false, false), new HashMap<String, ContentReader>(), null, listener);
contentCreator.prepareParsing(parentNode, null);
assertFalse(parentNode.hasProperty(propName));
contentCreator.createProperty(propName, PropertyType.DATE, propValues);
assertTrue(parentNode.hasProperty(propName));
Property dateProp = parentNode.getProperty(propName);
assertTrue(dateProp.isNew());
assertEquals(propValues.length, dateProp.getValues().length);
mockery.assertIsSatisfied();
}
use of org.apache.sling.jcr.contentloader.ContentReader in project sling by apache.
the class DefaultContentCreatorTest method willNotRewriteUndefinedPropertyType.
@Test
public void willNotRewriteUndefinedPropertyType() throws RepositoryException {
parentNode = mockery.mock(Node.class);
prop = mockery.mock(Property.class);
contentCreator.init(ImportOptionsFactory.createImportOptions(false, false, true, false, false), new HashMap<String, ContentReader>(), null, null);
contentCreator.prepareParsing(parentNode, null);
this.mockery.checking(new Expectations() {
{
oneOf(parentNode).hasProperty("foo");
will(returnValue(Boolean.TRUE));
oneOf(parentNode).getProperty("foo");
will(returnValue(prop));
oneOf(prop).isNew();
will(returnValue(Boolean.FALSE));
}
});
contentCreator.createProperty("foo", PropertyType.UNDEFINED, "bar");
}
Aggregations