Search in sources :

Example 11 with ContentReader

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();
}
Also used : Expectations(org.jmock.Expectations) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) Test(org.junit.Test)

Example 12 with ContentReader

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();
}
Also used : Expectations(org.jmock.Expectations) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) ContentImportListener(org.apache.sling.jcr.contentloader.ContentImportListener) Test(org.junit.Test)

Example 13 with ContentReader

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();
}
Also used : Expectations(org.jmock.Expectations) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) ContentImportListener(org.apache.sling.jcr.contentloader.ContentImportListener) Test(org.junit.Test)

Example 14 with ContentReader

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();
}
Also used : Expectations(org.jmock.Expectations) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) ContentImportListener(org.apache.sling.jcr.contentloader.ContentImportListener) Test(org.junit.Test)

Example 15 with ContentReader

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");
}
Also used : Expectations(org.jmock.Expectations) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) Test(org.junit.Test)

Aggregations

ContentReader (org.apache.sling.jcr.contentloader.ContentReader)20 Expectations (org.jmock.Expectations)15 Test (org.junit.Test)15 ContentImportListener (org.apache.sling.jcr.contentloader.ContentImportListener)10 SlingRepository (org.apache.sling.jcr.api.SlingRepository)2 Before (org.junit.Before)2 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 RepositoryException (javax.jcr.RepositoryException)1