Application Modeling and Code Generation using EFSM — ATM in StateForge Tutorial

Application Modeling and Code Generation using EFSM — ATM in StateForge TutorialArnold HigyedBlockedUnblockFollowFollowingMay 30The purpose of this writing is to present to you how to describe a model, which in our case is an ATM, and how to generate code using StateForge in order to obtain an application with time constraints (which supposes an asynchronous system).

So let’s get started :DBelow is a simple HelloWorld model in StateForge:State Machine Diagram EditorThe state machine diagram editor is a software tool to visualize and edit state machines.

www.

stateforge.

comAboutTime constraints can be modeled by using EFSM (Extended Finite State Machine).

EFSM incorporates the action of setting a timer, firing and handling an event and performing transitions to other states.

StateBuilderJava is used as state machine code generator for the proposed model.

The framework transforms a state model description into an extended version of the state pattern in Java.

The model is written in a simple XML format, which is both human readable and writable.

The state diagram editor helps to visualize and edit a state machine description.

ATM Application modelFirst, configure a java maven project in an IDE of your choice.

I used IntelliJ, but you can pick whatever tool suits your work better.

After you have an empty project, configure the pom with the following dependencies and build steps:StateForge and testing dependenciesThe first dependency is from StateForge since we will generate a big part of our application.

The other two are for testing (<scope>test</scope>).

Don’t worry, if you get stuck at any part of this brief introduction, I will provide my GitHub repo at the bottom.

Compiler and StateForge pluginThe second plugin is responsible for the code generation during the build process.

And finally, the plugins to create an executable jar and to copy all dependencies.

So after the project setup, we can go on the StateForge website, ignoring the desktop application, which has an expiring license, and we can design our model.

You will see, the web application is very lightweight and suggestive.

You will get used to it in no time.

Give yourself time, and explore a little bit around.

As about my project, this is my final state diagram captured by the online tool:ATM state diagramI know it’s a little bit hard to read, but you will find it on my GitHub repo.

So when you finalized your model, go to the xml section and copy all the code and paste it here:Just make sure that the build step, the generator plugin will see this path.

Also good to note: if your application is dependent on other entities, make sure you implement them in the same package in which the code will be generated in the target file.

In my case, for my BZL, meaning business logic, I needed an ATM, a BankAccount, a Card, a Pin and a Main to run the application.

I accept critics since I don’t think my application is the best in the meanings of implementation, but it serves well for a small introductory project.

Again, feel free to explore my repo or to clone it and to run the entire “THING”.

Don’t be afraid, it won’t crash your computer… for the moment :)).

TestingIn order to validate the generated model and the behavior of the application as a whole, I used Cucumber framework to test in a BDD, Behavior Driven Development style.

You will see, to begin with, this framework is a little bit messy, since the files are split up in three different locations and for the first impression you won’t even know how to run it, but check out a short Cucumber tutorial and come back to try them out.

Getting deeper into testing, I have found it really easy and friendly the way how you could structure the test architecture.

I got to the point, where someone with no information at all could easily add another scenario.

Just look how nice it looks:Cucumber feature fileYou will see, it’s hard work at the beginning, but worth it in the end.

It leaves a good impression and it’s easy to understand.

ConclusionsSo finally, my conclusions are that StateForge is a very useful and lightweight tool.

The development process is fast and flexible, having a tool suggestive enough to capture all its features.

The realized ATM model behaves as described in the end.

The generation was successful and the testing process was essential since it invalidated some of the erroneous conditions described in the model.

Testing the time constraints was not granular, it was based on seconds and all were respected in this context.

In the end, we have a project that incorporates all development processes, from design to implementation, testing and build.

Feel free to explore, run and code young padawans of this vast galaxy!.Cheers!HigyedArnold/RTSDReal Time System Design – MSE 2018.

Contribute to HigyedArnold/RTSD development by creating an account on GitHub.

github.

comCritics and appreciations are more than welcome.

I am open to discuss and to improve.

May the code be with you, always!.. More details

Leave a Reply