Search in sources :

Example 6 with ContentReader

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

the class DefaultContentCreatorTest method testCreateFalseCheckedOutPreperty.

@Test
public void testCreateFalseCheckedOutPreperty() throws RepositoryException {
    parentNode = mockery.mock(Node.class);
    this.mockery.checking(new Expectations() {

        {
            oneOf(parentNode).hasProperty(with(any(String.class)));
        }
    });
    contentCreator.init(ImportOptionsFactory.createImportOptions(false, false, false, false, false), new HashMap<String, ContentReader>(), null, null);
    contentCreator.prepareParsing(parentNode, null);
    int numberOfVersionablesNodes = contentCreator.getVersionables().size();
    contentCreator.createProperty("jcr:isCheckedOut", PropertyType.UNDEFINED, "false");
    //Checking that list of versionables was changed
    assertEquals(numberOfVersionablesNodes + 1, contentCreator.getVersionables().size());
    mockery.assertIsSatisfied();
}
Also used : Expectations(org.jmock.Expectations) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) Test(org.junit.Test)

Example 7 with ContentReader

use of org.apache.sling.jcr.contentloader.ContentReader 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();
}
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 8 with ContentReader

use of org.apache.sling.jcr.contentloader.ContentReader 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();
}
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 9 with ContentReader

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

the class DefaultContentCreatorTest method willRewriteUndefinedPropertyType.

@Test
public void willRewriteUndefinedPropertyType() throws RepositoryException {
    parentNode = mockery.mock(Node.class);
    prop = mockery.mock(Property.class);
    contentCreator.init(ImportOptionsFactory.createImportOptions(true, true, true, false, false), new HashMap<String, ContentReader>(), null, null);
    contentCreator.prepareParsing(parentNode, null);
    this.mockery.checking(new Expectations() {

        {
            allowing(parentNode).isNodeType("mix:versionable");
            will(returnValue(Boolean.FALSE));
            allowing(parentNode).getParent();
            will(returnValue(null));
            oneOf(parentNode).hasProperty("foo");
            will(returnValue(Boolean.TRUE));
            oneOf(parentNode).setProperty(with(equal("foo")), with(equal("bar")));
        }
    });
    contentCreator.createProperty("foo", PropertyType.UNDEFINED, "bar");
}
Also used : Expectations(org.jmock.Expectations) ContentReader(org.apache.sling.jcr.contentloader.ContentReader) Test(org.junit.Test)

Example 10 with ContentReader

use of org.apache.sling.jcr.contentloader.ContentReader 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();
}
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