|
Apache CXF example source code file (ManagedConnectionFactoryImplTest.java)
The Apache CXF ManagedConnectionFactoryImplTest.java source code/** * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.cxf.jca.cxf; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.util.HashSet; import java.util.Properties; import java.util.Set; import javax.resource.ResourceException; import javax.resource.spi.ConnectionManager; import javax.resource.spi.ManagedConnection; import javax.security.auth.Subject; import javax.xml.namespace.QName; import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; import org.apache.cxf.connector.CXFConnectionFactory; import org.apache.hello_world_soap_http.Greeter; import org.easymock.classextension.EasyMock; import org.junit.Assert; import org.junit.Before; import org.junit.Test; public class ManagedConnectionFactoryImplTest extends Assert { protected ManagedConnectionFactoryImpl mci; protected CXFConnectionRequestInfo cri; protected CXFConnectionRequestInfo cri2; protected CXFConnectionRequestInfo cri3; @Before public void setUp() throws Exception { mci = createManagedConnectionFactoryImpl(); URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl"); QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPService"); QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapPort"); cri = new CXFConnectionRequestInfo(Greeter.class, wsdl, serviceName, portName); cri2 = new CXFConnectionRequestInfo(Greeter.class, wsdl, new QName("service2"), new QName("fooPort2")); cri3 = new CXFConnectionRequestInfo(Greeter.class, wsdl, new QName("service3"), new QName("fooPort3")); } @SuppressWarnings("deprecation") @Test public void testSetConfigurationDomain() throws Exception { final String domainName = "SomeDomain"; Properties p = new Properties(); ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(p); mcf.setConfigurationDomain(domainName); assertTrue(p.containsValue(domainName)); assertEquals(domainName, mcf.getConfigurationDomain()); } @SuppressWarnings("deprecation") @Test public void testGetConfigurationDomainReturnsDefaultValue() throws Exception { Properties p = new Properties(); ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(p); assertEquals(ManagedConnectionFactoryImpl.CONFIG_DOMAIN, mcf.getConfigurationDomain()); } @SuppressWarnings("deprecation") @Test public void testSetConfigurationScope() throws Exception { final String name = "a.b.c"; Properties p = new Properties(); ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(p); mcf.setConfigurationScope(name); assertTrue(p.containsValue(name)); assertEquals(name, mcf.getConfigurationScope()); } @SuppressWarnings("deprecation") @Test public void testGetConfigurationScopeReturnsDefaultValue() throws Exception { Properties p = new Properties(); ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(p); assertEquals(ManagedConnectionFactoryImpl.CONFIG_SCOPE, mcf.getConfigurationScope()); } @Test public void testSetEJBServicePropertiesURL() throws Exception { final String name = "file://foo.txt"; Properties p = new Properties(); ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(p); mcf.setEJBServicePropertiesURL(name); assertTrue(p.containsValue(name)); assertEquals(name, mcf.getEJBServicePropertiesURL()); } @Test public void testSetMonitorEJBServiceProperties() throws Exception { final Boolean value = Boolean.TRUE; Properties p = new Properties(); ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(p); mcf.setMonitorEJBServiceProperties(value); assertTrue(p.containsValue(value.toString())); assertEquals(value, mcf.getMonitorEJBServiceProperties()); } @Test public void testSetEJBServicePropertiesPollInterval() throws Exception { final Integer value = new Integer(10); Properties p = new Properties(); ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(p); mcf.setEJBServicePropertiesPollInterval(value); assertTrue(p.containsValue(value.toString())); assertEquals(value, mcf.getEJBServicePropertiesPollInterval()); } @Test public void testSetLogLevelSetsLevelOnPlugin() throws Exception { Properties props = new Properties(); ManagedConnectionFactoryImpl propsmcf = new ManagedConnectionFactoryImpl(props); final String logLevel = "DEBUG"; propsmcf.setLogLevel(logLevel); assertTrue("prop is set", props.containsValue(logLevel)); } @Test public void testGetPropsURLFromBadURL() throws Exception { try { ManagedConnectionFactoryImpl mcf = new ManagedConnectionFactoryImpl(); mcf.setEJBServicePropertiesURL("rubbish_bad:/rubbish_name.properties"); mcf.getEJBServicePropertiesURLInstance(); fail("expect an exception ."); } catch (ResourceException re) { assertTrue("Cause is MalformedURLException, cause: " + re.getCause(), re.getCause() instanceof MalformedURLException); assertTrue("Error message should contains rubbish_bad", re.getMessage().indexOf("rubbish_bad") != -1); } } @Test public void testImplementsEqualsAndHashCode() throws Exception { Method equalMethod = mci.getClass().getMethod("equals", new Class[] {Object.class}); Method hashCodeMethod = mci.getClass().getMethod("hashCode", (Class[])null); assertTrue("not Object's equals method", equalMethod != Object.class .getDeclaredMethod("equals", new Class[] {Object.class})); assertTrue("not Object's hashCode method", hashCodeMethod != Object.class .getDeclaredMethod("hashCode", (Class[])null)); assertEquals("equal with its self", mci, mci); assertTrue("not equal with another", !mci.equals(new ManagedConnectionFactoryImpl())); assertTrue("not equal with another thing", !mci.equals(this)); } @Test public void testMatchManagedConnectionsWithUnboundConnection() throws Exception { mci = new ManagedConnectionFactoryImplTester(); Object unboundMC = mci.createManagedConnection(null, null); assertNotNull("MC must not be null.", unboundMC); Set<Object> mcSet = new HashSet |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.