1 5 6 package org.exoplatform.services.jcr.api.writing; 7 8 9 import javax.jcr.*; 10 import org.exoplatform.services.jcr.BaseTest; 11 import java.io.ByteArrayInputStream ; 12 import java.util.GregorianCalendar ; 13 14 19 public class ValueTest extends BaseTest{ 20 21 public void initRepository() throws RepositoryException { 22 Node root = ticket.getRootNode(); 23 Node propDef = root.addNode("propertyDefNode", "nt:propertyDef"); 24 propDef.setProperty("jcr:defaultValue", "testString"); 26 27 root.addNode("childNodeDefNode", "nt:childNodeDef"); 28 ticket.save(); 29 } 30 31 public void tearDown() throws RepositoryException { 32 ticket = repository.login(credentials, WORKSPACE); 33 Node root = ticket.getRootNode(); 34 root.remove("propertyDefNode"); 35 root.remove("childNodeDefNode"); 36 ticket.save(); 37 } 38 39 public void testSetValue() throws RepositoryException { 40 Node root = ticket.getRootNode(); 41 Property property = root.getNode("propertyDefNode").getProperty("jcr:defaultValue"); 42 43 property.setValue(new StringValue("haha")); 44 property.setValue("default"); 45 property.setValue(new ByteArrayInputStream (new String ("default").getBytes())); 46 property.setValue(true); 47 property.setValue(new GregorianCalendar ()); 48 property.setValue(20D); 49 property.setValue(20L); 50 51 Value[] values = {new StringValue("not"), new StringValue("in")}; 52 try { 53 property.setValue(values); 54 fail("exception should have been thrown"); 55 } catch (ValueFormatException e) { 56 } 57 58 property = root.getNode("propertyDefNode").getProperty("jcr:multiple"); 59 try { 60 property.setValue(20D); 61 fail("ValueFormatException should have been thrown"); 62 } catch (ValueFormatException e) { 63 } 64 65 property = root.getNode("childNodeDefNode").getProperty("jcr:requiredPrimaryTypes"); 66 property.setValue(values); 67 68 root.save(false); 69 70 ticket = repository.login(credentials, WORKSPACE); 71 Node node = ticket.getRootNode().getNode("childNodeDefNode"); 72 assertEquals(2, node.getProperty("jcr:requiredPrimaryTypes").getValues().length); 73 74 } 75 76 } 77 | Popular Tags |