Skip to content

Commit

Permalink
fix: remove duplicate database schema entries
Browse files Browse the repository at this point in the history
  • Loading branch information
bbortt committed May 8, 2024
1 parent f93073f commit ffa8c29
Show file tree
Hide file tree
Showing 59 changed files with 1,105 additions and 574 deletions.
75 changes: 75 additions & 0 deletions simulator-docs/src/main/asciidoc/images/database-schema.plantuml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@startuml

!theme vibrant
top to bottom direction
skinparam linetype ortho

class message {
direction: integer
created_date: timestamp(6) with time zone
last_modified_date: timestamp(6) with time zone
scenario_execution_execution_id: bigint
citrus_message_id: varchar(255)
payload: text
message_id: bigint
}
class message_header {
created_date: timestamp(6) with time zone
last_modified_date: timestamp(6) with time zone
message_id: bigint
header_value: varchar(255)
name: varchar(255)
header_id: bigint
}
class scenario_action {
end_date: timestamp(6) with time zone
scenario_execution_execution_id: bigint
start_date: timestamp(6) with time zone
name: varchar(255)
action_id: bigint
}
class scenario_execution {
end_date: timestamp(6) with time zone
start_date: timestamp(6) with time zone
test_result_id: bigint
scenario_name: varchar(255)
execution_id: bigint
}
class scenario_parameter {
control_type: integer
required: boolean
created_date: timestamp(6) with time zone
last_modified_date: timestamp(6) with time zone
scenario_execution_execution_id: bigint
label: varchar(255)
name: varchar(255)
parameter_value: text
parameter_id: bigint
}
class test_parameter {
created_date: timestamp(6) with time zone
last_modified_date: timestamp(6) with time zone
parameter_value: varchar(255)
test_result_id: bigint
parameter_key: varchar(255)
}
class test_result {
status: integer
created_date: timestamp(6) with time zone
last_modified_date: timestamp(6) with time zone
class_name: varchar(255)
failure_type: varchar(255)
test_name: varchar(255)
error_message: text
stack_trace: text
id: bigint
}

message -[#595959,plain]-^ scenario_execution : "scenario_execution_execution_id:execution_id"
message_header -[#595959,plain]-^ message : "message_id"
scenario_action -[#595959,plain]-^ scenario_execution : "scenario_execution_execution_id:execution_id"
scenario_execution -[#595959,plain]-^ test_result : "test_result_id:id"
scenario_parameter -[#595959,plain]-^ scenario_execution : "scenario_execution_execution_id:execution_id"
test_parameter -[#595959,plain]-^ test_result : "test_result_id:id"

@enduml
Binary file modified simulator-docs/src/main/asciidoc/images/database-schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2006-2017 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 static org.citrusframework.actions.EchoAction.Builder.echo;
import static org.citrusframework.actions.FailAction.Builder.fail;
import static org.citrusframework.dsl.MessageSupport.MessageBodySupport.fromBody;

import org.citrusframework.simulator.scenario.AbstractSimulatorScenario;
import org.citrusframework.simulator.scenario.Scenario;
import org.citrusframework.simulator.scenario.ScenarioRunner;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
* @author Christoph Deppisch
*/
@Scenario("Fail")
@RequestMapping(value = "/services/rest/simulator/fail", method = RequestMethod.POST)
public class FailScenario extends AbstractSimulatorScenario {

@Override
public void run(ScenarioRunner scenario) {
scenario.$(scenario.http()
.receive()
.post()
.message()
.body("<Failure xmlns=\"http://citrusframework.org/schemas/failure\">" +
"Fail!" +
"</Failure>"));

scenario.$(echo("Careful - I am gonna fail successfully (:"));

scenario.$(fail("It is the courage to continue that counts."));
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:citrus="http://www.citrusframework.org/schema/config"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:citrus="http://www.citrusframework.org/schema/config"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.citrusframework.org/schema/config http://www.citrusframework.org/schema/config/citrus-config.xsd">

<citrus:schema-repository id="schemaRepository">
<citrus:locations>
<citrus:location path="classpath:xsd/HelloService.xsd"/>
</citrus:locations>
<citrus:locations>
<citrus:location path="classpath:xsd/HelloService.xsd"/>
<citrus:location path="classpath:xsd/FailureService.xsd"/>
</citrus:locations>
</citrus:schema-repository>

<citrus:global-variables>
Expand All @@ -17,7 +18,7 @@

<citrus:namespace-context>
<citrus:namespace prefix="citrus" uri="http://citrusframework.org"/>
<citrus:namespace prefix="hello" uri="http://citrusframework.org/schemas/hello"/>
<citrus:namespace prefix="hello" uri="http://citrusframework.org/schemas/hello"/>
<citrus:namespace prefix="failure" uri="http://citrusframework.org/schemas/failure"/>
</citrus:namespace-context>

</beans>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2006-2017 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.
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://citrusframework.org/schemas/failure"
targetNamespace="http://citrusframework.org/schemas/failure"
elementFormDefault="qualified">

<xs:element name="Failure" type="xs:string"/>
</xs:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,16 @@
-->

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://citrusframework.org/schemas/hello"
targetNamespace="http://citrusframework.org/schemas/hello"
elementFormDefault="qualified"
attributeFormDefault="unqualified">
xmlns="http://citrusframework.org/schemas/hello"
targetNamespace="http://citrusframework.org/schemas/hello"
elementFormDefault="qualified">

<xs:element name="Hello" type="xs:string"/>
<xs:element name="HelloResponse" type="xs:string"/>
<xs:element name="Hello" type="xs:string"/>
<xs:element name="HelloResponse" type="xs:string"/>

<xs:element name="GoodBye" type="xs:string"/>
<xs:element name="GoodByeResponse" type="xs:string"/>
<xs:element name="GoodBye" type="xs:string"/>
<xs:element name="GoodByeResponse" type="xs:string"/>

<xs:element name="GoodNight" type="xs:string"/>
<xs:element name="GoodNightResponse" type="xs:string"/>
<xs:element name="GoodNight" type="xs:string"/>
<xs:element name="GoodNightResponse" type="xs:string"/>
</xs:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.springframework.test.context.ContextConfiguration;
import org.testng.annotations.Test;

import java.util.List;

import static org.citrusframework.actions.SleepAction.Builder.sleep;
import static org.citrusframework.http.actions.HttpActionBuilder.http;

Expand Down Expand Up @@ -224,14 +226,38 @@ public void testInterveningRequest() {
.body(defaultResponse));
}

/**
* Sends a request to the server expecting it to purposefully fail a simulation.
*/
@CitrusTest
public void testFailingSimulation() {
$(http().client(simulatorClient)
.send()
.post("fail")
.message()
.contentType(MediaType.APPLICATION_XML_VALUE)
.body("<Failure xmlns=\"http://citrusframework.org/schemas/failure\">" +
"Fail!" +
"</Failure>"));

$(http().client(simulatorClient)
.receive()
.response(HttpStatus.OK)); // TODO: Pretty sure this should be HttpStatus.INTERNAL_SERVER_ERROR
}

@Configuration
@PropertySource("classpath:application.properties")
public static class EndpointConfig {

@Bean
public XsdSchemaRepository schemaRepository() {
XsdSchemaRepository schemaRepository = new XsdSchemaRepository();
schemaRepository.getLocations().add("classpath:xsd/HelloService.xsd");
schemaRepository.getLocations()
.addAll(
List.of(
"classpath:xsd/HelloService.xsd",
"classpath:xsd/FailureService.xsd"
));
return schemaRepository;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.citrusframework.report.TestActionListener;
import org.citrusframework.simulator.service.ScenarioActionService;
import org.citrusframework.simulator.service.ScenarioExecutionService;
import org.citrusframework.simulator.service.TestResultService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand All @@ -38,6 +37,7 @@

import static org.citrusframework.TestResult.failed;
import static org.citrusframework.TestResult.success;
import static org.citrusframework.simulator.service.TestCaseUtil.getScenarioExecutionId;
import static org.citrusframework.util.StringUtils.hasText;
import static org.springframework.util.StringUtils.arrayToCommaDelimitedString;

Expand All @@ -62,12 +62,9 @@ public class SimulatorStatusListener extends AbstractTestListener implements Tes
private final ScenarioActionService scenarioActionService;
private final ScenarioExecutionService scenarioExecutionService;

private final TestResultService testResultService;

public SimulatorStatusListener(ScenarioActionService scenarioActionService, ScenarioExecutionService scenarioExecutionService, TestResultService testResultService) {
public SimulatorStatusListener(ScenarioActionService scenarioActionService, ScenarioExecutionService scenarioExecutionService) {
this.scenarioActionService = scenarioActionService;
this.scenarioExecutionService = scenarioExecutionService;
this.testResultService = testResultService;
}

@Override
Expand All @@ -85,45 +82,42 @@ public void onTestFinish(TestCase test) {
}

@Override
public void onTestSuccess(TestCase test) {
TestResult result;
if (test instanceof DefaultTestCase defaultTestCase) {
result = success(test.getName(), test.getTestClass().getSimpleName(), defaultTestCase.getParameters());
public void onTestSuccess(TestCase testCase) {
TestResult testResult;
if (testCase instanceof DefaultTestCase defaultTestCase) {
testResult = success(testCase.getName(), testCase.getTestClass().getSimpleName(), defaultTestCase.getParameters());
} else {
result = success(test.getName(), test.getTestClass().getSimpleName());
testResult = success(testCase.getName(), testCase.getTestClass().getSimpleName());
}

testResultService.transformAndSave(result);
scenarioExecutionService.completeScenarioExecutionSuccess(test);
scenarioExecutionService.completeScenarioExecution(getScenarioExecutionId(testCase), new org.citrusframework.simulator.model.TestResult(testResult));

logger.info(result.toString());
logger.info("Test succeeded: {}", testResult);
}

@Override
public void onTestFailure(TestCase test, Throwable cause) {
TestResult result;
if (test instanceof DefaultTestCase defaultTestCase) {
result = failed(test.getName(), test.getTestClass().getSimpleName(), cause, defaultTestCase.getParameters());
public void onTestFailure(TestCase testCase, Throwable cause) {
TestResult testResult;
if (testCase instanceof DefaultTestCase defaultTestCase) {
testResult = failed(testCase.getName(), testCase.getTestClass().getSimpleName(), cause, defaultTestCase.getParameters());
} else {
result = failed(test.getName(), test.getTestClass().getSimpleName(), cause);
testResult = failed(testCase.getName(), testCase.getTestClass().getSimpleName(), cause);
}

testResultService.transformAndSave(result);
scenarioExecutionService.completeScenarioExecutionFailure(test, cause);
scenarioExecutionService.completeScenarioExecution(getScenarioExecutionId(testCase), new org.citrusframework.simulator.model.TestResult(testResult));

logger.info(result.toString());
logger.info(result.getFailureType());
logger.info("Test failed: {}", testResult);
}

@Override
public void onTestActionStart(TestCase testCase, TestAction testAction) {
if (!ignoreTestAction(testAction)) {
if (logger.isDebugEnabled()) {
logger.debug(testCase.getName() + "(" +
arrayToCommaDelimitedString(getParameters(testCase)) + ") - " +
testAction.getName() +
(testAction instanceof Described described && hasText(described.getDescription()) ? ": " + described.getDescription() : ""));
}
logger.debug("{} ({}) - {}{}",
testCase.getName(),
arrayToCommaDelimitedString(getParameters(testCase)),
testAction.getName(),
(testAction instanceof Described described && hasText(described.getDescription()) ? ": " + described.getDescription() : "")
);

scenarioActionService.createForScenarioExecutionAndSave(testCase, testAction);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class Message extends AbstractAuditingEntity<Message, Long> implements Se
private Integer direction = Direction.UNKNOWN.getId();

@Lob
@Column(columnDefinition = "CLOB", updatable = false)
@Column(columnDefinition = "TEXT", updatable = false)
private String payload;

@NotEmpty
Expand Down
Loading

0 comments on commit ffa8c29

Please sign in to comment.