KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > beanfactory > TerracottaDomainConfigurationDocumentBeanFactoryTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.beanfactory;
5
6 import org.apache.xmlbeans.XmlException;
7
8 import com.tc.config.schema.test.TerracottaConfigBuilder;
9 import com.tc.test.TCTestCase;
10 import com.terracottatech.config.TcConfigDocument;
11
12 import java.io.ByteArrayInputStream JavaDoc;
13
14 /**
15  * Unit test for {@link TerracottaDomainConfigurationDocumentBeanFactory}.
16  */

17 public class TerracottaDomainConfigurationDocumentBeanFactoryTest extends TCTestCase {
18
19   private TerracottaDomainConfigurationDocumentBeanFactory factory;
20
21   public void setUp() throws Exception JavaDoc {
22     this.factory = new TerracottaDomainConfigurationDocumentBeanFactory();
23   }
24
25   public void testNormal() throws Exception JavaDoc {
26     TerracottaConfigBuilder builder = TerracottaConfigBuilder.newMinimalInstance();
27     builder.getClient().setLogs("foobar");
28     byte[] xml = builder.toString().getBytes();
29     ByteArrayInputStream JavaDoc stream = new ByteArrayInputStream JavaDoc(xml);
30
31     BeanWithErrors beanWithErrors = this.factory.createBean(stream, "from test");
32     assertEquals(0, beanWithErrors.errors().length);
33     assertEquals("foobar", ((TcConfigDocument) beanWithErrors.bean()).getTcConfig().getClients().getLogs());
34   }
35
36   public void testXmlMisparse() throws Exception JavaDoc {
37     TerracottaConfigBuilder builder = TerracottaConfigBuilder.newMinimalInstance();
38     builder.getClient().setLogs("foo <funk>"); // an unclosed tag; the builder intentionally doesn't escape text
39
byte[] xml = builder.toString().getBytes();
40     ByteArrayInputStream JavaDoc stream = new ByteArrayInputStream JavaDoc(xml);
41
42     try {
43       this.factory.createBean(stream, "from test");
44       fail("Didn't get XmlException on invalid XML");
45     } catch (XmlException xmle) {
46       // ok
47
}
48   }
49
50   public void testSchemaViolation() throws Exception JavaDoc {
51     TerracottaConfigBuilder builder = TerracottaConfigBuilder.newMinimalInstance();
52     builder.getSystem().setLicenseType("funkiness"); // invalid enumeration value
53
builder.getSystem().setLicenseLocation("foo");
54     byte[] xml = builder.toString().getBytes();
55     ByteArrayInputStream JavaDoc stream = new ByteArrayInputStream JavaDoc(xml);
56
57     BeanWithErrors beanWithErrors = this.factory.createBean(stream, "from test");
58     assertEquals(1, beanWithErrors.errors().length);
59     assertEquals("from test", beanWithErrors.errors()[0].getSourceName());
60     assertTrue(beanWithErrors.bean() instanceof TcConfigDocument);
61   }
62 }
63
Popular Tags