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