• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java Jcrom类的典型用法和代码示例

java 1次浏览

本文整理汇总了Java中org.jcrom.Jcrom的典型用法代码示例。如果您正苦于以下问题:Java Jcrom类的具体用法?Java Jcrom怎么用?Java Jcrom使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

Jcrom类属于org.jcrom包,在下文中一共展示了Jcrom类的32个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: AbstractJcrDAO

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Constructor.
 * 
 * @param entityClass the class handled by this DAO implementation. If entityClass is <code>null</code>, the entityClass is retrieved from {@link ParameterizedType} in the superclass
 * @param session the current JCR session
 * @param jcrom the Jcrom instance to use for object mapping
 * @param mixinTypes an array of mixin types to apply to new nodes
 */
@SuppressWarnings("unchecked")
public AbstractJcrDAO(Class<T> entityClass, Session session, Jcrom jcrom, String[] mixinTypes) {
    if (entityClass == null) {
        Class<?> clazz = getClass();
        while (!(clazz.getGenericSuperclass() instanceof ParameterizedType)) {
            clazz = clazz.getSuperclass();
        }
        this.entityClass = (Class<T>) ((ParameterizedType) clazz.getGenericSuperclass()).getActualTypeArguments()[0];
    } else {
        this.entityClass = entityClass;
    }
    this.session = session;
    this.jcrom = jcrom;
    this.mixinTypes = new String[mixinTypes.length];
    System.arraycopy(mixinTypes, 0, this.mixinTypes, 0, mixinTypes.length);
    this.isVersionable = checkIfVersionable();
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:26,
代码来源:AbstractJcrDAO.java

示例2: versioningDAOChild3

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to Andrius Kurtinaitis for identifying this problem and
 * contributing this test case.
 * @throws Exception
 */
@Test
public void versioningDAOChild3() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(VersionedEntity.class);

    // create the root
    Node rootNode = session.getRootNode().addNode("content").addNode("versionedEntities");
    VersionedDAO versionedDao = new VersionedDAO(session, jcrom);

    VersionedEntity entity = new VersionedEntity();
    entity.setTitle("MyEntity");
    entity.setBody("First");
    entity.setPath(rootNode.getPath());

    VersionedEntity child = new VersionedEntity();
    child.setName("child1");
    child.setBody("child1Body");

    entity.versionedChild3 = child;
    versionedDao.create(entity);
    assertEquals(child.getBody(), versionedDao.getVersion(entity.getPath(), "1.0").versionedChild3.getBody());
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:28,
代码来源:TestMapping.java

示例3: testAdobeCQ

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void testAdobeCQ() throws RepositoryException {
    Jcrom jcrom = new Jcrom();
    jcrom.map(PageContentNode.class);

    Node rootNode = session.getRootNode().addNode("root");

    String name = "Page Content Node 1";
    String title = "this is page content node 1";
    String description = "Description: page content node 1";
    String resourceType = "resourceType 1";
    String[] tags = new String[] { "new tag 1", "new tag 2" };
    PageContentNode pcn = createPageContentNode(name, title, description, resourceType, tags);

    Node newNode = jcrom.addNode(rootNode, pcn);
    assertNotNull(newNode);

    PageContentNode fromNode = jcrom.fromNode(PageContentNode.class, newNode);
    assertNotNull(fromNode);
    assertEquals(PathUtils.createValidName(name), fromNode.getName());
    assertEquals(title, fromNode.getTitle());
    assertEquals(description, fromNode.getDescription());
    assertEquals(resourceType, fromNode.getResourceType());
    assertNotNull(fromNode.getTags());
    assertEquals(tags.length, fromNode.getTags().length);
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:27,
代码来源:TestAdobeCQ.java

示例4: testNestedInterfaces

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void testNestedInterfaces() throws Exception {
    Jcrom jcrom = new Jcrom(true, true);
    jcrom.map(AImpl.class).map(BImpl.class).map(CImpl.class);

    A a = new AImpl("a");
    B b = new BImpl("b");
    C c = new CImpl("c");

    c.setA(a);
    b.setC(c);
    a.setB(b);

    Node rootNode = session.getRootNode();
    Node nodeA = jcrom.addNode(rootNode, a);

    A fromNodeA = jcrom.fromNode(A.class, nodeA);
    assertNotNull(fromNodeA);
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:20,
代码来源:TestMapping.java

示例5: versioningDAOChild1

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to Andrius Kurtinaitis for identifying this problem and
 * contributing this test case.
 * @throws Exception
 */
@Test
public void versioningDAOChild1() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(VersionedEntity.class);

    // create the root
    Node rootNode = ((Session) session).getRootNode().addNode("content").addNode("versionedEntities");
    VersionedDAO versionedDao = new VersionedDAO(session, jcrom);

    VersionedEntity entity = new VersionedEntity();
    entity.setName("MyEntity");
    entity.setBody("First");
    entity.setPath(rootNode.getPath());

    VersionedEntity child = new VersionedEntity();
    child.setName("child1");
    child.setBody("child1Body");

    entity.versionedChild1 = child;
    versionedDao.create(entity);

    VersionedEntity fromNode = versionedDao.getVersion(entity.getPath(), "1.0");
    assertEquals(child.getBody(), fromNode.versionedChild1.getBody());
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:30,
代码来源:TestMapping.java

示例6: serializedProperties

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void serializedProperties() throws Exception {

    Jcrom jcrom = new Jcrom();
    jcrom.map(EntityWithSerializedProperties.class);

    EntityWithSerializedProperties entity = new EntityWithSerializedProperties();
    entity.setName("withSerializedProperties");

    Parent parent = createParent("John");
    entity.setParent(parent);

    Node rootNode = ((Session) session).getRootNode().addNode("mapChildTest");
    Node newNode = jcrom.addNode(rootNode, entity);
    session.save();

    EntityWithSerializedProperties entityFromJcr = jcrom.fromNode(EntityWithSerializedProperties.class, newNode);

    assertTrue(entityFromJcr.getParent().getName().equals(entity.getParent().getName()));
    assertTrue(entityFromJcr.getParent().getBirthDay().equals(entity.getParent().getBirthDay()));
    assertTrue(entityFromJcr.getParent().getHeight() == entity.getParent().getHeight());
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:23,
代码来源:TestMapping.java

示例7: versioningDAOChild1

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to Andrius Kurtinaitis for identifying this problem and
 * contributing this test case.
 * @throws Exception
 */
@Test
public void versioningDAOChild1() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(VersionedEntity.class);

    // create the root
    Node rootNode = session.getRootNode().addNode("content").addNode("versionedEntities");
    VersionedDAO versionedDao = new VersionedDAO(session, jcrom);

    VersionedEntity entity = new VersionedEntity();
    entity.setName("MyEntity");
    entity.setBody("First");
    entity.setPath(rootNode.getPath());

    VersionedEntity child = new VersionedEntity();
    child.setName("child1");
    child.setBody("child1Body");

    entity.versionedChild1 = child;
    versionedDao.create(entity);

    VersionedEntity fromNode = versionedDao.getVersion(entity.getPath(), "1.0");
    assertEquals(child.getBody(), fromNode.versionedChild1.getBody());
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:30,
代码来源:TestMapping.java

示例8: test_dynamic_maps_stored_as_child_nodes_can_be_retrieved_by_key

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void test_dynamic_maps_stored_as_child_nodes_can_be_retrieved_by_key() throws Exception {
    Jcrom jcrom = new Jcrom(true, true);
    jcrom.map(DynamicObject.class).map(Child.class);

    Node rootNode = ((Session) session).getRootNode().addNode("test");

    DynamicObject dyna = new DynamicObject();
    dyna.setName("Dynamic");

    dyna.putSingleValueChild("childOne", createChildWithName("childName1"));
    dyna.putSingleValueChild("childTwo", createChildWithName("childName2"));
    dyna.putSingleValueChild("childThree", createChildWithName("childName3"));

    assertEquals(3, dyna.getSingleValueChildren().size());

    DynamicObject loaded = jcrom.fromNode(DynamicObject.class, jcrom.addNode(rootNode, dyna));

    assertEquals(3, loaded.getSingleValueChildren().size());
    assertNotNull(loaded.getSingleValueChildren().get("childOne"));
    assertNotNull(loaded.getSingleValueChildren().get("childTwo"));
    assertNotNull(loaded.getSingleValueChildren().get("childThree"));

}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:25,
代码来源:TestInstantiation.java

示例9: mapPackage

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void mapPackage() throws Exception {
    final Jcrom jcrom = new Jcrom(true, true);
    jcrom.mapPackage("org.jcrom.entities");

    final Node parentNode = this.session.getRootNode().addNode("mynode");

    First first = new First();
    first.setName("first");
    first.setFirstString("nr1");

    Second second = new Second();
    second.setName("second");
    second.setSecondString("nr2");

    jcrom.addNode(parentNode, first);
    jcrom.addNode(parentNode, second);

    assertTrue(parentNode.getNode("first").hasProperty("firstString"));
    assertTrue(parentNode.getNode("second").hasProperty("secondString"));
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:22,
代码来源:TestMapping.java

示例10: versioningDAOChild5

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void versioningDAOChild5() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(VersionedEntity.class);

    // create the root
    Node rootNode = session.getRootNode().addNode("content").addNode("versionedEntities");
    VersionedDAO versionedDao = new VersionedDAO(session, jcrom);

    VersionedEntity entity = new VersionedEntity();
    entity.setTitle("MyEntity");
    entity.setBody("First");
    entity.setPath(rootNode.getPath());

    VersionedEntity child = new VersionedEntity();
    child.setName("child1");
    child.setBody("child1Body");

    entity.versionedChild4 = child;
    versionedDao.create(entity);
    assertEquals(child.getBody(), versionedDao.getVersion(entity.getPath(), "1.0").versionedChild4.getBody());

    child.setTitle("child1 with new title");
    child = versionedDao.update(child);
    assertEquals(child.getTitle(), versionedDao.get(child.getPath()).getTitle());
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:27,
代码来源:TestMapping.java

示例11: versioningDAOChild6

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void versioningDAOChild6() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(VersionedEntity.class);

    // create the root
    Node rootNode = session.getRootNode().addNode("content").addNode("versionedEntities");
    VersionedDAO versionedDao = new VersionedDAO(session, jcrom);

    VersionedEntity entity = new VersionedEntity();
    entity.setTitle("MyEntity");
    entity.setBody("First");
    entity.setPath(rootNode.getPath());

    versionedDao.create(entity);

    VersionedEntity child = new VersionedEntity();
    child.setName("child1");
    child.setBody("child1Body");
    child.setPath(entity.getPath());

    versionedDao.create(child);
    assertEquals(child.getBody(), versionedDao.getVersion(entity.getPath() + "/" + child.getName(), "1.0").getBody());
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:25,
代码来源:TestMapping.java

示例12: versioningDAOChild6

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void versioningDAOChild6() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(VersionedEntity.class);

    // create the root
    Node rootNode = ((Session) session).getRootNode().addNode("content").addNode("versionedEntities");
    VersionedDAO versionedDao = new VersionedDAO(session, jcrom);

    VersionedEntity entity = new VersionedEntity();
    entity.setTitle("MyEntity");
    entity.setBody("First");
    entity.setPath(rootNode.getPath());

    versionedDao.create(entity);

    VersionedEntity child = new VersionedEntity();
    child.setName("child1");
    child.setBody("child1Body");
    child.setPath(entity.getPath());

    versionedDao.create(child);
    assertEquals(child.getBody(), versionedDao.getVersion(entity.getPath() + "/" + child.getName(), "1.0").getBody());
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:25,
代码来源:TestMapping.java

示例13: testEmptyList

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to Decebal Suiu for contributing this test case.
 * @throws Exception 
 */
@Test
public void testEmptyList() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(Person.class);

    // create person
    Person person = new Person();
    person.setName("peter");
    person.setAge(20);
    person.setPhones(Arrays.asList(new String[] { "053453553" }));

    // add person in jcr
    Node node = jcrom.addNode(session.getRootNode(), person);
    Person personFromJcr = jcrom.fromNode(Person.class, node);
    assertEquals(1, personFromJcr.getPhones().size());

    // update person in jcr
    person.setPhones(new ArrayList<String>()); // reset the phones
    jcrom.updateNode(node, person);

    // retrieve updated person from jcr
    personFromJcr = jcrom.fromNode(Person.class, node);
    assertFalse(personFromJcr.getPhones().size() == 1); // <<< FAILED
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:29,
代码来源:TestMapping.java

示例14: testJcrFileMapping

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void testJcrFileMapping() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(JcrFile.class);

    Node root = session.getRootNode().addNode("files");

    JcrFile file = createFile("myfile", true);
    Calendar lastModified = file.getLastModified();

    Node node = jcrom.addNode(root, file);

    assertTrue(node.hasNode("jcr:content"));
    assertEquals("image/jpeg", node.getNode("jcr:content").getProperty("jcr:mimeType").getString());
    assertEquals("UTF-8", node.getNode("jcr:content").getProperty("jcr:encoding").getString());

    JcrFile fromNode = jcrom.fromNode(JcrFile.class, node);

    assertEquals("image/jpeg", fromNode.getMimeType());
    assertEquals("UTF-8", fromNode.getEncoding());
    assertEquals(lastModified.getTimeInMillis(), fromNode.getLastModified().getTimeInMillis());
    assertTrue(fromNode.getDataProvider().getContentLength() > 0);
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:24,
代码来源:TestMapping.java

示例15: testJcrFileNodeFromInputStream

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to eltabo for contributing this test case (Issue 95).
 * @throws Exception 
 */
@Test
public void testJcrFileNodeFromInputStream() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(Document.class);
    jcrom.map(Parent.class);
    jcrom.map(JcrFile.class);

    Node rootNode = session.getRootNode().addNode("root");

    Parent parent = createParent("Bob");
    parent.setJcrFile(createFile("jcr_image.jpg", true));
    Node newNode = jcrom.addNode(rootNode, parent);
    assertNotNull(newNode);
    assertTrue(newNode.hasNode("jcrFile/jcr_image.jpg/jcr:content"));

    Node fileNode = newNode.getNode("jcrFile/jcr_image.jpg");
    assertEquals("image/jpeg", fileNode.getNode("jcr:content").getProperty("jcr:mimeType").getString());
    assertEquals("UTF-8", fileNode.getNode("jcr:content").getProperty("jcr:encoding").getString());

    JcrFile fromNode = jcrom.fromNode(JcrFile.class, fileNode);

    assertEquals("image/jpeg", fromNode.getMimeType());
    assertEquals("UTF-8", fromNode.getEncoding());
    assertTrue(fromNode.getDataProvider().getContentLength() > 0);
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:30,
代码来源:TestMapping.java

示例16: testEmptyList

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to Decebal Suiu for contributing this test case.
 * @throws Exception 
 */
@Test
public void testEmptyList() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(Person.class);

    // create person
    Person person = new Person();
    person.setName("peter");
    person.setAge(20);
    person.setPhones(Arrays.asList(new String[] { "053453553" }));

    // add person in jcr
    Node node = jcrom.addNode(((Session) session).getRootNode(), person);
    Person personFromJcr = jcrom.fromNode(Person.class, node);
    assertEquals(1, personFromJcr.getPhones().size());

    // update person in jcr
    person.setPhones(new ArrayList<String>()); // reset the phones
    jcrom.updateNode(node, person);

    // retrieve updated person from jcr
    personFromJcr = jcrom.fromNode(Person.class, node);
    assertFalse(personFromJcr.getPhones().size() == 1); // <<< FAILED
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:29,
代码来源:TestMapping.java

示例17: testAddMapToModel

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to [email protected] for contributing this test case.
 * Tests adding a Map field to a mapped class at a later date, 
 * fails with PathNotFoundException in JCROM 2.0
 */
@Test
public void testAddMapToModel() throws Exception {
    final Jcrom jcrom = new Jcrom();
    jcrom.map(EntityToBeModified.class);
    jcrom.map(EntityModifiedMapFieldAdded.class);

    EntityToBeModified entity = new EntityToBeModified();
    entity.setName("original");
    entity.setPath("original");

    Node originalNode = jcrom.addNode(this.session.getRootNode(), entity);

    try {
        jcrom.fromNode(EntityModifiedMapFieldAdded.class, originalNode);
    } catch (JcrMappingException e) {
        if (e.getCause() instanceof PathNotFoundException) {
            fail("PathNotFoundException thrown.");
        } else {
            throw e;
        }
    }
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:28,
代码来源:TestMapping.java

示例18: testNoReferentialIntegrity

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test(expected = ReferentialIntegrityException.class)
public void testNoReferentialIntegrity() throws JcrMappingException, RepositoryException {
    System.out.println("no referential integrity using default reference");

    // initialise jcrom
    Jcrom jcrom = new Jcrom();
    jcrom.map(A3.class);
    jcrom.map(B.class);

    // initialise mappable objects
    B instanceB = new B();
    instanceB.setId("12345");
    instanceB.setName("instanceB");

    A3 instanceA3 = new A3();
    instanceA3.setName("instanceA3");
    instanceA3.setbRef(instanceB);

    jcrom.addNode(session.getRootNode(), instanceB, new String[] { "mix:referenceable" });
    jcrom.addNode(session.getRootNode(), instanceA3);
    session.getRootNode().getNode("instanceB").remove();
    session.save();
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:24,
代码来源:TestJcrReference.java

示例19: serializedProperties

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void serializedProperties() throws Exception {

    Jcrom jcrom = new Jcrom();
    jcrom.map(EntityWithSerializedProperties.class);

    EntityWithSerializedProperties entity = new EntityWithSerializedProperties();
    entity.setName("withSerializedProperties");

    Parent parent = createParent("John");
    entity.setParent(parent);

    Node rootNode = session.getRootNode().addNode("mapChildTest");
    Node newNode = jcrom.addNode(rootNode, entity);
    session.save();

    EntityWithSerializedProperties entityFromJcr = jcrom.fromNode(EntityWithSerializedProperties.class, newNode);

    assertTrue(entityFromJcr.getParent().getName().equals(entity.getParent().getName()));
    assertTrue(entityFromJcr.getParent().getBirthDay().equals(entity.getParent().getBirthDay()));
    assertTrue(entityFromJcr.getParent().getHeight() == entity.getParent().getHeight());
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:23,
代码来源:TestMapping.java

示例20: testAdobeCQ

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void testAdobeCQ() throws RepositoryException {
    Jcrom jcrom = new Jcrom();
    jcrom.map(PageContentNode.class);

    Node rootNode = ((Session) session).getRootNode().addNode("root");

    String name = "Page Content Node 1";
    String title = "this is page content node 1";
    String description = "Description: page content node 1";
    String resourceType = "resourceType 1";
    String[] tags = new String[] { "new tag 1", "new tag 2" };
    PageContentNode pcn = createPageContentNode(name, title, description, resourceType, tags);

    Node newNode = jcrom.addNode(rootNode, pcn);
    assertNotNull(newNode);

    PageContentNode fromNode = jcrom.fromNode(PageContentNode.class, newNode);
    assertNotNull(fromNode);
    assertEquals(PathUtils.createValidName(name), fromNode.getName());
    assertEquals(title, fromNode.getTitle());
    assertEquals(description, fromNode.getDescription());
    assertEquals(resourceType, fromNode.getResourceType());
    assertNotNull(fromNode.getTags());
    assertEquals(tags.length, fromNode.getTags().length);
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:27,
代码来源:TestAdobeCQ.java

示例21: testNestedInterfaces

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void testNestedInterfaces() throws Exception {
    Jcrom jcrom = new Jcrom(true, true);
    jcrom.map(AImpl.class).map(BImpl.class).map(CImpl.class);

    A a = new AImpl("a");
    B b = new BImpl("b");
    C c = new CImpl("c");

    c.setA(a);
    b.setC(c);
    a.setB(b);

    Node rootNode = ((Session) session).getRootNode();
    Node nodeA = jcrom.addNode(rootNode, a);

    A fromNodeA = jcrom.fromNode(A.class, nodeA);
    assertNotNull(fromNodeA);
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:20,
代码来源:TestMapping.java

示例22: versioningDAOChild3

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to Andrius Kurtinaitis for identifying this problem and
 * contributing this test case.
 * @throws Exception
 */
@Test
public void versioningDAOChild3() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(VersionedEntity.class);

    // create the root
    Node rootNode = ((Session) session).getRootNode().addNode("content").addNode("versionedEntities");
    VersionedDAO versionedDao = new VersionedDAO(session, jcrom);

    VersionedEntity entity = new VersionedEntity();
    entity.setTitle("MyEntity");
    entity.setBody("First");
    entity.setPath(rootNode.getPath());

    VersionedEntity child = new VersionedEntity();
    child.setName("child1");
    child.setBody("child1Body");

    entity.versionedChild3 = child;
    versionedDao.create(entity);
    assertEquals(child.getBody(), versionedDao.getVersion(entity.getPath(), "1.0").versionedChild3.getBody());
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:28,
代码来源:TestMapping.java

示例23: versioningDAOChild4

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to Andrius Kurtinaitis for identifying this problem and
 * contributing this test case.
 * @throws Exception
 */
@Test
public void versioningDAOChild4() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(VersionedEntity.class);

    // create the root
    Node rootNode = ((Session) session).getRootNode().addNode("content").addNode("versionedEntities");
    VersionedDAO versionedDao = new VersionedDAO(session, jcrom);

    VersionedEntity entity = new VersionedEntity();
    entity.setTitle("MyEntity");
    entity.setBody("First");
    entity.setPath(rootNode.getPath());

    VersionedEntity child = new VersionedEntity();
    child.setName("child1");
    child.setBody("child1Body");

    entity.versionedChild4 = child;
    versionedDao.create(entity);
    assertEquals(child.getBody(), versionedDao.getVersion(entity.getPath(), "1.0").versionedChild4.getBody());
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:28,
代码来源:TestMapping.java

示例24: testJcrFileMapping

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void testJcrFileMapping() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(JcrFile.class);

    Node root = ((Session) session).getRootNode().addNode("files");

    JcrFile file = createFile("myfile", true);
    Calendar lastModified = file.getLastModified();

    Node node = jcrom.addNode(root, file);

    assertTrue(node.hasNode("jcr:content"));
    assertEquals("image/jpeg", node.getNode("jcr:content").getProperty("jcr:mimeType").getString());
    assertEquals("UTF-8", node.getNode("jcr:content").getProperty("jcr:encoding").getString());

    JcrFile fromNode = jcrom.fromNode(JcrFile.class, node);

    assertEquals("image/jpeg", fromNode.getMimeType());
    assertEquals("UTF-8", fromNode.getEncoding());
    assertEquals(lastModified.getTimeInMillis(), fromNode.getLastModified().getTimeInMillis());
    assertTrue(fromNode.getDataProvider().getContentLength() > 0);
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:24,
代码来源:TestMapping.java

示例25: testAddMapToModel

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to [email protected] for contributing this test case.
 * Tests adding a Map field to a mapped class at a later date, 
 * fails with PathNotFoundException in JCROM 2.0
 */
@Test
public void testAddMapToModel() throws Exception {
    final Jcrom jcrom = new Jcrom();
    jcrom.map(EntityToBeModified.class);
    jcrom.map(EntityModifiedMapFieldAdded.class);

    EntityToBeModified entity = new EntityToBeModified();
    entity.setName("original");
    entity.setPath("original");

    Node originalNode = jcrom.addNode(((Session) session).getRootNode(), entity);

    try {
        jcrom.fromNode(EntityModifiedMapFieldAdded.class, originalNode);
    } catch (JcrMappingException e) {
        if (e.getCause() instanceof PathNotFoundException) {
            fail("PathNotFoundException thrown.");
        } else {
            throw e;
        }
    }
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:28,
代码来源:TestMapping.java

示例26: mapPackage

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void mapPackage() throws Exception {
    final Jcrom jcrom = new Jcrom(true, true);
    jcrom.mapPackage("org.jcrom.entities");

    final Node parentNode = ((Session) session).getRootNode().addNode("mynode");

    First first = new First();
    first.setName("first");
    first.setFirstString("nr1");

    Second second = new Second();
    second.setName("second");
    second.setSecondString("nr2");

    jcrom.addNode(parentNode, first);
    jcrom.addNode(parentNode, second);

    assertTrue(parentNode.getNode("first").hasProperty("firstString"));
    assertTrue(parentNode.getNode("second").hasProperty("secondString"));
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:22,
代码来源:TestMapping.java

示例27: testNodeClassChange

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test(expected = PathNotFoundException.class)
public void testNodeClassChange() throws Exception {
    Jcrom jcrom = new Jcrom(true, true);
    jcrom.map(Rectangle.class).map(Triangle.class);

    Node rootNode = session.getRootNode().addNode("root");

    // create the node
    Triangle triangle = new Triangle(1, 1);
    triangle.setName("test");
    Node newNode = jcrom.addNode(rootNode, triangle);

    // now switch to another class for the node
    Rectangle rectangle = new Rectangle(2.5, 3.3);
    rectangle.setName("test");
    jcrom.updateNode(newNode, rectangle);

    // finally make sure that the old properties have been removed,
    // this should throw an exception:
    newNode.getProperty("base");
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:22,
代码来源:TestMapping.java

示例28: test_dynamic_maps_stored_as_child_nodes_can_be_retrieved_by_key

点赞 3

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void test_dynamic_maps_stored_as_child_nodes_can_be_retrieved_by_key() throws Exception {
    Jcrom jcrom = new Jcrom(true, true);
    jcrom.map(DynamicObject.class).map(Child.class);

    Node rootNode = session.getRootNode().addNode("test");

    DynamicObject dyna = new DynamicObject();
    dyna.setName("Dynamic");

    dyna.putSingleValueChild("childOne", createChildWithName("childName1"));
    dyna.putSingleValueChild("childTwo", createChildWithName("childName2"));
    dyna.putSingleValueChild("childThree", createChildWithName("childName3"));

    assertEquals(3, dyna.getSingleValueChildren().size());

    DynamicObject loaded = jcrom.fromNode(DynamicObject.class, jcrom.addNode(rootNode, dyna));

    assertEquals(3, loaded.getSingleValueChildren().size());
    assertNotNull(loaded.getSingleValueChildren().get("childOne"));
    assertNotNull(loaded.getSingleValueChildren().get("childTwo"));
    assertNotNull(loaded.getSingleValueChildren().get("childThree"));

}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:25,
代码来源:TestInstantiation.java

示例29: finalFields

点赞 2

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void finalFields() throws Exception {
    final Jcrom jcrom = new Jcrom();
    jcrom.map(FinalEntity.class);

    FinalEntity entity = new FinalEntity("This cannot be changed");
    entity.setName("myentity");

    final Node parentNode = ((Session) session).getRootNode().addNode("mynode");

    jcrom.addNode(parentNode, entity);

    assertTrue(parentNode.getNode("myentity").hasProperty("immutableString"));
    assertEquals(entity.getImmutableString(), parentNode.getNode("myentity").getProperty("immutableString").getString());
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:16,
代码来源:TestMapping.java

示例30: testFileReferenceByPath

点赞 2

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void testFileReferenceByPath() throws JcrMappingException, RepositoryException {
    System.out.println("JcrFileNode referenced by path");

    // initialise jcrom
    Jcrom jcrom = new Jcrom();
    jcrom.map(JcrFileReferenceByPathParentNode.class);
    jcrom.map(ReferenceableJCRFile.class);

    // initialise mappable objects
    ReferenceableJCRFile fileRef = new ReferenceableJCRFile();
    fileRef.setId("12345");
    fileRef.setName("fileRef");
    fileRef.setMimeType("image/jpeg");
    fileRef.setEncoding("UTF-8");

    File imageFile = new File("src/test/resources/ogg.jpg");

    Calendar lastModified = Calendar.getInstance();
    lastModified.setTimeInMillis(imageFile.lastModified());
    fileRef.setLastModified(lastModified);

    fileRef.setDataProvider(new JcrDataProviderImpl(imageFile));

    JcrFileReferenceByPathParentNode parent = new JcrFileReferenceByPathParentNode();
    parent.setName("parent");
    parent.setbRef(fileRef);

    jcrom.addNode(((Session) session).getRootNode(), fileRef, new String[] { "mix:referenceable" });
    String instancePath = ((Session) session).getRootNode().getNode("fileRef").getPath();
    jcrom.addNode(((Session) session).getRootNode(), parent);

    assertEquals(((Session) session).getRootNode().getNode("parent").getProperty("bRef").getType(), PropertyType.STRING);
    assertEquals(((Session) session).getRootNode().getNode("parent").getProperty("bRef").getString(), instancePath);

    JcrFileReferenceByPathParentNode entityFromJcr = jcrom.fromNode(JcrFileReferenceByPathParentNode.class, ((Session) session).getRootNode().getNode("parent"));
    assertEquals("image/jpeg", entityFromJcr.getbRef().getMimeType());
    assertEquals(imageFile.length(), entityFromJcr.getbRef().getDataProvider().getContentLength());
    ///session.save();
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:41,
代码来源:TestJcrFileReference.java

示例31: testReferenceCycles

点赞 2

import org.jcrom.Jcrom; //导入依赖的package包/类
/**
 * Thanks to Bouiaw and Andrius Kurtinaitis for identifying this problem and
 * contributing this test case.
 * @throws Exception
 */
@Test
public void testReferenceCycles() throws Exception {
    Jcrom jcrom = new Jcrom(true, true);
    jcrom.map(BadNode.class);

    BadNode node1 = new BadNode();
    node1.body = "body1";

    BadNode node2 = new BadNode();
    node2.body = "body2";

    Node rootNode = session.getRootNode();
    Node n1 = jcrom.addNode(rootNode, node1);
    Node n2 = jcrom.addNode(rootNode, node2);

    node1.reference = node2;
    node2.reference = node1;

    jcrom.updateNode(n1, node1);
    jcrom.updateNode(n2, node2);

    BadNode fromNode1 = jcrom.fromNode(BadNode.class, n1);
    BadNode fromNode2 = jcrom.fromNode(BadNode.class, n2);

    assertEquals(node1.body, fromNode2.reference.body);
    assertEquals(node2.body, fromNode1.reference.body);
}
 

开发者ID:sbrinkmann,
项目名称:jcrom-extended,
代码行数:33,
代码来源:TestMapping.java

示例32: testNoChildContainerNode

点赞 2

import org.jcrom.Jcrom; //导入依赖的package包/类
@Test
public void testNoChildContainerNode() throws Exception {
    Jcrom jcrom = new Jcrom();
    jcrom.map(UserProfile.class);

    Node rootNode = session.getRootNode().addNode("noChildTest");

    UserProfile userProfile = new UserProfile();
    userProfile.setName("john");

    Address address = new Address();
    address.setStreet("Some street");
    address.setPostCode("101");
    userProfile.setAddress(address);

    Node userProfileNode = jcrom.addNode(rootNode, userProfile);

    UserProfile fromJcr = jcrom.fromNode(UserProfile.class, userProfileNode);

    assertEquals(address.getName(), "address");
    assertEquals(address.getStreet(), fromJcr.getAddress().getStreet());
    assertEquals(address.getPostCode(), fromJcr.getAddress().getPostCode());

    fromJcr.getAddress().setStreet("Another street");

    jcrom.updateNode(userProfileNode, fromJcr);

    UserProfile updatedFromJcr = jcrom.fromNode(UserProfile.class, userProfileNode);

    assertEquals(fromJcr.getAddress().getStreet(), updatedFromJcr.getAddress().getStreet());
    assertEquals(fromJcr.getAddress().getPostCode(), updatedFromJcr.getAddress().getPostCode());
}
 

开发者ID:dooApp,
项目名称:jcromfx,
代码行数:33,
代码来源:TestMapping.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)