End-to-End Tests
Automated End-to-end testing to thoroughly corroborate the integrity of generated projects.
Considering the importance of a reliable testing process on the parts that constitute the XOOM Designer codegen, our team created a small library of classes and resources in order to facilitate the creation of broader test cases that, along with the usual testing approaches, readily checks the integrity of projects created from XOOM Designer. Thus, the following aspects are validated:
    Project model processing;
    Compilation;
    Initialization;
    API operations;
    Event projections;
    Schemas registration / transpilation;
In the next section, we'll understand how to run End-to-End tests and implement new ones.

Execution

End-to-end tests are part of the Designer build lifecycle, so you can execute it by calling:
1
$ mvn verify -P e2e-supporting-services
Copied!
Understanding what happens afterward, the sequence of Maven goals performed during the execution of this command is unit tests, packaging, End-to-End tests. So, in case you want to focus on the test results and skip the packaging step, add the only-tests profile:
1
$ mvn verify -P only-tests, e2e-supporting-service
Copied!
Some test cases depend on external resources (e.g. XOOM Schemata) which are meant to be up and running when tests are executed. Using e2e-supporting-service profile, these resources are automatically started via Docker. Alternatively, you can manually run these dependencies. Learn more in the Dependencies section.

Implementation

Exploring the XOOM Designer codebase, End-to-End tests are found in the src\e2e-test\ and its classes have to be under the packageio.vlingo.xoom.designer.codegen.e2e.* extendingJavaBasedProjectGenerationTest. Let's take a look at the basic structure of a test class:
1
public class BookStoreServiceGenerationTest extends JavaBasedProjectGenerationTest {
2
3
@BeforeAll
4
public static void setUp() {
5
JavaBasedProjectGenerationTest.init();
6
}
7
8
@Test
9
public void testThatServiceWithStatefulEntitiesIsWorking() {
10
//Load model
11
//Generate and run the project
12
//Assertions
13
}
14
15
@Test
16
public void testThatServiceWithSourcedEntitiesIsWorking() {
17
//Load model
18
//Generate and run the project
19
//Assertions
20
}
21
22
@AfterEach
23
public void tearDown() throws Exception {
24
JavaBasedProjectGenerationTest.clear();
25
}
26
}
Copied!
JavaBasedProjectGenerationTest.init() prepares the test environment setting the internal components required for generating a project and runs the XOOM Designer Server. Whereas, clear() basically stops the application ran in each test case. As demonstrated above, ensure that both methods are invoked respectively at the right time of the test lifecycle.
The main test input is a JSON file containing a XOOM Designer model. It should be saved under src/e2e-test/resources/sample-models/[context-name]/ . the values of deployment.httpServerPort and projectDiretory have to be updated to a replacement token (%s) for the fact that these values will be dynamically resolved during the tests. Here's an example:
1
{
2
"deployment": {
3
"httpServerPort": "%s"
4
},
5
...
6
"projectDirectory": "%s"
7
}
Copied!
In the test method, the model can be loaded by creating anio.vlingo.xoom.designer.codegen.e2e.Project object which is also used to generate the project.
1
@Test
2
public void testThatGeneratedServiceWithStatefulEntitiesIsWorking() {
3
4
//Loads the model passing the directory name and its name
5
6
final Project projectWithStatefulEntities =
7
Project.from("book-store-context", "book-store-with-stateful-entities");
8
9
super.generateAndRun(projectWithStatefulEntities);
10
11
...
12
}
Copied!
The generateAndRun method receives the Project object carrying the model settings which is submitted to the XOOM Designer API. Still, this method internally asserts that the project is properly generated. If the generation succeeds, the project will also be compiled and initialized. Otherwise, a message assertion error will be shown.
Afterward, the test statements refer to the API validation. The next code snippet gives some tips on how to perform requests and assertions:
1
@Test
2
public void testThatServiceWithSourcedEntitiesIsWorking() {
3
final Project projectWithStatefulEntities =
4
Project.from("book-store-context", "book-store-with-sourced-entities");
5
6
super.generateAndRun(projectWithStatefulEntities);
7
8
final BookData newBook = BookData.sample();
9
10
final Response response =
11
super.apiOf(bookStoreProject).body(newBook).post("/books");
12
13
final BookData responseBody =
14
response.then().extract().body().as(BookData.class);
15
16
Assertions.assertEquals(Status.Created.code, response.statusCode(), "Wrong http status while creating book " + bookStoreProject);
17
Assertions.assertEquals(newBook, responseBody, "Wrong response while creating book " + bookStoreProject);
18
}
Copied!
Other assertions should be added in order to make a meticulous verification of the project's consistency. It's also strongly recommended that each test method are commented on regarding the XOOM Designer model details.
1
/**
2
* Test that the service is generated and working with:
3
* - Stateful Entities containing only scalar-typed fields
4
* - Operation-based projection
5
* - Xoom Annotations + Auto-dispatch
6
*/
7
@Test
8
public void testThatServiceWithStatefulEntitiesIsWorking() {
9
10
...
11
}
Copied!
See the full code used in this example here.

Dependencies

Whenever a XOOM Designer model is configured to produce or consume events, the generated project will depend on XOOM Schemata and XOOM Lattice/Exchange (RabbitMQ). Therefore, the installation, initialization, and closing of these resources are part of the End-to-End testing routine. The quickest way to handle this external resources management on a local environment is to use the e2e-supporting-services profile.
1
$ mvn verify -P e2e-supporting-services
Copied!
The End-to-End test cases require that XOOM Schemata and RabbitMQ are respectively available on port 9019 and 5672. Ensure that these ports are not in use before activating the e2e-supporting-services profile.
Then, call SupportingServicesManager.run() before the test cases are executed:
1
public class CargoShippingServicesGenerationTest extends JavaBasedProjectGenerationTest {
2
3
@BeforeAll
4
public static void setUp() {
5
SupportingServicesManager.run();
6
JavaBasedProjectGenerationTest.init();
7
}
8
...
9
}
Copied!
The first statements of a test method that generates a project that has dependencies are meant to assert that the external resources are available:
1
@Test
2
public void testThatGeneratedServicesAreWorking() {
3
super.assertServiceIsAvailable(SupportingServicesManager.findPortOf(SCHEMATA), "Schemata service is not available");
4
super.assertServiceIsAvailable(SupportingServicesManager.findPortOf(RABBIT_MQ), "RabbitMQ service is not available");
5
6
//Generate the project
7
}
Copied!
The SupportingServicesManager automatically shut down the managed services when the test cases execution is done.

Constraints

Following the classical test pyramid concept that states that "the more high-level you get the fewer tests you should have", we should not have several End-to-End test cases once they are slower and hard to maintain. Rather, a small set of test cases that cover a number of corner cases and complex scenarios is the best goal.
Due to the complexity of covering user-interface functionalities on automated testing, the implementation of End-to-End tests on XOOM Designer does not validate the XOOM Designer UI. Also, when a XOOM Designer model has an embedded ReactJS app, the generated frontend code is not syntactically checked, taking into account that this additional validation would imply resolving the framework dependencies increasing significantly the time consumed on each test.
Last modified 21d ago