1 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 ; 13 14 17 public class TerracottaDomainConfigurationDocumentBeanFactoryTest extends TCTestCase { 18 19 private TerracottaDomainConfigurationDocumentBeanFactory factory; 20 21 public void setUp() throws Exception { 22 this.factory = new TerracottaDomainConfigurationDocumentBeanFactory(); 23 } 24 25 public void testNormal() throws Exception { 26 TerracottaConfigBuilder builder = TerracottaConfigBuilder.newMinimalInstance(); 27 builder.getClient().setLogs("foobar"); 28 byte[] xml = builder.toString().getBytes(); 29 ByteArrayInputStream stream = new ByteArrayInputStream (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 { 37 TerracottaConfigBuilder builder = TerracottaConfigBuilder.newMinimalInstance(); 38 builder.getClient().setLogs("foo <funk>"); byte[] xml = builder.toString().getBytes(); 40 ByteArrayInputStream stream = new ByteArrayInputStream (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 } 48 } 49 50 public void testSchemaViolation() throws Exception { 51 TerracottaConfigBuilder builder = TerracottaConfigBuilder.newMinimalInstance(); 52 builder.getSystem().setLicenseType("funkiness"); builder.getSystem().setLicenseLocation("foo"); 54 byte[] xml = builder.toString().getBytes(); 55 ByteArrayInputStream stream = new ByteArrayInputStream (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 |