This document outlines the steps for manually testing the EnergyController in the Green Energy Manager application. The focus is on ensuring that the controller correctly handles various scenarios for calculating net energy differences and posting energy readings.
- Test Environment
- Test Tools
- Test Scenarios
- 1. Test Net Energy Difference Calculation for a Valid Month
- 2. Test Net Energy Difference Calculation for an Invalid Month
- 3. Test Net Energy Difference Calculation for an Invalid Month (String)
- 4. Test Net Energy Difference Calculation with No Data for Month
- 5. Test Posting Energy Reading for Generated Energy
- 6. Test Posting Energy Reading for Used Energy
- 7. Test Posting Energy Reading with Invalid Transaction Type
- 8. Test Posting Energy Reading with Database Error
- 9. Test Posting Energy Reading with Empty Body
- 10. Test Posting Energy Reading with Missing Transaction Type
- 11. Test Posting Energy Reading with Missing amountkWh
- 12. Test Posting Energy Reading with Missing transactionDate
- Further Testing Ideas
- Application server with EnergyController deployed.
- Access to the REST API endpoints.
- Database containing sample data for energy transactions.
- API testing tool (e.g., Postman)
- Browser
Objective: Verify that the netEnergyDifferenceCalculation
method returns the correct net energy difference for a valid month.
Steps:
- Use Postman to send a GET request to the endpoint:
/api/energy/netDifference?month=4
. - Verify the response status is HTTP 200 OK.
- Verify the response body contains the message:
Net Energy Difference for APRIL is: 8 kWh
.
Expected Result:
- Status code:
200
- Response body:
{"netEnergyDifference": "Net Energy Difference for APRIL is: 8 kWh"}
Objective: Verify that the netEnergyDifferenceCalculation
method returns a bad request error for an invalid month.
Steps:
- Use Postman to send a GET request to the endpoint:
/api/energy/netDifference?month=13
. - Verify the response status is HTTP 400 Bad Request.
- Verify the response body contains the error message:
Invalid month. Please provide a month value between 1 and 12.
Expected Result:
- Status code:
400
- Response body:
{"error": "Invalid month. Please provide a month value between 1 and 12."}
Objective: Verify that the netEnergyDifferenceCalculation
method returns a bad request error for when the month is entered as string.
Steps:
- Use Postman to send a GET request to the endpoint:
/api/energy/netDifference?month=June
. - Verify the response status is HTTP 400 Bad Request.
- Verify the response body contains the error message:
Invalid parameter type. Please provide a valid month value as an integer.
Expected Result:
- Status code:
400
- Response body:
{"error": "Invalid parameter type. Please provide a valid month value as an integer."}
Objective: Verify that the netEnergyDifferenceCalculation
method returns a zero net energy difference when there is no data for the specified month.
Steps:
- Use Postman to send a GET request to the endpoint:
/api/energy/netDifference?month=8
. - Verify the response status is HTTP 200 OK.
- Verify the response body contains the message:
Net Energy Difference for AUGUST is: 0 kWh
.
Expected Result:
- Status code:
200
- Response body:
{"netEnergyDifference": "Net Energy Difference for AUGUST is: 0 kWh"}
Objective: Verify that the meterReading
endpoint correctly processes a new energy reading for generated energy.
Steps:
- Use Postman to send a POST request to the endpoint:
/api/energy/meterReading
with the following JSON body:{ "transactionType": "GENERATED", "energyType": "solar", "amountKWh": 50.1, "transactionDate": "2024-07-22T00:00:00.000Z" }
- Verify the response status is HTTP 200 OK.
- Verify the response body contains the message:
New energy reading added: {meterReading}
.
Expected Result:
- Status code:
200
- Response body:
New energy reading added: {meterReading}
Objective: Verify that the meterReading
endpoint correctly processes a new energy reading for used energy.
Steps:
- Use Postman to send a POST request to the endpoint:
/api/energy/meterReading
with the following JSON body:{ "transactionType": "USED", "energyType": "wind", "amountKWh": 48.1, "transactionDate": "2024-07-22T00:00:00.000Z" }
- Verify the response status is HTTP 200 OK.
- Verify the response body contains the message:
New energy reading added: {meterReading}
.
Expected Result:
- Status code:
200
- Response body:
New energy reading added: {meterReading}
Objective: Verify that the meterReading
endpoint returns a bad request error when an invalid transaction type is provided.
Steps:
- Use Postman to send a POST request to the endpoint:
/api/energy/meterReading
with the following JSON body:{ "transactionType": "NOTVALID", "energyType": "wind", "amountKWh": 48.1, "transactionDate": "2024-07-22T00:00:00.000Z" }
- Verify the response status is HTTP 400 Bad Request.
Expected Result:
- Status code:
400
- Response body:
Invalid transaction type.
Objective: Verify that the meterReading
endpoint returns a bad request error when there is a database error.
Steps:
- Use Postman to send a POST request to the endpoint:
/api/energy/meterReading
with the following JSON body:{ "transactionType": "GENERATED", "energyType": "wind", "amountKWh": 48.1, "transactionDate": "2024-07-22T00:00:00.000Z" }
- Verify the response status is HTTP 500 Internal Server Error.
Expected Result:
- Status code:
500
- Response body:
Internal server error occurred. Please try again later.
Objective: Verify that the meterReading
endpoint returns a bad request error when the request body is empty.
Steps:
- Use Postman to send a POST request to the endpoint:
/api/energy/meterReading
with an empty JSON body:{}
. - Verify the response status is HTTP 400 Bad Request.
Expected Result:
- Status code:
400
Objective: Verify that the meterReading
endpoint returns a bad request error when the transaction type is missing.
Steps:
- Use Postman to send a POST request to the endpoint:
/api/energy/meterReading
with the following JSON body:{ "energyType": "solar", "amountKWh": 50.1, "transactionDate": "2024-07-22T00:00:00.000Z" }
- Verify the response status is HTTP 400 Bad Request.
Expected Result:
- Status code:
400
- Response body:
Transaction type is required.
Objective: Verify that the meterReading endpoint returns a bad request error when the amountkWh field is missing in the request body.
Steps:
-
Use Postman to send a POST request to the endpoint:
/api/energy/meterReading
with the following JSON body:{ "transactionType": "GENERATED", "energyType": "solar", "transactionDate": "2024-07-22T00:00:00.000Z" }
-
Verify that the response status is HTTP 400 Bad Request.
Expected Result:
- Status code:
400
- Response body:
Amount of energy in KW/h is required.
Objective: Verify that the meterReading endpoint returns a bad request error when the transactionDate field is missing in the request body.
Steps:
-
Use Postman to send a POST request to the endpoint:
/api/energy/meterReading
with the following JSON body:{ "transactionType": "GENERATED", "energyType": "solar", "amountKWh": 50.1 }
-
Verify that the response status is HTTP 400 Bad Request.
Expected Result:
- Status code:
400
- Response body:
Valid date in format YYYY-MM-DD is required.
Objective: Verify that only authenticated users can access the energy endpoints.
Steps:
- Use Postman to send a GET and POST request to the endpoint without authentication.
- Verify the response status is HTTP 401 Unauthorised.
Expected Result:
- Status code:
401
- Response body:
{"error": "Unauthorised access"}
Objective: Verify that users with appropriate roles can access and perform actions.
Steps:
- Use Postman to send a GET/POST request with a user having insufficient privileges.
- Verify the response status is HTTP 403 Forbidden.
Expected Result:
- Status code:
403
- Response body:
{"error": "Forbidden"}
Objective: Verify that a negative amount of energy returns a proper error message.
Steps:
- Use Postman to send a POST request with a negative energy amount.
- Verify the response status is HTTP 400 Bad Request.
Expected Result:
- Status code:
400
- Response body:
{"error": "Amount of energy cannot be negative"}`
Objective: Verify that the endpoint rejects invalid date formats.
Steps:
- Use Postman to send a POST request with an incorrectly formatted transactionDate.
- Verify that the system returns a 400 Bad Request response with an appropriate error message.
Expected Result:
- Status code:
400
- Response body:
{"error": "Invalid date format"}