*/
public void testFindSpecifiedType() throws Exception {
EnunciateFreemarkerModel model = new EnunciateFreemarkerModel();
FreemarkerModel.set(model);
model.add(new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.AdaptedBeanTwo")));
ClassDeclaration adaptedBeanExamplesDeclaration = (ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.AdaptedBeanExamples");
ComplexTypeDefinition examples = new ComplexTypeDefinition(adaptedBeanExamplesDeclaration);
Accessor beanOneField = null;
Accessor beanThreeField = null;
Accessor beanFourField = null;
Accessor stringBufferField = null;
for (Accessor fieldDeclaration : examples.getElements()) {
if ("adaptedBeanOne".equals(fieldDeclaration.getSimpleName())) {
beanOneField = fieldDeclaration;
}
else if ("adaptedBeanThree".equals(fieldDeclaration.getSimpleName())) {
beanThreeField = fieldDeclaration;
}
else if ("stringBuffer".equals(fieldDeclaration.getSimpleName())) {
stringBufferField = fieldDeclaration;
}
else if ("beanFour".equals(fieldDeclaration.getSimpleName())) {
beanFourField = fieldDeclaration;
}
}
assertNotNull(beanFourField);
XmlType beanFourXmlType = XmlTypeFactory.findExplicitSchemaType(beanFourField);
assertEquals("The xml type for bean four should have been specified at the package-level.", "specified-bean-four", beanFourXmlType.getName());
assertEquals("The xml type for bean four should have been specified at the package-level.", "http://org.codehaus.enunciate/core/samples/beanfour", beanFourXmlType.getNamespace());
assertNull(XmlTypeFactory.findSpecifiedType(new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.schema.DifferentPackageReferencingBeanFour")).getElements().first()));
assertNotNull(beanOneField);
assertEquals(new QName("http://org.codehaus.enunciate/core/samples/another", "adaptedBeanTwo"), XmlTypeFactory.findSpecifiedType(beanOneField).getQname());
assertNotNull(beanThreeField);
assertEquals(KnownXmlType.STRING.getQname(), XmlTypeFactory.findSpecifiedType(beanThreeField).getQname());
assertNotNull(stringBufferField);
assertEquals(KnownXmlType.STRING.getQname(), XmlTypeFactory.findSpecifiedType(stringBufferField).getQname());
EndpointInterface ei = new EndpointInterface(adaptedBeanExamplesDeclaration);
WebParam beanFourParam = ei.getWebMethods().iterator().next().getWebParameters().iterator().next();
assertNotNull(beanFourParam);
assertEquals(new QName("http://org.codehaus.enunciate/core/samples/another", "adaptedBeanTwo"), XmlTypeFactory.findSpecifiedType(beanFourParam).getQname());
try {
new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.AdaptedBeanBadExamples"));
fail("Shouldn't be a valid xml type adapter.");
}
catch (ValidationException e) {
//fall through...
}
try {
new ComplexTypeDefinition((ClassDeclaration) getDeclaration("org.codehaus.enunciate.samples.anotherschema.AdaptedBeanBadExamples2"));
fail("Shouldn't be a valid xml type adapter.");
}
catch (ValidationException e) {
//fall through...
}