Search in sources :

Example 1 with BusApplicationContext

use of org.apache.cxf.bus.spring.BusApplicationContext in project cxf by apache.

the class ConfigurerImplTest method testConfigureSimpleMatchingStarBeanId.

@Test
public void testConfigureSimpleMatchingStarBeanId() {
    SimpleBean sb = new SimpleBean("simple2");
    BusApplicationContext ac = new BusApplicationContext("/org/apache/cxf/configuration/spring/test-beans.xml", false);
    ConfigurerImpl configurer = new ConfigurerImpl();
    configurer.setApplicationContext(ac);
    configurer.configureBean(sb);
    assertTrue("Unexpected value for attribute booleanAttr", !sb.getBooleanAttr());
    assertEquals("Unexpected value for attribute integerAttr", BigInteger.TEN, sb.getIntegerAttr());
    assertEquals("Unexpected value for attribute stringAttr", "StarHallo", sb.getStringAttr());
}
Also used : BusApplicationContext(org.apache.cxf.bus.spring.BusApplicationContext) Test(org.junit.Test)

Example 2 with BusApplicationContext

use of org.apache.cxf.bus.spring.BusApplicationContext in project cxf by apache.

the class ConfigurerImplTest method testConfigureSimpleNoMatchingBean.

@Test
public void testConfigureSimpleNoMatchingBean() {
    SimpleBean sb = new SimpleBean("unknown");
    BusApplicationContext ac = new BusApplicationContext("/org/apache/cxf/configuration/spring/test-beans.xml", false);
    ConfigurerImpl configurer = new ConfigurerImpl(ac);
    configurer.configureBean(sb);
    assertEquals("Unexpected value for attribute stringAttr", "hello", sb.getStringAttr());
    assertTrue("Unexpected value for attribute booleanAttr", sb.getBooleanAttr());
    assertEquals("Unexpected value for attribute integerAttr", BigInteger.ONE, sb.getIntegerAttr());
    assertEquals("Unexpected value for attribute intAttr", Integer.valueOf(2), sb.getIntAttr());
    assertEquals("Unexpected value for attribute longAttr", Long.valueOf(3L), sb.getLongAttr());
    assertEquals("Unexpected value for attribute shortAttr", Short.valueOf((short) 4), sb.getShortAttr());
    assertEquals("Unexpected value for attribute decimalAttr", new BigDecimal("5"), sb.getDecimalAttr());
    assertEquals("Unexpected value for attribute floatAttr", Float.valueOf(6F), sb.getFloatAttr());
    assertEquals("Unexpected value for attribute doubleAttr", Double.valueOf(7.0D), sb.getDoubleAttr());
    assertEquals("Unexpected value for attribute byteAttr", Byte.valueOf((byte) 8), sb.getByteAttr());
    QName qn = sb.getQnameAttr();
    assertEquals("Unexpected value for attribute qnameAttrNoDefault", "schema", qn.getLocalPart());
    assertEquals("Unexpected value for attribute qnameAttrNoDefault", "http://www.w3.org/2001/XMLSchema", qn.getNamespaceURI());
    byte[] expected = DatatypeConverter.parseBase64Binary("abcd");
    byte[] val = sb.getBase64BinaryAttr();
    assertEquals("Unexpected value for attribute base64BinaryAttrNoDefault", expected.length, val.length);
    for (int i = 0; i < expected.length; i++) {
        assertEquals("Unexpected value for attribute base64BinaryAttrNoDefault", expected[i], val[i]);
    }
    expected = new HexBinaryAdapter().unmarshal("aaaa");
    val = sb.getHexBinaryAttr();
    assertEquals("Unexpected value for attribute hexBinaryAttrNoDefault", expected.length, val.length);
    for (int i = 0; i < expected.length; i++) {
        assertEquals("Unexpected value for attribute hexBinaryAttrNoDefault", expected[i], val[i]);
    }
    assertEquals("Unexpected value for attribute unsignedIntAttrNoDefault", Long.valueOf(9L), sb.getUnsignedIntAttr());
    assertEquals("Unexpected value for attribute unsignedShortAttrNoDefault", Integer.valueOf(10), sb.getUnsignedShortAttr());
    assertEquals("Unexpected value for attribute unsignedByteAttrNoDefault", Short.valueOf((short) 11), sb.getUnsignedByteAttr());
}
Also used : BusApplicationContext(org.apache.cxf.bus.spring.BusApplicationContext) HexBinaryAdapter(javax.xml.bind.annotation.adapters.HexBinaryAdapter) QName(javax.xml.namespace.QName) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with BusApplicationContext

use of org.apache.cxf.bus.spring.BusApplicationContext in project cxf by apache.

the class ConfigurerImplTest method verifyConfigureSimple.

public void verifyConfigureSimple(String beanName) {
    SimpleBean sb = new SimpleBean(beanName);
    BusApplicationContext ac = new BusApplicationContext("/org/apache/cxf/configuration/spring/test-beans.xml", false);
    ConfigurerImpl configurer = new ConfigurerImpl();
    configurer.setApplicationContext(ac);
    configurer.configureBean(sb);
    assertEquals("Unexpected value for attribute stringAttr", "hallo", sb.getStringAttr());
    assertTrue("Unexpected value for attribute booleanAttr", !sb.getBooleanAttr());
    assertEquals("Unexpected value for attribute integerAttr", BigInteger.TEN, sb.getIntegerAttr());
    assertEquals("Unexpected value for attribute intAttr", Integer.valueOf(12), sb.getIntAttr());
    assertEquals("Unexpected value for attribute longAttr", Long.valueOf(13L), sb.getLongAttr());
    assertEquals("Unexpected value for attribute shortAttr", Short.valueOf((short) 14), sb.getShortAttr());
    assertEquals("Unexpected value for attribute decimalAttr", new BigDecimal("15"), sb.getDecimalAttr());
    assertEquals("Unexpected value for attribute floatAttr", Float.valueOf(16F), sb.getFloatAttr());
    assertEquals("Unexpected value for attribute doubleAttr", Double.valueOf(17D), sb.getDoubleAttr());
    assertEquals("Unexpected value for attribute byteAttr", Byte.valueOf((byte) 18), sb.getByteAttr());
    assertEquals("Unexpected value for attribute unsignedIntAttrNoDefault", Long.valueOf(19L), sb.getUnsignedIntAttr());
    assertEquals("Unexpected value for attribute unsignedShortAttrNoDefault", Integer.valueOf(20), sb.getUnsignedShortAttr());
    assertEquals("Unexpected value for attribute unsignedByteAttrNoDefault", Short.valueOf((short) 21), sb.getUnsignedByteAttr());
}
Also used : BusApplicationContext(org.apache.cxf.bus.spring.BusApplicationContext) BigDecimal(java.math.BigDecimal)

Example 4 with BusApplicationContext

use of org.apache.cxf.bus.spring.BusApplicationContext in project cxf by apache.

the class ConfigurerImplTest method testConfigureSimpleMatchingStarBeanIdWithChildInstance.

@Test
public void testConfigureSimpleMatchingStarBeanIdWithChildInstance() {
    SimpleBean sb = new ChildBean("simple2");
    BusApplicationContext ac = new BusApplicationContext("/org/apache/cxf/configuration/spring/test-beans.xml", false);
    ConfigurerImpl configurer = new ConfigurerImpl();
    configurer.setApplicationContext(ac);
    configurer.configureBean(sb);
    assertTrue("Unexpected value for attribute booleanAttr", !sb.getBooleanAttr());
    assertEquals("Unexpected value for attribute integerAttr", BigInteger.TEN, sb.getIntegerAttr());
    assertEquals("Unexpected value for attribute stringAttr", "StarHallo", sb.getStringAttr());
}
Also used : BusApplicationContext(org.apache.cxf.bus.spring.BusApplicationContext) Test(org.junit.Test)

Example 5 with BusApplicationContext

use of org.apache.cxf.bus.spring.BusApplicationContext in project cxf by apache.

the class SpringServiceBuilderFactory method getApplicationContext.

/**
 * This is factored out to permit use in a unit test.
 *
 * @param bus
 * @return
 */
public static ApplicationContext getApplicationContext(List<String> additionalFilePathnames) {
    BusApplicationContext busApplicationContext = BusFactory.getDefaultBus().getExtension(BusApplicationContext.class);
    GenericApplicationContext appContext = new GenericApplicationContext(busApplicationContext);
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
    List<URL> urls = ClassLoaderUtils.getResources("META-INF/cxf/java2wsbeans.xml", SpringServiceBuilderFactory.class);
    for (URL url : urls) {
        reader.loadBeanDefinitions(new UrlResource(url));
    }
    for (String pathname : additionalFilePathnames) {
        try {
            reader.loadBeanDefinitions(new FileSystemResource(pathname));
        } catch (BeanDefinitionStoreException bdse) {
            throw new ToolException("Unable to open bean definition file " + pathname, bdse.getCause());
        }
    }
    appContext.refresh();
    return appContext;
}
Also used : BusApplicationContext(org.apache.cxf.bus.spring.BusApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) UrlResource(org.springframework.core.io.UrlResource) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) FileSystemResource(org.springframework.core.io.FileSystemResource) ToolException(org.apache.cxf.tools.common.ToolException) URL(java.net.URL)

Aggregations

BusApplicationContext (org.apache.cxf.bus.spring.BusApplicationContext)5 Test (org.junit.Test)3 BigDecimal (java.math.BigDecimal)2 URL (java.net.URL)1 HexBinaryAdapter (javax.xml.bind.annotation.adapters.HexBinaryAdapter)1 QName (javax.xml.namespace.QName)1 ToolException (org.apache.cxf.tools.common.ToolException)1 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)1 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 FileSystemResource (org.springframework.core.io.FileSystemResource)1 UrlResource (org.springframework.core.io.UrlResource)1