Package org.apache.jackrabbit.ocm.manager

Examples of org.apache.jackrabbit.ocm.manager.ObjectContentManager


  private void importData(Date date)
  {
    try
    {

      ObjectContentManager ocm = getObjectContentManager();
     
      for (int i = 1; i <= 100; i++)
      {
        Atomic a = new Atomic();
        a.setPath("/test" + i);
        a.setBooleanObject(new Boolean(i%2==0));
        a.setBooleanPrimitive(true);
        a.setIntegerObject(new Integer(100 * i));
        a.setIntPrimitive(200 + i);       
        a.setDate(date);
        Calendar calendar = Calendar.getInstance();
        calendar.set(1976, 4, 20, 15, 40);
        a.setCalendar(calendar);
        a.setDoubleObject(new Double(2.12 + i));
        a.setDoublePrimitive(1.23 + i);
        long now = System.currentTimeMillis();
        a.setTimestamp(new Timestamp(now));
        if ((i % 2) == 0)
        {
          a.setString("Test String JCR " + i);
             a.setByteArray("This is small object stored in a JCR repository".getBytes());
             a.setInputStream(new ByteArrayInputStream("Test inputstream".getBytes()));
        }
        else
        {
           a.setByteArray("This is small object stored in the ocm repository".getBytes());
           a.setInputStream(new ByteArrayInputStream("Another Stream".getBytes()));
           a.setString("Test String " + i);
        }
        ocm.insert(a);
       
       
      }
      ocm.save();

    }
    catch (Exception e)
    {
      e.printStackTrace();
View Full Code Here


     */
    public void testBeanReference()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();

            // --------------------------------------------------------------------------------
            // Create and store an object A in the repository
            // --------------------------------------------------------------------------------
            A a = new A();
            a.setPath("/test");
            a.setStringData("testdata");
            ocm.insert(a);
            ocm.save();          

            // --------------------------------------------------------------------------------
            // Get the object a
            // --------------------------------------------------------------------------------          
            a = (A) ocm.getObject( "/test");
            assertNotNull("a is null", a);
            String uuidA = a.getUuid();
            assertNotNull("uuid is null", uuidA);
            System.out.println("UUID : " + uuidA);
           
            // --------------------------------------------------------------------------------
            // Create and store an object B in the repository which has a reference to A
            // --------------------------------------------------------------------------------
            B2 b = new B2();
            b.setA(a);
            b.setPath("/testB2");
            ocm.insert(b);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Retrieve object B
            // --------------------------------------------------------------------------------
            b = (B2) ocm.getObject("/testB2");
            a = b.getA();
            assertNotNull("a is null", a);
            assertTrue("Invalid object a", a.getStringData().equals("testdata"));
            assertTrue("Invalid uuid property", a.getUuid().equals(uuidA));

            // --------------------------------------------------------------------------------
            // Update object B with an null value
            // --------------------------------------------------------------------------------
            b.setA(null);
            ocm.update(b);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Retrieve object B
            // --------------------------------------------------------------------------------
            b = (B2) ocm.getObject("/testB2");
            a = b.getA();
            assertNull("a is not null", a);
           
           
        }
View Full Code Here

     */
    public void testLockWithNodeType()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();


            // --------------------------------------------------------------------------------
            // Create an object which is associated to the
            // --------------------------------------------------------------------------------
            Lockable lockable = new Lockable();
            lockable.setPath("/test");
            lockable.setA1("a1");
            lockable.setA2("a2");
            ocm.insert(lockable);
            ocm.save();
           

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            lockable = (Lockable) ocm.getObject("/test");
            assertNotNull("a is null", lockable);
           
            // --------------------------------------------------------------------------------
            // Check if the object is locked
            // --------------------------------------------------------------------------------
            assertFalse("the object is locked", ocm.isLocked("/test"));
            assertNull("Attribute lockowner is not null", lockable.getLockOwner());
            // --------------------------------------------------------------------------------
            // Lock the object
            // --------------------------------------------------------------------------------                      
            Lock lock = ocm.lock("/test", true, false);
           
            // --------------------------------------------------------------------------------
            // Check if the object is locked
            // --------------------------------------------------------------------------------
            assertTrue("the object is not locked", ocm.isLocked("/test"));
           
            // --------------------------------------------------------------------------------
            // Unlock the object
            // --------------------------------------------------------------------------------          
            ocm.unlock("/test", lock.getLockToken());

            // --------------------------------------------------------------------------------
            // Check if the object is locked
            // --------------------------------------------------------------------------------
            assertFalse("the object is locked", ocm.isLocked("/test"));


            // --------------------------------------------------------------------------------
            // Lock & update
            // --------------------------------------------------------------------------------
            lock = ocm.lock("/test", true, false);
            assertTrue("the object is not locked", ocm.isLocked("/test"));
            lockable = (Lockable) ocm.getObject("/test");
            assertNotNull("Attribute lockowner is null", lockable.getLockOwner());
            lockable.setA1("new a1 Value");
            ocm.update(lockable);
            ocm.save();
            ocm.unlock("/test", lock.getLockToken());
           
           
            // --------------------------------------------------------------------------------
            // Remove the object
            // --------------------------------------------------------------------------------          
            ocm.remove(lockable);
            ocm.save();
           
        }
        catch (Exception e)
        {
            e.printStackTrace();
View Full Code Here

    public void testResidualProperties()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();

            // --------------------------------------------------------------------------------
            // Create and store an object graph in the repository with a null hashmap
            // --------------------------------------------------------------------------------

            Residual residual = new Residual.ResidualProperties();
            residual.setPath("/test");
                       
            ocm.insert(residual);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            residual = (Residual) ocm.getObject( "/test");
            assertNotNull("Object is null", residual);
            assertNull("Hashmap is not null", residual.getElements());
           
            // --------------------------------------------------------------------------------
            // Update an object graph in the repository
            // --------------------------------------------------------------------------------

            residual = new Residual.ResidualProperties();
            residual.setPath("/test");
           
            ManagedHashMap map = new ManagedHashMap();
            map.put("value1", "Value1");
            map.put("value2", "Value2");
            map.put("value3", "Value3");
            map.put("value4", "Value4");
            map.put("value5", Arrays.asList(new String[]{ "Value5-1", "Value5-2" }));
            residual.setElements(map);
           
            ocm.update(residual);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          
            residual = (Residual) ocm.getObject( "/test");
            assertNotNull("Object is null", residual);
            assertTrue("Incorrect number of values", residual.getElements().size() == 5);           
            assertTrue("Incorrect collection element", residual.getElements().get("value2").equals("Value2"));
            assertNotNull("Missing collection element", residual.getElements().get("value5"));
            assertTrue("Incorrect collection element type", (residual.getElements().get("value5") instanceof List));
            assertEquals("Incorrect collection element list size", ((List) residual.getElements().get("value5")).size(), 2);
            assertEquals("Incorrect collection element list value", ((List) residual.getElements().get("value5")).get(0), "Value5-1");
           
            // --------------------------------------------------------------------------------
            // Update the object
            // --------------------------------------------------------------------------------
            map = new ManagedHashMap();
            map.put("value11", "Value11");
            map.put("value12", "Value12");
            map.put("value13", "Value13");
            map.put("value14", "Value14");
            map.put("value15", "Value15");
            map.put("value16", Arrays.asList(new String[]{ "Value16-1", "Value16-2" }));
            residual.setElements(map);
           
            ocm.update(residual);
            ocm.save();

            // --------------------------------------------------------------------------------
            // Get the object
            // --------------------------------------------------------------------------------          

            residual = (Residual) ocm.getObject( "/test");
            assertNotNull("Object is null", residual);
            assertTrue("Incorrect number of values", residual.getElements().size() == 6);
            assertNull("Unexpected collection element", residual.getElements().get("value2"));
            assertNull("Unexpected collection element", residual.getElements().get("value5"));
            assertTrue("Incorrect collection element", residual.getElements().get("value15").equals("Value15"));
View Full Code Here


  public void testRetrieveSingleton() {

    try {
      ObjectContentManager ocm = this.getObjectContentManager();

      //---------------------------------------------------------------------------------------------------------
      // Insert a descendant object
      //---------------------------------------------------------------------------------------------------------     
      Descendant descendant = new Descendant();
      descendant.setDescendantField("descendantValue");
      descendant.setAncestorField("ancestorValue");
      descendant.setIntField(200);
      descendant.setPath("/test");
      ocm.insert(descendant);
      ocm.save();

      //---------------------------------------------------------------------------------------------------------
      // Retrieve a descendant object
      //---------------------------------------------------------------------------------------------------------           
      descendant = null;
      descendant = (Descendant) ocm.getObject(   "/test");
      assertEquals("Descendant path is invalid", descendant.getPath(), "/test");
      assertEquals("Descendant ancestorField is invalid", descendant.getAncestorField(), "ancestorValue");
      assertEquals("Descendant descendantField is invalid", descendant.getDescendantField(), "descendantValue");
      assertEquals("Descendant intField is invalid", descendant.getIntField(), 200);

      //---------------------------------------------------------------------------------------------------------
      // Update  a descendant object
      //---------------------------------------------------------------------------------------------------------           
      descendant.setAncestorField("anotherAncestorValue");
      descendant.setIntField(123);
      ocm.update(descendant);
      ocm.save();

      //---------------------------------------------------------------------------------------------------------
      // Retrieve the updated descendant object
      //---------------------------------------------------------------------------------------------------------           
      descendant = null;
      descendant = (Descendant) ocm.getObject(   "/test");
      assertEquals("Descendant path is invalid", descendant.getPath(), "/test");
      assertEquals("Descendant ancestorField is invalid", descendant.getAncestorField(), "anotherAncestorValue");
      assertEquals("Descendant descendantField is invalid", descendant  .getDescendantField(), "descendantValue");
      assertEquals("Descendant intField is invalid", descendant.getIntField(), 123);

      Ancestor ancestor = (Ancestor) ocm.getObject("/test");
      assertTrue("Invalid object instance", ancestor instanceof Descendant );
      assertEquals("Ancestor  path is invalid", ancestor.getPath(), "/test");
      assertEquals("Ancestor ancestorField is invalid", ancestor.getAncestorField(), "anotherAncestorValue");
     
     
View Full Code Here

  }

 
  public void testAuto() {
   
    ObjectContentManager ocm = this.getObjectContentManager();

    //---------------------------------------------------------------------------------------------------------
    // Insert cmsobjects
    //---------------------------------------------------------------------------------------------------------
      Folder  folder = new FolderImpl();
      folder.setPath("/folder2");
      folder.setName("folder2");       
   
      Document document = new DocumentImpl();
      document.setPath("/folder2/document4");
      document.setName("document4");
      document.setContentType("plain/text");
      DocumentStream documentStream = new DocumentStream();
      documentStream.setEncoding("utf-8");
      documentStream.setContent("Test Content 4".getBytes());
      document.setDocumentStream(documentStream);      

      Folder subFolder = new FolderImpl();
      subFolder.setName("subfolder");
      subFolder.setPath("/folder2/subfolder");
                 
      folder.addChild(document);
      folder.addChild(subFolder);
      ocm.insert(folder);                  
    ocm.save();
   
    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve folder2
    //--------------------------------------------------------------------------------------------------------- 
    Folder folder2 = (Folder) ocm.getObject( "/folder2");
    assertNotNull("folder 2 is null", folder2);
    assertEquals("Invalid number of cms object  found in folder2 children", folder2.getChildren().size() ,0); // autoInsert = false
   
    //--------------------------------------------------------------------------------------------------------- 
    // Insert nested objects
    //---------------------------------------------------------------------------------------------------------
    ocm.insert(subFolder);
    ocm.insert(document);
    ocm.save();
   
    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve folder2
    //--------------------------------------------------------------------------------------------------------- 
     folder2 = (Folder) ocm.getObject( "/folder2");
    assertNotNull("folder 2 is null", folder2);
    assertEquals("Invalid number of cms object  found in folder2 children", folder2.getChildren().size() ,0); // autoInsert = false

    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve children attribute
    //---------------------------------------------------------------------------------------------------------     
    ocm.retrieveMappedAttribute(folder2, "children");
    assertNotNull("folder 2 is null", folder2);
    assertEquals("Invalid number of cms object  found in folder2 children", folder2.getChildren().size() ,2);
    assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class));
    assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class));   
   
    //--------------------------------------------------------------------------------------------------------- 
    // Update
    //--------------------------------------------------------------------------------------------------------- 
    folder2.setChildren(null);
    ocm.update(folder2); // autoupdate = true for the children attribute. So no update on the children collection
    ocm.save();

    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve children attribute
    //---------------------------------------------------------------------------------------------------------     
    ocm.retrieveMappedAttribute(folder2, "children");
    assertNotNull("folder 2 is null", folder2);
    assertEquals("Invalid number of cms object  found in folder2 children", folder2.getChildren().size() ,2);
    assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/document4", DocumentImpl.class));
    assertTrue("Invalid item in the collection", this.contains(folder2.getChildren(), "/folder2/subfolder", FolderImpl.class));   
   
View Full Code Here

     */
    public void testCollectionOfUuid()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();

            // --------------------------------------------------------------------------------
            // Create and store an object A in the repository
            // --------------------------------------------------------------------------------
            A a1 = new A();
            a1.setPath("/a1");
            a1.setStringData("testdata1");
            ocm.insert(a1);
           
            A a2 = new A();
            a2.setPath("/a2");
            a2.setStringData("testdata2");
            ocm.insert(a2);           
            ocm.save();          

            // --------------------------------------------------------------------------------
            // Get the objects
            // --------------------------------------------------------------------------------          
            a1 = (A) ocm.getObject( "/a1");
            assertNotNull("a1 is null", a1);
            a2 = (A) ocm.getObject( "/a2");
            assertNotNull("a2 is null", a2);
            ArrayList references = new ArrayList();
            references.add(a1.getUuid());
            references.add(a2.getUuid());
           
            // --------------------------------------------------------------------------------
            // Create and store an object B in the repository which has a collection of A
            // --------------------------------------------------------------------------------
            B b = new B();
            b.setPath("/testB");
            b.setMultiReferences(references);
            ocm.insert(b);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Retrieve object B
            // --------------------------------------------------------------------------------
            b = (B) ocm.getObject("/testB");
            Collection allref = b.getMultiReferences();
            assertNotNull("collection is null", allref);
            assertTrue("Invalid number of items in the collection", allref.size() == 2);

            // --------------------------------------------------------------------------------
            // Update object B with invalid uuid
            // --------------------------------------------------------------------------------
            allref.add("12345");
            b.setMultiReferences(allref);
            try
            {
              ocm.update(b);             
              fail("Exception not throw");
            }
            catch(Exception e)
            {
              //Throws an exception due to an invalid uuid
              System.out.println("Invalid uuid value in the collection : " + e);
             
            }
           
            // --------------------------------------------------------------------------------
            // Update object B with an null value
            // --------------------------------------------------------------------------------
            b.setMultiReferences(null);
            ocm.update(b);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Retrieve object B
            // --------------------------------------------------------------------------------
            b = (B) ocm.getObject("/testB");           
            assertNull("a is not null", b.getMultiReferences());
           
           
        }
        catch (Exception e)
View Full Code Here

  }

 
  public void testRetrieveCollection() {
    ObjectContentManager ocm = this.getObjectContentManager();

    //--------------------------------------------------------------------------------------------------------- 
    // Insert  descendant objects
    //---------------------------------------------------------------------------------------------------------     
    Descendant descendant = new Descendant();
    descendant.setDescendantField("descendantValue");
    descendant.setAncestorField("ancestorValue");
    descendant.setPath("/descendant1");
    ocm.insert(descendant);

    descendant = new Descendant();
    descendant.setDescendantField("descendantValue2");
    descendant.setAncestorField("ancestorValue2");
    descendant.setPath("/descendant2");
    ocm.insert(descendant);

    SubDescendant subDescendant = new SubDescendant();
    subDescendant.setDescendantField("descendantValue2");
    subDescendant.setAncestorField("ancestorValue2");
    subDescendant.setPath("/subdescendant");
    subDescendant.setSubDescendantField("subdescendantvalue");
    ocm.insert(subDescendant);   

     subDescendant = new SubDescendant();
    subDescendant.setDescendantField("descendantValue3");
    subDescendant.setAncestorField("ancestorValue2");
    subDescendant.setPath("/subdescendant2");
    subDescendant.setSubDescendantField("subdescendantvalue1");
    ocm.insert(subDescendant);   
   
   
    AnotherDescendant anotherDescendant = new AnotherDescendant();
    anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
    anotherDescendant.setAncestorField("ancestorValue3");
    anotherDescendant.setPath("/anotherdescendant1");
    ocm.insert(anotherDescendant);

    anotherDescendant = new AnotherDescendant();
    anotherDescendant.setAnotherDescendantField("anotherDescendantValue");
    anotherDescendant.setAncestorField("ancestorValue4");
    anotherDescendant.setPath("/anotherdescendant2");
    ocm.insert(anotherDescendant);

    anotherDescendant = new AnotherDescendant();
    anotherDescendant.setAnotherDescendantField("anotherDescendantValue2");
    anotherDescendant.setAncestorField("ancestorValue5");
    anotherDescendant.setPath("/anotherdescendant3");
    ocm.insert(anotherDescendant);

   
    Atomic a = new Atomic();
    a.setPath("/atomic");
    a.setBooleanPrimitive(true);
    ocm.insert(a);

    ocm.save();

    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve Descendant class
    //---------------------------------------------------------------------------------------------------------     
    QueryManager queryManager = ocm.getQueryManager();
    Filter filter = queryManager.createFilter(Descendant.class);
    Query query = queryManager.createQuery(filter);

    Collection result = ocm.getObjects(query);
    assertEquals("Invalid number of Descendant found", result.size(), 4);
    assertTrue("Invalid item in the collection", this.contains(result, "/descendant1", Descendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant2", SubDescendant.class));
   

    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve AnotherDescendant class
    //---------------------------------------------------------------------------------------------------------     
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(AnotherDescendant.class);
    filter.addEqualTo("anotherDescendantField", "anotherDescendantValue");
    query = queryManager.createQuery(filter);

    result = ocm.getObjects(query);
    assertEquals("Invalid number of AnotherDescendant found", result.size(),2);
    assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant1", AnotherDescendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/anotherdescendant2", AnotherDescendant.class));

    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve some descendants & subdescendants
    //---------------------------------------------------------------------------------------------------------     
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(Descendant.class);   
    filter.addEqualTo("descendantField","descendantValue2");
    query = queryManager.createQuery(filter);

    result = ocm.getObjects(query);
    assertEquals("Invalid ancestor object found", result.size(),2);
    assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
   
    //--------------------------------------------------------------------------------------------------------- 
    // Retrieve all class
    //---------------------------------------------------------------------------------------------------------     
    queryManager = ocm.getQueryManager();
    filter = queryManager.createFilter(Ancestor.class);   
    query = queryManager.createQuery(filter);

    result = ocm.getObjects(query);
    assertEquals("Invalid ancestor object found", result.size(),7);
    assertTrue("Invalid item in the collection", this.contains(result, "/descendant1", Descendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/descendant2", Descendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant", SubDescendant.class));
    assertTrue("Invalid item in the collection", this.contains(result, "/subdescendant2", SubDescendant.class));
View Full Code Here

     */
    public void testCollectionOfBeanWithUuid()
    {
        try
        {
          ObjectContentManager ocm = getObjectContentManager();

            // --------------------------------------------------------------------------------
            // Create and store an object A in the repository
            // --------------------------------------------------------------------------------
            A a1 = new A();
            a1.setPath("/a1");
            a1.setStringData("testdata1");
            ocm.insert(a1);
           
            A a2 = new A();
            a2.setPath("/a2");
            a2.setStringData("testdata2");
            ocm.insert(a2);           
            ocm.save();          

            // --------------------------------------------------------------------------------
            // Get the objects
            // --------------------------------------------------------------------------------          
            a1 = (A) ocm.getObject( "/a1");
            assertNotNull("a1 is null", a1);
            a2 = (A) ocm.getObject( "/a2");
            assertNotNull("a2 is null", a2);
            ArrayList references = new ArrayList();
            references.add(a1);
            references.add(a2);
           
            // --------------------------------------------------------------------------------
            // Create and store an object B in the repository which has a collection of A
            // --------------------------------------------------------------------------------
            B2 b = new B2();
            b.setPath("/testB2");
            b.setMultiReferences(references);
            ocm.insert(b);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Retrieve object B
            // --------------------------------------------------------------------------------
            b = (B2) ocm.getObject("/testB2");
            Collection allref = b.getMultiReferences();
            assertNotNull("collection is null", allref);
            assertTrue("Invalid number of items in the collection", allref.size() == 2);
            this.contains(allref, "/a1" , A.class);
            this.contains(allref, "/a2" , A.class);

            // --------------------------------------------------------------------------------
            // Update object B with an null value
            // --------------------------------------------------------------------------------
            b.setMultiReferences(null);
            ocm.update(b);
            ocm.save();
           
            // --------------------------------------------------------------------------------
            // Retrieve object B
            // --------------------------------------------------------------------------------
            b = (B2) ocm.getObject("/testB2");           
            assertNull("a is not null", b.getMultiReferences());
           
           
        }
        catch (Exception e)
View Full Code Here

  public void testRequiredProperty()
  {

    try
    {
      ObjectContentManager ocm = this.getObjectContentManager();
      //---------------------------------------------------------------------------------------------------------
      // Insert without the mandatory field
      //---------------------------------------------------------------------------------------------------------     
     
            PropertyTest propertyTest = new PropertyTest();
            propertyTest.setPath("/test");
            propertyTest.setRequiredProp("requiredPropValue");
            propertyTest.setRequiredWithConstraintsProp("abc");
           
            try
            {
                 ocm.insert(propertyTest);
                 fail("Incorrect insert operation - the mandatory fields have no value");
            }
            catch(Exception e)
            {
               // Normal behaviour  
              ocm.refresh(false);
            }
           
      //---------------------------------------------------------------------------------------------------------
      // Insert with the mandatory fields
      //---------------------------------------------------------------------------------------------------------     
            propertyTest.setMandatoryProp("mandatoryValue");
            propertyTest.setMandatoryWithConstaintsProp("xx");
            ocm.insert(propertyTest);
            ocm.save();
           
      //---------------------------------------------------------------------------------------------------------
      // Retrieve
      //---------------------------------------------------------------------------------------------------------     
            propertyTest = (PropertyTest) ocm.getObject("/test");
            assertTrue("Invalid required property", propertyTest.getRequiredProp().equals("requiredPropValue"));
            assertTrue("Invalid required property with constraints", propertyTest.getRequiredWithConstraintsProp().equals("abc"));           
            assertTrue("Invalid autocreated property", propertyTest.getAutoCreatedProp().equals("aaa"));
            assertTrue("Invalid autocreated property", propertyTest.getAutoCreatedWithConstraintsProp().equals("ccc"));
            assertTrue("Invalid protected property", propertyTest.getProtectedWithDefaultValueProp().equals("protectedValue"));
           
            //---------------------------------------------------------------------------------------------------------
      // update the property requiredWithConstraintsProp with bad value
      //---------------------------------------------------------------------------------------------------------     
            propertyTest = (PropertyTest) ocm.getObject("/test");
            propertyTest.setRequiredWithConstraintsProp("invalid value");
            try
            {
              ocm.update(propertyTest);
              ocm.save();
              fail("Invalid value was accepted for requiredWithConstraintsProp");
            }
            catch(Exception e)
            {                 
               // Do nothing - normal behaviour, the value                
            }
           
            //---------------------------------------------------------------------------------------------------------
      // update the property AutoCreatedWithConstraintsProp with bad value
      //---------------------------------------------------------------------------------------------------------     
            propertyTest = (PropertyTest) ocm.getObject("/test");
            propertyTest.setAutoCreatedWithConstraintsProp("invalid value");
            try
            {
              ocm.update(propertyTest);
              ocm.save();
              fail("Invalid value was accepted for autoCreatedWithConstraintsProp ");
            }
            catch(Exception e)
            {              
               // Do nothing - normal behaviour, the value is not valid
                
            }
           
            //---------------------------------------------------------------------------------------------------------
      // update the property mandatoryWithConstaintsProp with bad value
      //---------------------------------------------------------------------------------------------------------     
            propertyTest = (PropertyTest) ocm.getObject("/test");
            propertyTest.setMandatoryWithConstaintsProp("yy");
            try
            {
              ocm.update(propertyTest);
              ocm.save();
              fail("Invalid value was accepted for mandatoryWithConstaintsProp");
            }
            catch(Exception e)
            {                 
                e.printStackTrace();
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.ocm.manager.ObjectContentManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.