Revision: 9860
Author: [email protected]
Date: Wed Mar 16 12:12:36 2011
Log: Rolling back ServiceInheritanceTest to make it GWT safe so can run in
RequestFactorySuite also
Review at http://gwt-code-reviews.appspot.com/1384802
http://code.google.com/p/google-web-toolkit/source/detail?r=9860
Deleted:
/trunk/user/test/com/google/gwt/requestfactory/server/ServiceInheritanceJreTest.java
/trunk/user/test/com/google/gwt/requestfactory/shared/ServiceInheritanceTest.java
Modified:
/trunk/user/src/com/google/gwt/requestfactory/server/LocatorServiceLayer.java
/trunk/user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
/trunk/user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
/trunk/user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
/trunk/user/test/com/google/gwt/requestfactory/RequestFactoryJreSuite.java
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/server/ServiceInheritanceJreTest.java
Wed Mar 16 07:05:51 2011
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed 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 com.google.gwt.requestfactory.server;
-
-import com.google.gwt.requestfactory.shared.ServiceInheritanceTest;
-
-/**
- * A JRE version of {@link ServiceInheritanceTest}.
- */
-public class ServiceInheritanceJreTest extends ServiceInheritanceTest {
- @Override
- public String getModuleName() {
- return null;
- }
-
- @Override
- protected Factory createFactory() {
- return RequestFactoryJreTest.createInProcess(Factory.class);
- }
-}
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/shared/ServiceInheritanceTest.java
Wed Mar 16 07:05:51 2011
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright 2011 Google Inc.
- *
- * Licensed 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 com.google.gwt.requestfactory.shared;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.event.shared.SimpleEventBus;
-import com.google.gwt.junit.client.GWTTestCase;
-
-/**
- * Tests the ability of instance services to inherit methods
- * from a base class.
- */
-public class ServiceInheritanceTest extends GWTTestCase {
-
- /**
- * Generic locator returns an instance of the class named in
- * the @{@link Service} annotation
- */
- public static class AnyServiceLocator implements ServiceLocator {
-
- @Override
- public Object getInstance(Class<?> clazz) {
- assertTrue(BaseImpl.class.isAssignableFrom(clazz));
- try {
- return clazz.newInstance();
- } catch (InstantiationException e) {
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- /**
- * The factory under test.
- */
- protected interface Factory extends RequestFactory {
- SumService sumContext();
- SumServiceBase sumBaseContext();
- }
-
- /**
- * Specifies a service which extends a base class
- */
- @Service(value = SubclassImpl.class, locator = AnyServiceLocator.class)
- interface SumService extends RequestContext {
- Request<Integer> add(int n);
- }
-
- /**
- * Specifies a service which is a base class
- */
- @Service(value = BaseImpl.class, locator = AnyServiceLocator.class)
- interface SumServiceBase extends RequestContext {
- Request<Integer> add(int n);
- }
-
- static class BaseImpl {
- protected int base;
-
- public BaseImpl() {
- base = 5;
- }
-
- public Integer add(int n) {
- return base + n;
- }
- }
-
- static class SubclassImpl extends BaseImpl {
- public SubclassImpl() {
- // Distinguish from base service
- base = 8;
- }
- }
-
- private static final int TEST_DELAY = 5000;
-
- private Factory factory;
-
- @Override
- public String getModuleName() {
- return "com.google.gwt.requestfactory.RequestFactorySuite";
- }
-
- /**
- * Verify that the method can be invoked on the base class
- * as well as the subclass
- */
- public void testInvokeMethodOnBaseClass() {
- delayTestFinish(TEST_DELAY);
- factory.sumBaseContext().add(13).fire(new Receiver<Integer>() {
- @Override
- public void onSuccess(Integer response) {
- assertEquals((Integer) 18, response);
- finishTest();
- }
- });
- }
-
- /**
- * Verify that the method is invoked on the subclass,
- * not the base class
- */
- public void testInvokeMethodOnSubclass() {
- delayTestFinish(TEST_DELAY);
- factory.sumContext().add(13).fire(new Receiver<Integer>() {
- @Override
- public void onSuccess(Integer response) {
- assertEquals((Integer) 21, response);
- finishTest();
- }
- });
- }
-
- protected Factory createFactory() {
- Factory toReturn = GWT.create(Factory.class);
- toReturn.initialize(new SimpleEventBus());
- return toReturn;
- }
-
- @Override
- protected void gwtSetUp() throws Exception {
- factory = createFactory();
- }
-
-}
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/server/LocatorServiceLayer.java
Wed Mar 16 07:05:51 2011
+++
/trunk/user/src/com/google/gwt/requestfactory/server/LocatorServiceLayer.java
Wed Mar 16 12:12:36 2011
@@ -20,7 +20,6 @@
import com.google.gwt.requestfactory.shared.ProxyFor;
import com.google.gwt.requestfactory.shared.ProxyForName;
import com.google.gwt.requestfactory.shared.Request;
-import com.google.gwt.requestfactory.shared.RequestContext;
import com.google.gwt.requestfactory.shared.Service;
import com.google.gwt.requestfactory.shared.ServiceLocator;
import com.google.gwt.requestfactory.shared.ServiceName;
@@ -53,11 +52,7 @@
Class<? extends ServiceLocator> locatorType =
getTop().resolveServiceLocator(contextMethod, domainMethod);
ServiceLocator locator = newInstance(locatorType,
ServiceLocator.class);
- // Enclosing class may be a parent class, so invoke on service class
- Class<?> declaringClass = contextMethod.getDeclaringClass();
- Class<?> serviceClass =
- getTop().resolveServiceClass((Class<? extends RequestContext>)
declaringClass);
- return locator.getInstance(serviceClass);
+ return locator.getInstance(domainMethod.getDeclaringClass());
}
@Override
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
Wed Mar 16 07:05:51 2011
+++
/trunk/user/src/com/google/gwt/requestfactory/server/ResolverServiceLayer.java
Wed Mar 16 12:12:36 2011
@@ -117,9 +117,22 @@
@Override
public Method resolveDomainMethod(Method requestContextMethod) {
- Class<?> declaringClass = requestContextMethod.getDeclaringClass();
- Class<?> searchIn =
- getTop().resolveServiceClass((Class<? extends RequestContext>)
declaringClass);
+ Class<?> enclosing = requestContextMethod.getDeclaringClass();
+
+ Class<?> searchIn = null;
+ Service s = enclosing.getAnnotation(Service.class);
+ if (s != null) {
+ searchIn = s.value();
+ }
+ ServiceName sn = enclosing.getAnnotation(ServiceName.class);
+ if (sn != null) {
+ searchIn = forName(sn.value());
+ }
+ if (searchIn == null) {
+ die(null, "The %s type %s did not specify a service type",
RequestContext.class
+ .getSimpleName(), enclosing.getCanonicalName());
+ }
+
Class<?>[] parameterTypes = requestContextMethod.getParameterTypes();
Class<?>[] domainArgs = new Class<?>[parameterTypes.length];
for (int i = 0, j = domainArgs.length; i < j; i++) {
@@ -164,25 +177,6 @@
return report("Could not locate %s method %s::%s",
RequestContext.class.getSimpleName(),
requestContextClass, methodName);
}
-
- @Override
- public Class<?> resolveServiceClass(Class<? extends RequestContext>
requestContextClass) {
- Class<?> searchIn = null;
- Service s = requestContextClass.getAnnotation(Service.class);
- // TODO Handle case when both annotations are present
- if (s != null) {
- searchIn = s.value();
- }
- ServiceName sn = requestContextClass.getAnnotation(ServiceName.class);
- if (sn != null) {
- searchIn = forName(sn.value());
- }
- if (searchIn == null) {
- die(null, "The %s type %s did not specify a service type",
RequestContext.class
- .getSimpleName(), requestContextClass.getCanonicalName());
- }
- return searchIn;
- }
@Override
public String resolveTypeToken(Class<? extends BaseProxy> clazz) {
=======================================
--- /trunk/user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
Wed Mar 16 07:05:51 2011
+++ /trunk/user/src/com/google/gwt/requestfactory/server/ServiceLayer.java
Wed Mar 16 12:12:36 2011
@@ -17,7 +17,6 @@
import com.google.gwt.requestfactory.shared.BaseProxy;
import com.google.gwt.requestfactory.shared.Locator;
-import com.google.gwt.requestfactory.shared.RequestContext;
import com.google.gwt.requestfactory.shared.ServiceLocator;
import java.lang.reflect.Method;
@@ -333,15 +332,6 @@
*/
public abstract Method resolveRequestContextMethod(String
requestContextClass, String methodName);
- /**
- * Given a {@link RequestContext} method, find the service class
referenced in
- * the {@link Service} or {@link ServiceName} annotation.
- *
- * @param requestContextClass a RequestContext interface
- * @return the type of service to use
- */
- public abstract Class<?> resolveServiceClass(Class<? extends
RequestContext> requestContextClass);
-
/**
* Given a RequestContext method declaration, resolve the
* {@link ServiceLocator} that should be used when invoking the domain
method.
=======================================
---
/trunk/user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
Wed Mar 16 07:05:51 2011
+++
/trunk/user/src/com/google/gwt/requestfactory/server/ServiceLayerDecorator.java
Wed Mar 16 12:12:36 2011
@@ -17,7 +17,6 @@
import com.google.gwt.requestfactory.shared.BaseProxy;
import com.google.gwt.requestfactory.shared.Locator;
-import com.google.gwt.requestfactory.shared.RequestContext;
import com.google.gwt.requestfactory.shared.ServiceLocator;
import java.lang.reflect.InvocationTargetException;
@@ -155,11 +154,6 @@
public Method resolveRequestContextMethod(String requestContextClass,
String methodName) {
return getNext().resolveRequestContextMethod(requestContextClass,
methodName);
}
-
- @Override
- public Class<?> resolveServiceClass(Class<? extends RequestContext>
requestContextClass) {
- return getNext().resolveServiceClass(requestContextClass);
- }
@Override
public Class<? extends ServiceLocator> resolveServiceLocator(Method
contextMethod,
=======================================
---
/trunk/user/test/com/google/gwt/requestfactory/RequestFactoryJreSuite.java
Wed Mar 16 07:05:51 2011
+++
/trunk/user/test/com/google/gwt/requestfactory/RequestFactoryJreSuite.java
Wed Mar 16 12:12:36 2011
@@ -24,7 +24,6 @@
import
com.google.gwt.requestfactory.server.RequestFactoryInterfaceValidatorTest;
import com.google.gwt.requestfactory.server.RequestFactoryJreTest;
import
com.google.gwt.requestfactory.server.RequestFactoryUnicodeEscapingJreTest;
-import com.google.gwt.requestfactory.server.ServiceInheritanceJreTest;
import com.google.gwt.requestfactory.shared.impl.SimpleEntityProxyIdTest;
import junit.framework.Test;
@@ -51,7 +50,6 @@
suite.addTestSuite(RequestFactoryJreTest.class);
suite.addTestSuite(RequestFactoryModelTest.class);
suite.addTestSuite(RequestFactoryUnicodeEscapingJreTest.class);
- suite.addTestSuite(ServiceInheritanceJreTest.class);
suite.addTestSuite(SimpleEntityProxyIdTest.class);
return suite;
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors