Architecture
Architecture
=====================================================
1. Introduction
===============
This document provides an overview of the architecture and design of the Voter
service. The service is designed to manage
candidate information, allow users to cast votes, and provide insights into voting
results.
2. Architecture Overview
========================
3. Components
=============
- Responsible for handling HTTP requests and routing them to the appropriate
services.
- Implements the API endpoints for entering candidates, casting votes, counting
votes, listing votes, and retrieving
the winner.
- Handles the logic for casting votes, counting votes, and determining the
winner.
- Ensures data consistency and integrity during the voting process.
4. Database Schema
===================
5. Sequence Diagrams
=====================
6. Testing
===========
Overview:
The VotingControllerTest class is designed to test the functionalities of the
VotingController class in the Voting System project. The tests utilize the Spring
WebMvcTest annotation for testing the controller layer in isolation.
Test Methods:
1. testEnterCandidate:
Objective: Verify that the enterCandidate endpoint successfully adds a
candidate to the system.
Test Steps:
Perform a POST request to "/entercandidate" with the candidate name
parameter set to "ajay".
Expect an HTTP OK status (200).
2. testCastVoteValidCandidate:
Objective: Confirm that the castVote endpoint correctly registers a vote for
a valid candidate.
Test Steps:
Mock the votingService.castVote method to return 1 when called
with the name "ajay".
Perform a POST request to "/castvote" with the candidate name
parameter set to "ajay".
Expect an HTTP OK status (200) and response content "1".
3. testCastVoteInvalidCandidate:
Objective: Validate that the castVote endpoint handles invalid candidates and
returns the expected result.
Test Steps:
Mock the votingService.castVote method to return -1 when called
with the name "invalidCandidate".
Perform a POST request to "/castvote" with the candidate name
parameter set to "invalidCandidate".
Expect an HTTP OK status (200) and response content "-1".
4. testCountVote:
Objective: Ensure that the countVote endpoint retrieves the correct vote
count for a specific candidate.
Test Steps:
Mock the votingService.countVote method to return 3 when called with
the name "ajay".
Perform a GET request to "/countvote" with the candidate name parameter
set to "ajay".
Expect an HTTP OK status (200) and response content "3".
5. testListVote:
Objective: Validate that the listVotes endpoint returns the expected
JSON response for a list of candidates and their vote counts.
Test Steps:
Mock the votingService.listVotes method to return a map with
candidate names and respective vote counts.
Perform a GET request to "/listvote".
Expect an HTTP OK status (200) and JSON response with the correct
candidate names and vote counts.
6. testGetWinner:
Objective: Confirm that the getWinner endpoint returns the correct
winner.
Test Steps:
Mock the votingService.getWinner method to return "ajay".
Perform a GET request to "/getwinner".
Expect an HTTP OK status (200) and response content "ajay".
Conclusion:
The unit tests for the VotingController have been designed to ensure the
correct behavior of the various endpoints
in the Voting System project. These tests cover scenarios such as candidate
entry, vote casting, vote counting, and
winner determination.
7. Deployment
==============
i.Prerequisites
Before deploying the Voter service, make sure you have the following
prerequisites installed:
Java Development Kit (JDK)
Git
ii.Clone the Repository
git clone --depth 1 --branch master
https://github.com/jayaprakash9603/VotingSystem.git
cd voter-service
iii.API Usage
You can now use the provided APIs to interact with the Voter service. Example
API usage: