-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(simulator-spring-boot): indicate simulation failure with http status
- Loading branch information
Showing
38 changed files
with
697 additions
and
445 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
48 changes: 48 additions & 0 deletions
48
...ample-rest/src/main/java/org/citrusframework/simulator/sample/scenario/ThrowScenario.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,48 @@ | ||
/* | ||
* Copyright the original author or authors. | ||
* | ||
* 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 org.citrusframework.simulator.sample.scenario; | ||
|
||
import org.citrusframework.exceptions.CitrusRuntimeException; | ||
import org.citrusframework.simulator.scenario.AbstractSimulatorScenario; | ||
import org.citrusframework.simulator.scenario.Scenario; | ||
import org.citrusframework.simulator.scenario.ScenarioRunner; | ||
import org.citrusframework.simulator.scenario.SimulatorScenario; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import static org.citrusframework.actions.EchoAction.Builder.echo; | ||
|
||
/** | ||
* This scenario fails at runtime, unexpectedly. It must therefore be reported as failed {@link SimulatorScenario}. | ||
* <p> | ||
* On the other hand, if a simulation fails on purpose, see {@link FailScenario}, it must be a "successful simulation". | ||
*/ | ||
@Scenario("Throw") | ||
@RequestMapping(value = "/services/rest/simulator/throw", method = RequestMethod.GET) | ||
public class ThrowScenario extends AbstractSimulatorScenario { | ||
|
||
@Override | ||
public void run(ScenarioRunner scenario) { | ||
scenario.$(scenario.http() | ||
.receive() | ||
.get()); | ||
|
||
scenario.$(echo("Careful - I am gonna fail (:")); | ||
|
||
throw new CitrusRuntimeException("Every failure is a step to success."); | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
...in/java/org/citrusframework/simulator/endpoint/SimulationFailedUnexpectedlyException.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,41 @@ | ||
/* | ||
* Copyright the original author or authors. | ||
* | ||
* 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 org.citrusframework.simulator.endpoint; | ||
|
||
import org.citrusframework.message.DefaultMessage; | ||
|
||
/** | ||
* An implementation of a {@link org.citrusframework.message.Message} that hints that a simulation has failed. Because | ||
* of the nature of {@link java.util.concurrent.CompletableFuture<org.citrusframework.message.Message>}'s, there is no | ||
* other way than mapping the response message in case of an error. Exception-propagation from the asynchronous thread | ||
* back into the parent does not exist. | ||
* | ||
* @see SimulatorEndpointAdapter | ||
*/ | ||
public class SimulationFailedUnexpectedlyException extends DefaultMessage { | ||
|
||
public static final String EXCEPTION_TYPE = SimulationFailedUnexpectedlyException.class.getSimpleName() + ":Exception"; | ||
|
||
public SimulationFailedUnexpectedlyException(Throwable e) { | ||
super(e); | ||
} | ||
|
||
@Override | ||
public String getType() { | ||
return EXCEPTION_TYPE; | ||
} | ||
} |
Oops, something went wrong.