How to Build an Application - Maes95/TFG-WebChat GitHub Wiki
How to build an application
What are the requirements for an application to be tested?
The application in question must be able to support a chat in which several users can communicate with each other.
Requires launching the application as a server listening at port and offering a WebSocket connection on the /chat
address.
First conexion
When the client establishing the connection, will send his data in a string, that can be formatted to JSON and has the following structure:
{
"name": "MyName",
"chat": "MyRoom"
}
The application must store this data with the websocket connection so that they are "registered".
Message Management
Once the connection has been established and the initialization message has been sent, the client will send messages to the application, again as a String, which can be formatted to a JSON with the following structure:
{
"name": "MyName",
"chat": "MyRoom",
"message":"MyMessage"
}
This message must be forwarded by the application to all users whose chat room is the same as the message.
IMPORTANT: Do not confuse a chat message with a connection message, the way to differentiate them is by the existence or not of the "message"
key in the JSON.
Disconnection
The application must manage the disconnection of users. When a user disconnects, it must be removed from the application so that messages are not forwarded to it.
Optional
Although the tests are not required it, the application can prevent two users with the same name can connect (regardless of the chat to which they belong). In case it already exists the user should send a message back to the client as shown below:
{
"type": "system",
"message": "A user with that name already exists"
}
In addition, and in order to quickly test the correct operation of the application, you can offer an Http client that allows the connection from the browser. The template of this client can be found here
How do I include an application in a comparison?
WebChatTest contains a configuration file available in WebChatTest/src/main/resources/config.json
looking like this:
{
"apps" : [
{
"name" : "NodeJS",
"commands" : "node app.js",
"port" : 8080,
},
{
"name" : "Vert.x",
"address" : "192.168.1.45",
"port" : 5000,
}
],
"chats": [
{
"numChats": 1,
"users": [10, 20, 30, 40, 50, 60]
}
]
}
Our application will be included as a new object to "apps", whose format is defined in the following table:
Property | Type | Required | Default | Explanation |
---|---|---|---|---|
name | String | Si | - | Name of application |
globalDefinition | String | No | No definition provided | Definition of technology |
specificDefinition | String | No | - | Specific definition of application |
commands | String | No | - | Command/s which launch the app |
port | Number | No | 9000 | Port on which the application listens |
folderName | String | No | name+"-WebChat" | Name of the folder where the application is located |
address | String | No | 127.0.0.0 | IP address of the application host |
delay | Number | No | 10000 | Time (in ms) that is expected to start the application |
remote | Boolean | No | false | If the machine runs on remote |
pid | Number | No | - | PID of process |
Local aplications
These are the applications launched by WebChatTest
-
The application project must be in the same directory as the testing application, WebChatTest.
-
It should specify the startup commands for the application.
-
The address should not be overwritten.
Remote aplications
These are the applications NOT launched by WebChatTest
-
It should specify the
remote
parameter to true. -
It should specify the address where it is run, unless it runs on the same machine.
-
It is not necessary, therefore, to specify the boot commands or the application folder. The delay is fixed for remote applications (0 ms).
-
If the application runs on the same machine and you want to get the performance measures, it is necessary to include in the configuration your
pid
How do I test my application?
Once you have built your application and you have included it correctly in the configuration, you only have to launch the test application:
$ cd WebChatTest
$ mvn test