forked from ArcBees/GWTP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ArcBees#340 from ArcBees/spg_fixed_action_exception
Custom ActionException subclasses are not rethrown as new ActionException Former-commit-id: 0fb839e
- Loading branch information
Showing
10 changed files
with
360 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...r-guice/src/test/java/com/gwtplatform/dispatch/server/ActionExceptionThrownByHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2011 ArcBees 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.gwtplatform.dispatch.server; | ||
|
||
import com.gwtplatform.dispatch.shared.ActionException; | ||
|
||
public class ActionExceptionThrownByHandler extends ActionException { | ||
public ActionExceptionThrownByHandler(Throwable cause) { | ||
super("", cause); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...guice/src/test/java/com/gwtplatform/dispatch/server/ActionExceptionThrownByValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2011 ArcBees 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.gwtplatform.dispatch.server; | ||
|
||
import com.gwtplatform.dispatch.shared.ActionException; | ||
|
||
public class ActionExceptionThrownByValidator extends ActionException { | ||
public ActionExceptionThrownByValidator(Throwable cause) { | ||
super("", cause); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...server-guice/src/test/java/com/gwtplatform/dispatch/server/ActionThrownByHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* Copyright 2011 ArcBees 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.gwtplatform.dispatch.server; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jukito.JukitoModule; | ||
import org.jukito.JukitoRunner; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.gwtplatform.dispatch.server.guice.DispatchServiceImpl; | ||
import com.gwtplatform.dispatch.server.guice.actionvalidator.DefaultActionValidator; | ||
import com.gwtplatform.dispatch.shared.ActionException; | ||
import com.gwtplatform.dispatch.shared.ServiceException; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
|
||
@RunWith(JukitoRunner.class) | ||
public class ActionThrownByHandlerTest { | ||
public static class MyModule extends JukitoModule { | ||
@Override | ||
protected void configureTest() { | ||
install(new ServiceModule(DefaultActionValidator.class)); | ||
} | ||
} | ||
|
||
@Inject | ||
DispatchServiceImpl service; | ||
|
||
@Test | ||
public void exceptionThrownByHandlerIsNotWrappedInActionException() throws ServiceException { | ||
try { | ||
service.execute("", new SomeAction()); | ||
fail(); | ||
} catch (ActionException e) { | ||
assertThat(e, instanceOf(ActionExceptionThrownByHandler.class)); | ||
assertEquals(0, e.getStackTrace().length); | ||
assertEquals(0, e.getCause().getStackTrace().length); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...rver-guice/src/test/java/com/gwtplatform/dispatch/server/ActionThrownByValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright 2011 ArcBees 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.gwtplatform.dispatch.server; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jukito.JukitoModule; | ||
import org.jukito.JukitoRunner; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import com.gwtplatform.dispatch.server.guice.DispatchServiceImpl; | ||
import com.gwtplatform.dispatch.shared.ActionException; | ||
import com.gwtplatform.dispatch.shared.ServiceException; | ||
|
||
import static org.hamcrest.CoreMatchers.instanceOf; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
|
||
@RunWith(JukitoRunner.class) | ||
public class ActionThrownByValidatorTest { | ||
public static class MyModule extends JukitoModule { | ||
@Override | ||
protected void configureTest() { | ||
install(new ServiceModule(ActionValidatorThatThrows.class)); | ||
} | ||
} | ||
|
||
@Inject | ||
DispatchServiceImpl service; | ||
|
||
@Test | ||
public void exceptionThrownByValidatorIsNotWrappedInActionException() throws ServiceException { | ||
try { | ||
service.execute("", new SomeAction()); | ||
fail(); | ||
} catch (ActionException e) { | ||
assertThat(e, instanceOf(ActionExceptionThrownByValidator.class)); | ||
assertEquals(0, e.getStackTrace().length); | ||
assertEquals(0, e.getCause().getStackTrace().length); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...server-guice/src/test/java/com/gwtplatform/dispatch/server/ActionValidatorThatThrows.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Copyright 2011 ArcBees 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.gwtplatform.dispatch.server; | ||
|
||
import com.gwtplatform.dispatch.server.actionvalidator.ActionValidator; | ||
import com.gwtplatform.dispatch.shared.Action; | ||
import com.gwtplatform.dispatch.shared.ActionException; | ||
import com.gwtplatform.dispatch.shared.Result; | ||
|
||
public class ActionValidatorThatThrows implements ActionValidator { | ||
@Override | ||
public boolean isValid(Action<? extends Result> action) throws ActionException { | ||
throw new ActionExceptionThrownByValidator(new Exception()); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...guice/src/test/java/com/gwtplatform/dispatch/server/HandlerThatThrowsActionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright 2011 ArcBees 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.gwtplatform.dispatch.server; | ||
|
||
import javax.inject.Inject; | ||
|
||
import com.gwtplatform.dispatch.server.actionhandler.AbstractActionHandler; | ||
import com.gwtplatform.dispatch.shared.ActionException; | ||
import com.gwtplatform.dispatch.shared.NoResult; | ||
|
||
public class HandlerThatThrowsActionException extends AbstractActionHandler<SomeAction, NoResult> { | ||
@Inject | ||
HandlerThatThrowsActionException() { | ||
super(SomeAction.class); | ||
} | ||
|
||
@Override | ||
public NoResult execute(SomeAction action, ExecutionContext context) throws ActionException { | ||
throw new ActionExceptionThrownByHandler(new Exception()); | ||
} | ||
|
||
@Override | ||
public void undo(SomeAction action, NoResult result, ExecutionContext context) throws ActionException { | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...tp-dispatch-server-guice/src/test/java/com/gwtplatform/dispatch/server/ServiceModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright 2011 ArcBees 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.gwtplatform.dispatch.server; | ||
|
||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Singleton; | ||
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler; | ||
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorClass; | ||
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorMap; | ||
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorMapImpl; | ||
import com.gwtplatform.dispatch.server.actionhandlervalidator.ActionHandlerValidatorRegistry; | ||
import com.gwtplatform.dispatch.server.actionvalidator.ActionValidator; | ||
import com.gwtplatform.dispatch.server.guice.DispatchImpl; | ||
import com.gwtplatform.dispatch.server.guice.actionhandlervalidator.ActionHandlerValidatorLinker; | ||
import com.gwtplatform.dispatch.server.guice.actionhandlervalidator.LazyActionHandlerValidatorRegistryImpl; | ||
import com.gwtplatform.dispatch.shared.Action; | ||
import com.gwtplatform.dispatch.shared.Result; | ||
|
||
public class ServiceModule extends AbstractModule { | ||
private final Class<? extends ActionValidator> actionValidator; | ||
|
||
public ServiceModule(Class<? extends ActionValidator> actionValidator) { | ||
this.actionValidator = actionValidator; | ||
} | ||
|
||
@Override | ||
protected void configure() { | ||
bind(Dispatch.class).to(DispatchImpl.class); | ||
bind(ActionHandlerValidatorRegistry.class).to( | ||
LazyActionHandlerValidatorRegistryImpl.class).in(Singleton.class); | ||
|
||
bindHandler(SomeAction.class, HandlerThatThrowsActionException.class, actionValidator); | ||
requestStaticInjection(ActionHandlerValidatorLinker.class); | ||
} | ||
|
||
protected <A extends Action<R>, R extends Result> void bindHandler( | ||
Class<A> actionClass, Class<? extends ActionHandler<A, R>> handlerClass, | ||
Class<? extends ActionValidator> actionValidator) { | ||
|
||
bind(ActionHandlerValidatorMap.class).toInstance( | ||
new ActionHandlerValidatorMapImpl<A, R>(actionClass, | ||
new ActionHandlerValidatorClass<A, R>(handlerClass, actionValidator))); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
.../gwtp-dispatch-server-guice/src/test/java/com/gwtplatform/dispatch/server/SomeAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* Copyright 2011 ArcBees 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.gwtplatform.dispatch.server; | ||
|
||
import com.gwtplatform.dispatch.shared.Action; | ||
import com.gwtplatform.dispatch.shared.NoResult; | ||
|
||
public class SomeAction implements Action<NoResult> { | ||
@Override | ||
public String getServiceName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isSecured() { | ||
return false; | ||
} | ||
} |
Oops, something went wrong.