Search in sources :

Example 16 with ContentReader

use of org.apache.sling.jcr.contentloader.ContentReader in project sling by apache.

the class DefaultContentCreatorTest method setup.

@Before
public void setup() throws Exception {
    final SlingRepository repo = RepositoryProvider.instance().getRepository();
    session = repo.loginAdministrative(null);
    contentCreator = new DefaultContentCreator(null);
    contentCreator.init(ImportOptionsFactory.createImportOptions(true, true, true, false, false), new HashMap<String, ContentReader>(), null, null);
    parentNode = session.getRootNode().addNode(getClass().getSimpleName()).addNode(uniqueId());
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) Before(org.junit.Before)

Example 17 with ContentReader

use of org.apache.sling.jcr.contentloader.ContentReader in project sling by apache.

the class CreateNodeTest method setup.

@Before
public void setup() throws Exception {
    final SlingRepository repo = RepositoryProvider.instance().getRepository();
    session = repo.loginAdministrative(null);
    contentCreator = new DefaultContentCreator(null);
    contentCreator.init(ImportOptionsFactory.createImportOptions(true, true, true, false, false), new HashMap<String, ContentReader>(), null, null);
    testRoot = session.getRootNode().addNode(getClass().getSimpleName()).addNode(uniqueId());
}
Also used : SlingRepository(org.apache.sling.jcr.api.SlingRepository) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) Before(org.junit.Before)

Example 18 with ContentReader

use of org.apache.sling.jcr.contentloader.ContentReader in project sling by apache.

the class DefaultContentCreatorTest method finishNodeWithSingleProperty.

@Test
public void finishNodeWithSingleProperty() throws RepositoryException, NoSuchFieldException {
    final String propName = uniqueId();
    final String underTestNodeName = uniqueId();
    final ContentImportListener listener = mockery.mock(ContentImportListener.class);
    this.mockery.checking(new Expectations() {

        {
            exactly(2).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, underTestNodeName);
    contentCreator.createNode(underTestNodeName, null, null);
    Node underTest = parentNode.getNode(underTestNodeName);
    underTest.addMixin("mix:referenceable");
    contentCreator.finishNode();
    assertEquals(underTest.getUUID(), parentNode.getProperty(propName).getString());
    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 19 with ContentReader

use of org.apache.sling.jcr.contentloader.ContentReader in project sling by apache.

the class DefaultContentCreatorTest method testCreatePropertyWithNewPropertyType.

@Test
public void testCreatePropertyWithNewPropertyType() throws RepositoryException, ParseException {
    final String propertyName = "foo";
    final String propertyValue = "bar";
    final Integer propertyType = -1;
    final ContentImportListener listener = mockery.mock(ContentImportListener.class);
    parentNode = mockery.mock(Node.class);
    prop = mockery.mock(Property.class);
    this.mockery.checking(new Expectations() {

        {
            oneOf(parentNode).hasProperty(with(any(String.class)));
            oneOf(parentNode).getProperty(propertyName);
            will(returnValue(prop));
            oneOf(parentNode).setProperty(propertyName, propertyValue, propertyType);
            oneOf(prop).getPath();
            will(returnValue(""));
            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, propertyValue);
    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 20 with ContentReader

use of org.apache.sling.jcr.contentloader.ContentReader in project sling by apache.

the class DefaultContentCreatorTest method testCreateDateProperty.

@Test
public void testCreateDateProperty() throws RepositoryException, ParseException {
    final String propertyName = "dateProp";
    final String propertyValue = "2012-10-01T09:45:00.000+02:00";
    final ContentImportListener listener = mockery.mock(ContentImportListener.class);
    parentNode = mockery.mock(Node.class);
    prop = mockery.mock(Property.class);
    this.mockery.checking(new Expectations() {

        {
            oneOf(parentNode).hasProperty(with(any(String.class)));
            oneOf(parentNode).setProperty(with(any(String.class)), with(any(Calendar.class)));
            oneOf(parentNode).getProperty(with(any(String.class)));
            will(returnValue(prop));
            oneOf(prop).getPath();
            will(returnValue(""));
            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.DATE, propertyValue);
    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)

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