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: */
019: package org.apache.axis2.jaxws.injection;
020:
021: import javax.xml.ws.WebServiceContext;
022:
023: import junit.framework.TestCase;
024: import org.apache.axis2.jaxws.context.WebServiceContextImpl;
025: import org.apache.axis2.jaxws.resourceinjection.sei.ResourceInjectionPortType;
026: import org.apache.axis2.jaxws.resourceinjection.sei.ResourceInjectionService;
027: import org.apache.axis2.jaxws.server.endpoint.injection.ResourceInjector;
028: import org.apache.axis2.jaxws.server.endpoint.injection.factory.ResourceInjectionFactory;
029: import org.apache.axis2.jaxws.TestLogger;
030:
031: public class ResourceInjectionTests extends TestCase {
032:
033: private Object resource = new WebServiceContextImpl();
034:
035: public ResourceInjectionTests() {
036: super ();
037: // TODO Auto-generated constructor stub
038: }
039:
040: public void testInjectionOnField() {
041: Object serviceInstance = new ResourceInjectionTestImpl1();
042: TestLogger.logger.debug("------------------------------");
043: TestLogger.logger.debug("Test : " + getName());
044: try {
045: ResourceInjector injector = ResourceInjectionFactory
046: .createResourceInjector(WebServiceContext.class);
047: injector.inject(resource, serviceInstance);
048: ResourceInjectionTestImpl1 serviceImpl = (ResourceInjectionTestImpl1) serviceInstance;
049: assertNotNull(serviceImpl.ctx);
050: TestLogger.logger.debug("Resource Injected on Field");
051: TestLogger.logger.debug("------------------------------");
052: } catch (Exception e) {
053: e.printStackTrace();
054: fail();
055: }
056: }
057:
058: public void testInjectionOnMethod() {
059: Object serviceInstance = new ResourceInjectionTestImpl2();
060: TestLogger.logger.debug("------------------------------");
061: TestLogger.logger.debug("Test : " + getName());
062: try {
063: ResourceInjector injector = ResourceInjectionFactory
064: .createResourceInjector(WebServiceContext.class);
065: injector.inject(resource, serviceInstance);
066: ResourceInjectionTestImpl2 serviceImpl = (ResourceInjectionTestImpl2) serviceInstance;
067: assertNotNull(serviceImpl.ctx);
068: TestLogger.logger.debug("Resource Injected on Method");
069: TestLogger.logger.debug("------------------------------");
070: } catch (Exception e) {
071: e.printStackTrace();
072: fail();
073: }
074: }
075:
076: public void testInjectionOnPrivateField() {
077: Object serviceInstance = new ResourceInjectionTestImpl3();
078: TestLogger.logger.debug("------------------------------");
079: TestLogger.logger.debug("Test : " + getName());
080: try {
081: ResourceInjector injector = ResourceInjectionFactory
082: .createResourceInjector(WebServiceContext.class);
083: injector.inject(resource, serviceInstance);
084: ResourceInjectionTestImpl3 serviceImpl = (ResourceInjectionTestImpl3) serviceInstance;
085: assertNotNull(serviceImpl.getCtx());
086: TestLogger.logger
087: .debug("Resource Injected on Private Field");
088: TestLogger.logger.debug("------------------------------");
089: } catch (Exception e) {
090: e.printStackTrace();
091: fail();
092: }
093: }
094:
095: public void testInjectionOnProvateMethod() {
096: Object serviceInstance = new ResourceInjectionTestImpl4();
097: TestLogger.logger.debug("------------------------------");
098: TestLogger.logger.debug("Test : " + getName());
099: try {
100: ResourceInjector injector = ResourceInjectionFactory
101: .createResourceInjector(WebServiceContext.class);
102: injector.inject(resource, serviceInstance);
103: ResourceInjectionTestImpl4 serviceImpl = (ResourceInjectionTestImpl4) serviceInstance;
104: assertNotNull(serviceImpl.getCtx());
105: TestLogger.logger
106: .debug("Resource Injected using private Method");
107: TestLogger.logger.debug("------------------------------");
108: } catch (Exception e) {
109: e.printStackTrace();
110: fail();
111: }
112: }
113:
114: public void testTypedResourceInjectionOnField() {
115: Object serviceInstance = new ResourceInjectionTestImpl5();
116: TestLogger.logger.debug("------------------------------");
117: TestLogger.logger.debug("Test : " + getName());
118: try {
119: ResourceInjector injector = ResourceInjectionFactory
120: .createResourceInjector(WebServiceContext.class);
121: injector.inject(resource, serviceInstance);
122: ResourceInjectionTestImpl5 serviceImpl = (ResourceInjectionTestImpl5) serviceInstance;
123: assertNotNull(serviceImpl.ctx);
124: TestLogger.logger.debug("Resource Injected on Field");
125: TestLogger.logger.debug("------------------------------");
126: } catch (Exception e) {
127: e.printStackTrace();
128: fail();
129: }
130: }
131:
132: public void testEchoWithResourceInjectionAndLifecycleMethods() {
133: TestLogger.logger.debug("------------------------------");
134: TestLogger.logger.debug("Test : " + getName());
135: try {
136: ResourceInjectionService service = new ResourceInjectionService();
137: ResourceInjectionPortType proxy = service
138: .getResourceInjectionPort();
139: String response = proxy.echo("echo Request");
140: TestLogger.logger.debug("Response String = " + response);
141: TestLogger.logger.debug("------------------------------");
142: } catch (Exception e) {
143: e.printStackTrace();
144: fail();
145: }
146: }
147:
148: }
|