KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > jcr > api > writing > ValueTest


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;
7
8
9 import javax.jcr.*;
10 import org.exoplatform.services.jcr.BaseTest;
11 import java.io.ByteArrayInputStream JavaDoc;
12 import java.util.GregorianCalendar JavaDoc;
13
14 /**
15  * Created y the eXo platform team
16  * User: Benjamin Mestrallet
17  * Date: 2 ao�t 2004
18  */

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     // Unknown Property Type. Should set something!
25
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 JavaDoc(new String JavaDoc("default").getBytes()));
46     property.setValue(true);
47     property.setValue(new GregorianCalendar JavaDoc());
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