001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.aegis.type.java5;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.apache.cxf.aegis.AbstractAegisTest;
023: import org.apache.cxf.aegis.type.Configuration;
024: import org.apache.cxf.aegis.type.CustomTypeMapping;
025: import org.apache.cxf.aegis.type.DefaultTypeMappingRegistry;
026: import org.apache.cxf.aegis.type.Type;
027: import org.apache.cxf.aegis.type.XMLTypeCreator;
028: import org.apache.cxf.aegis.type.basic.BeanType;
029: import org.apache.cxf.aegis.type.basic.BeanTypeInfo;
030: import org.junit.Before;
031: import org.junit.Test;
032:
033: /**
034: * @author adam
035: */
036: public class ConfigurationTest extends AbstractAegisTest {
037:
038: CustomTypeMapping tm;
039:
040: Configuration config;
041:
042: @Before
043: public void setUp() throws Exception {
044: super .setUp();
045:
046: DefaultTypeMappingRegistry reg = new DefaultTypeMappingRegistry();
047: config = reg.getConfiguration();
048: XMLTypeCreator creator = new XMLTypeCreator();
049: creator.setConfiguration(reg.getConfiguration());
050: Java5TypeCreator next = new Java5TypeCreator();
051: next.setConfiguration(reg.getConfiguration());
052: creator.setNextCreator(next);
053: reg.createDefaultMappings();
054: tm = (CustomTypeMapping) reg.getDefaultTypeMapping();
055: tm.setTypeCreator(creator);
056: }
057:
058: @Test
059: public void testNillableDefaultTrue() throws Exception {
060: config.setDefaultNillable(true);
061:
062: Type type = tm.getTypeCreator()
063: .createType(AnnotatedBean1.class);
064: BeanTypeInfo info = ((BeanType) type).getTypeInfo();
065:
066: assertTrue(info.isNillable(new QName(
067: info.getDefaultNamespace(), "bogusProperty")));
068: }
069:
070: @Test
071: public void testNillableDefaultFalse() throws Exception {
072: config.setDefaultNillable(false);
073: Type type = tm.getTypeCreator()
074: .createType(AnnotatedBean1.class);
075: BeanTypeInfo info = ((BeanType) type).getTypeInfo();
076:
077: assertFalse(info.isNillable(new QName(info
078: .getDefaultNamespace(), "bogusProperty")));
079: }
080:
081: @Test
082: public void testMinOccursDefault0() throws Exception {
083: config.setDefaultMinOccurs(0);
084: Type type = tm.getTypeCreator()
085: .createType(AnnotatedBean1.class);
086: BeanTypeInfo info = ((BeanType) type).getTypeInfo();
087:
088: assertEquals(info.getMinOccurs(new QName(info
089: .getDefaultNamespace(), "bogusProperty")), 0);
090: }
091:
092: @Test
093: public void testMinOccursDefault1() throws Exception {
094: config.setDefaultMinOccurs(1);
095: Type type = tm.getTypeCreator()
096: .createType(AnnotatedBean1.class);
097: BeanTypeInfo info = ((BeanType) type).getTypeInfo();
098:
099: assertEquals(info.getMinOccurs(new QName(info
100: .getDefaultNamespace(), "bogusProperty")), 1);
101: }
102:
103: @Test
104: public void testExtensibleDefaultTrue() throws Exception {
105: config.setDefaultExtensibleElements(true);
106: config.setDefaultExtensibleAttributes(true);
107: Type type = tm.getTypeCreator()
108: .createType(AnnotatedBean1.class);
109: BeanTypeInfo info = ((BeanType) type).getTypeInfo();
110: assertTrue(info.isExtensibleElements());
111: assertTrue(info.isExtensibleAttributes());
112: }
113:
114: @Test
115: public void testExtensibleDefaultFalse() throws Exception {
116: config.setDefaultExtensibleElements(false);
117: config.setDefaultExtensibleAttributes(false);
118: Type type = tm.getTypeCreator()
119: .createType(AnnotatedBean1.class);
120: BeanTypeInfo info = ((BeanType) type).getTypeInfo();
121: assertFalse(info.isExtensibleElements());
122: assertFalse(info.isExtensibleAttributes());
123: }
124:
125: }
|