KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > api > writing > fs > TestValue


1 /*
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  */

5
6 package org.exoplatform.services.jcr.api.writing.fs;
7
8
9 import java.io.ByteArrayInputStream JavaDoc;
10 import java.util.GregorianCalendar JavaDoc;
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 /**
23  * Created y the eXo platform team
24  * User: Benjamin Mestrallet
25  * Date: 2 aout 2004
26  */

27 public class TestValue extends ValueTest{
28
29   public void setUp() throws Exception JavaDoc {
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 // ticket.save();
40
}
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 // ticket.save();
48
}
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 JavaDoc(new String JavaDoc("default").getBytes()));
57     property.setValue(true);
58     property.setValue(new GregorianCalendar JavaDoc());
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 // root.save(false);
80

81 // ticket = repository.login(credentials, WORKSPACE);
82
Node node = ticket.getRootNode().getNode("childNodeDefNode");
83     assertEquals(2, node.getProperty("jcr:requiredPrimaryTypes").getValues().length);
84
85   }
86
87 }
88
Popular Tags