From 7550f493d17b7492e70612d5f5efc014ce962056 Mon Sep 17 00:00:00 2001 From: Gituser010 Date: Tue, 21 May 2024 13:43:55 +0200 Subject: [PATCH 1/3] Basic tests implemented (cherry picked from commit 8e7984bde4684e0f1fbfef63de9ba7ec3c256c46) --- .gitignore | 40 ++++ README.md | 42 +++- docker-compose.yml | 14 ++ init.py | 28 +++ pom.xml | 52 ++++ src/main/java/org/example/Main.java | 7 + src/test/java/DeviceTest.java | 78 ++++++ src/test/java/DoorTest.java | 289 ++++++++++++++++++++++ src/test/java/FireplaceTest.java | 263 ++++++++++++++++++++ src/test/java/HouseTest.java | 148 ++++++++++++ src/test/java/RGBTest.java | 360 ++++++++++++++++++++++++++++ src/test/java/ThermometerTest.java | 284 ++++++++++++++++++++++ 12 files changed, 1603 insertions(+), 2 deletions(-) create mode 100644 .gitignore create mode 100644 docker-compose.yml create mode 100755 init.py create mode 100644 pom.xml create mode 100644 src/main/java/org/example/Main.java create mode 100644 src/test/java/DeviceTest.java create mode 100644 src/test/java/DoorTest.java create mode 100644 src/test/java/FireplaceTest.java create mode 100644 src/test/java/HouseTest.java create mode 100644 src/test/java/RGBTest.java create mode 100644 src/test/java/ThermometerTest.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7b962cc --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/vcs.xml +.idea +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/README.md b/README.md index b80ed7c..63ea033 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,40 @@ -# smart-home-tests-plus -integration tests for virtual smart home plus +# Virtual Smart Home Project + +This project requires Docker to be running on your machine. Follow the steps below to get the Virtual Smart Home Docker images up and running. + +## Prerequisites + +- Docker installed and running on your machine. +- Git installed on your machine. + +## Steps + +1. Clone the virtual-smart-home-plus repositories from GitHub: + ``` + git clone + ``` +2. Clone the virtual-smart-home-gateway-plus repository from GitHub: + ``` + git clone + ``` +3. Navigate to the project directory of both repositories: + ``` + cd + ``` +4. Run Maven to clean and build the both projects: + ``` + mvn clean install + ``` +5. Create the Docker image for both projects by running the following command in each project directory: + ``` + docker build -t . + ``` +6. Run the `init.py` script to initialize the project: + ``` + python init.py + ``` + +7. Run the tests to ensure everything is working correctly: + ``` + mvn test + ``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f941865 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.7' +services: + gateway: + image: virtual-smart-home-plus-api:latest + ports: + - "8080:8080" + expose: + - "8080" + smart-home: + image: virtual-smart-home-plus:latest + ports: + - "8081:8081" + expose: + - "8081" \ No newline at end of file diff --git a/init.py b/init.py new file mode 100755 index 0000000..2522cec --- /dev/null +++ b/init.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python +import subprocess +import requests +import time + +with open("/tmp/output.log","a") as out: + subprocess.Popen("docker compose up", shell=True, stdout=out, stderr=out) + +print("Waiting for virtual-smart-home to start") +print("Waiting for virtual-smart-home-gateway to start") +time.sleep(9) +print("Servers started") + +house_url = "http://localhost:8081" +gateway_url = "http://localhost:8080" +doorObject = {"label": "door1", "deviceType": "door", "status": "open"} +thermometerObject = {"label": "thermometer1", "deviceType": "thermometer", "temperature": 15.3} +rgbObject = { + "label": "rgb1", "deviceType": "rgb", "switchedOn": "true", "red": 255, "green": 0, "blue": 0} +fireplaceObject = {"label": "fireplace1", "deviceType": "fireplace", "status": "extinguished"} +houseObject = {"name": "house1", "address": "http://smart-home:8081"} + +requests.post(gateway_url + "/api/v0.1/gateway/house", json=houseObject) +requests.post(house_url + "/api/v0.1/house/device/door/", json=doorObject) +requests.post(house_url + "/api/v0.1/house/device/thermometer/", json=thermometerObject) +requests.post(house_url + "/api/v0.1/house/device/rgb/", json=rgbObject) +requests.post(house_url + "/api/v0.1/house/device/fireplace/", json=fireplaceObject) +print("Devices created") \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a83a26b --- /dev/null +++ b/pom.xml @@ -0,0 +1,52 @@ + + + 4.0.0 + + org.example + Virtaul-Smart-Home-Tests + 1.0-SNAPSHOT + + + + org.junit.jupiter + junit-jupiter-api + 5.8.1 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.8.1 + test + + + io.rest-assured + rest-assured + 5.4.0 + test + + + com.fasterxml.jackson.core + jackson-databind + 2.13.0 + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.1 + + + + + + 17 + 17 + + + \ No newline at end of file diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java new file mode 100644 index 0000000..407f157 --- /dev/null +++ b/src/main/java/org/example/Main.java @@ -0,0 +1,7 @@ +package org.example; + +public class Main { + public static void main(String[] args) { + System.out.println("Hello world!"); + } +} \ No newline at end of file diff --git a/src/test/java/DeviceTest.java b/src/test/java/DeviceTest.java new file mode 100644 index 0000000..118d16f --- /dev/null +++ b/src/test/java/DeviceTest.java @@ -0,0 +1,78 @@ +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.with; +import static org.hamcrest.Matchers.*; + +public class DeviceTest { + + @Test + public void device_returns_200_with_correct_name_and_address() { + get("http://localhost:8080/api/v0.1/gateway/house1/device") + .then() + .statusCode(200).assertThat() + .log().all() + .body("size()",is(4)) + .body("deviceType", hasItems("RGBLight", "Door", "Fireplace", "Thermometer")); + } + + @Test + public void device_returns_404_with_incorrect_name() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer2") + .then() + .statusCode(404) + .assertThat() + .body("status", equalTo("NOT_FOUND")); + } + + @Test + public void device_returns_200_for_rgb() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/rgb1") + .then() + .statusCode(200).assertThat() + .body("label", equalTo("rgb1")) + .body("deviceType", equalTo("RGBLight")) + .body("enabled", equalTo(false)) + .body("red", instanceOf(Integer.class)) + .body("green", instanceOf(Integer.class)) + .body("blue", instanceOf(Integer.class)); + } + + @Test + public void device_returns_200_for_door() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/door1") + .then() + .statusCode(200).assertThat() + .body("label", equalTo("door1")) + .body("deviceType", equalTo("Door")) + .body("enabled", instanceOf(Boolean.class)) + .body("status", either(equalTo("opened")).or(equalTo("closed"))); + } + + @Test + public void device_returns_200_for_fireplace() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace1") + .then() + .statusCode(200).assertThat() + .body("label", equalTo("fireplace1")) + .body("deviceType", equalTo("Fireplace")) + .body("enabled", equalTo(false)) + .body("status", either(equalTo("extinguished")).or(equalTo("on_fire"))); + + } + + @Test + public void device_returns_200_for_thermometer() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer1") + .then() + .statusCode(200).assertThat() + .body("label", equalTo("thermometer1")) + .body("deviceType", equalTo("Thermometer")) + .body("enabled", equalTo(false)) + .body("unit", equalTo("C")) + .body("temperature", instanceOf(Float.class)); + } + +} diff --git a/src/test/java/DoorTest.java b/src/test/java/DoorTest.java new file mode 100644 index 0000000..5a992eb --- /dev/null +++ b/src/test/java/DoorTest.java @@ -0,0 +1,289 @@ +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.with; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; + +public class DoorTest { + + @Test + public void door_get_returns_200_with_correct_label_and_type() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("door1")) + .body("enabled", equalTo(false)) + .body("status", equalTo("closed")); + } + + @Test + public void door_get_returns_404_with_incorrect_label() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/door/door2") + .then() + .log().all() + .log().body() + .statusCode(404) + .assertThat() + .body("status", equalTo("NOT_FOUND")); + } + + @Test + public void door_get_returns_404_with_incorrect_devType() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/Doorrrr/door1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void door_get_returns_404_with_empty_label() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/door/") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void update_door_returns_200_with_correct_label_and_devType() { + Map door = Map.of("label","door1","deviceType","Door" ,"enabled",true, "status", "opened"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(200) + .assertThat() + .body("label", equalTo("door1")) + .body("enabled", equalTo(true)) + .body("status", equalTo("opened")); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(200) + .assertThat() + .body("label", equalTo("door1")) + .body("enabled", equalTo(true)) + .body("status", equalTo("opened")); + + door= Map.of("label", "door1", "enabled", false, "status", "closed", "deviceType", "Door"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(200) + .assertThat() + .body("label", equalTo("door1")) + .body("enabled", equalTo(false)) + .body("status", equalTo("closed")); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(200) + .assertThat() + .body("label", equalTo("door1")) + .body("enabled", equalTo(false)) + .body("status", equalTo("closed")); + } + + @Test + public void update_door_returns_200_with_minimal_body() { + Map door = Map.of("label", "door1", "deviceType", "Door"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(200) + .assertThat() + .body("label", equalTo("door1")) + .body("enabled", equalTo(false)) + .body("status", equalTo("closed")); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(200) + .assertThat() + .body("label", equalTo("door1")) + .body("enabled", equalTo(false)) + .body("status", equalTo("closed")); + + } + + @Test + public void door_update_returns_404_with_incorrect_label() { + Map door = Map.of("label","door2","deviceType","Door" ,"enabled",true, "status", "opened"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door2") + .then() + .log().all() + .log().body() + .statusCode(404) + .assertThat() + .body("status", equalTo("NOT_FOUND")); + } + + @Test + public void door_update_returns_400_with_incorrect_body_label_missing() { + Map door = Map.of("deviceType","Door" ,"enabled",true, "status", "opened"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void door_update_returns_400_with_incorrect_body_label_type() { + Map door = Map.of("label",1,"deviceType","Door" ,"enabled",true, "status", "opened"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void door_update_returns_400_with_incorrect_body_deviceType_wrong_type() { + Map door = Map.of("label","door1","deviceType",1 ,"enabled",true, "status", "opened"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void door_update_returns_400_with_incorrect_body_status_wrong_type() { + Map door = Map.of("label","door1","deviceType","Door" ,"enabled",true, "status", 1); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void door_update_returns_400_with_incorrect_body_enabled_wrong_type() { + Map door = Map.of("label","door1","deviceType","Door" ,"enabled",1, "status", "opened"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void door_update_returns_400_with_wrong_enable_not_boolean() { + Map door = Map.of("label","door1","deviceType","Door" ,"enabled","true", "status", "opened"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void door_update_returns_400_with_wrong_status() { + Map door = Map.of("label","door1","deviceType","Door" ,"enabled",true, "status", "open"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void door_update_returns_400_with_wrong_enable_type() { + Map door = Map.of("label","door1","deviceType","Door" ,"enabled",1, "status", "opened"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + + + @Test + public void door_update_returns_404_with_incorrect_devType() { + Map door = Map.of("label","door1","deviceType","Door" ,"enabled",true, "status", "opened"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/doorr/door1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void door_update_returns_404_with_empty_label() { + Map door = Map.of("deviceType","Door" ,"enabled",true, "status", "opened"); + + with().body(door) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void door_post_returns_404() { + Map door = Map.of("label","door1","deviceType","Door" ,"enabled",true, "status", "opened"); + + with().body(door) + .when().post("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void door_delete_returns_404() { + with() + .when().delete("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") + .then() + .log().all() + .statusCode(404); + } + + + + +} diff --git a/src/test/java/FireplaceTest.java b/src/test/java/FireplaceTest.java new file mode 100644 index 0000000..8745dea --- /dev/null +++ b/src/test/java/FireplaceTest.java @@ -0,0 +1,263 @@ +import org.junit.jupiter.api.Test; + +import java.net.PortUnreachableException; +import java.util.Map; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.with; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; + +public class FireplaceTest { + + @Test + public void fireplace_get_returns_200_with_correct_label_and_type() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("fireplace1")) + .body("enabled", equalTo(false)) + .body("status", equalTo("extinguished")); + } + + @Test + public void fireplace_get_returns_404_with_incorrect_label() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace2") + .then() + .log().all() + .log().body() + .statusCode(404) + .assertThat() + .body("status", equalTo("NOT_FOUND")); + } + + @Test + public void fireplace_get_returns_404_with_incorrect_devType() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/Fireplacerrr/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void fireplace_get_returns_404_with_empty_label() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void update_fireplace_returns_200_with_correct_label_and_devType() { + Map fireplace = Map.of("label","fireplace1","deviceType","Fireplace" ,"enabled",true, "status", "on_fire"); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .statusCode(200).assertThat() + .body("label", equalTo("fireplace1")) + .body("enabled", equalTo(true)) + .body("status", equalTo("on_fire")); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("fireplace1")) + .body("enabled", equalTo(true)) + .body("status", equalTo("on_fire")); + + fireplace= Map.of("label", "fireplace1","deviceType","Fireplace", "enabled", false, "status", "extinguished"); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("fireplace1")) + .body("enabled", equalTo(false)) + .body("status", equalTo("extinguished")); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("fireplace1")) + .body("enabled", equalTo(false)) + .body("status", equalTo("extinguished")); + } + + @Test + public void update_fireplace_returns_200_with_minimal_body() { + Map fireplace = Map.of("label","fireplace1","deviceType","Fireplace"); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .statusCode(200).assertThat() + .body("label", equalTo("fireplace1")) + .body("enabled", equalTo(false)) + .body("status", equalTo("extinguished")); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("fireplace1")) + .body("enabled", equalTo(false)) + .body("status", equalTo("extinguished")); + } + + @Test + public void update_fireplace_returns_404_with_incorrect_label() { + Map fireplace = Map.of("label","fireplace2","deviceType","Fireplace" ,"enabled",true); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace2") + .then() + .log().all() + .log().body() + .statusCode(404) + .assertThat() + .body("status", equalTo("NOT_FOUND")); + } + + @Test + public void update_fireplace_returns_404_with_incorrect_devType() { + Map fireplace = Map.of("label","fireplace1","deviceType","Fireplace" ,"enabled",true); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplaceeee/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(404) + .assertThat() + .body("error", equalTo("Not Found")); + } + + @Test + public void update_fireplace_returns_404_with_empty_label() { + Map fireplace = Map.of("label","","deviceType","Fireplace" ,"enabled",true); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void update_fireplace_returns_400_with_incorrect_status_type() { + Map fireplace = Map.of("label","fireplace1","deviceType","Fireplace" ,"enabled",true, "status", 1); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(400) + .assertThat(); + } + + @Test + public void update_fireplace_returns_400_with_incorrect_status() { + Map fireplace = Map.of("label","fireplace1","deviceType","Fireplace" ,"enabled",true, "status", "on_fireee"); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(400) + .assertThat(); + } + + @Test + public void update_fireplace_returns_400_with_incorrect_enabled_type() { + Map fireplace = Map.of("label","fireplace1","deviceType","Fireplace" ,"enabled", 1, "status", "on_fire"); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(400) + .assertThat(); + } + + @Test + public void update_fireplace_returns_400_with_incorrect_label_type() { + Map fireplace = Map.of("label",1,"deviceType","Fireplace" ,"enabled",true, "status", "on_fire"); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(400) + .assertThat(); + } + + @Test + public void update_fireplace_returns_400_with_incorrect_devType_type() { + Map fireplace = Map.of("label","fireplace1","deviceType",1 ,"enabled",true, "status", "on_fire"); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(400) + .assertThat(); + } + + @Test + public void update_fireplace_returns_400_with_empty_body() { + Map fireplace = Map.of(); + + with().body(fireplace) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(400) + .assertThat(); + } + + + @Test + public void fireplace_post_returns_404() { + Map fireplace = Map.of("label","fireplace1","deviceType","Fireplace" ,"enabled",true); + + with().body(fireplace) + .when().post("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void fireplace_delete_returns_404() { + with() + .when().delete("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + +} diff --git a/src/test/java/HouseTest.java b/src/test/java/HouseTest.java new file mode 100644 index 0000000..87cdb75 --- /dev/null +++ b/src/test/java/HouseTest.java @@ -0,0 +1,148 @@ +import org.junit.jupiter.api.Test; + + +import java.util.HashMap; +import java.util.Map; + +import static io.restassured.RestAssured.*; +import static org.hamcrest.Matchers.*; + +public class HouseTest { + + @Test + public void house_returns_200_with_correct_name_and_address() { + get("http://localhost:8080/api/v0.1/gateway/house") + .then() + .statusCode(200).assertThat() + .body("name", hasItem("house1")) + .body("address", hasItem("http://smart-home:8081")); + } + + + @Test + public void house_returns_404_with_incorrect_name() { + get("http://localhost:8080/api/v0.1/gateway/house2") + .then() + .statusCode(404) + .assertThat() + .body("error", equalTo("House not Found")); + } + + @Test + public void house_returns_404_with_empty_name() { + get("http://localhost:8080/api/v0.1/gateway/") + .then() + .statusCode(404); + } + + @Test + public void create_house_returns_201_with_correct_name_and_address() { + Map house = new HashMap<>(); + house.put("name", "house2"); + house.put("address", "http://smart-home:8081"); + + with().body(house) + .when().post("http://localhost:8080/api/v0.1/gateway/house") + .then() + .statusCode(200) + .assertThat() + .body("name", equalTo("house2")) + .body("address", equalTo("http://smart-home:8081")); + + delete("http://localhost:8080/api/v0.1/gateway/house2") + .then() + .statusCode(204); + } + + @Test + public void create_house_returns_409_with_duplicate_name() { + Map house = new HashMap<>(); + house.put("name", "house2"); + house.put("address", "http://smart-home:8081"); + + + with().body(house).when().post("http://localhost:8080/api/v0.1/gateway/house") + .then().statusCode(200); + + with().body(house) + .when().post("http://localhost:8080/api/v0.1/gateway/house") + .then() + .statusCode(409) + .assertThat() + .body("error", equalTo("House already exists")); + + delete("http://localhost:8080/api/v0.1/gateway/house2") + .then() + .statusCode(204); + } + + @Test + public void create_house_returns_400_with_empty_name() { + Map house = new HashMap<>(); + house.put("name", ""); + house.put("address", "http://smart-home:8081"); + + with().body(house) + .when().post("http://localhost:8080/api/v0.1/gateway/house") + .then() + .statusCode(400) + .assertThat() + .body("error", equalTo("Bad Request")); + } + + @Test + public void create_house_returns_400_with_empty_address() { + Map house = new HashMap<>(); + house.put("name", "house2"); + house.put("address", ""); + + with().body(house) + .when().post("http://localhost:8080/api/v0.1/gateway/house") + .then() + .statusCode(400) + .assertThat() + .body("error", equalTo("Bad Request")); + } + + @Test + public void create_house_returns_400_with_wrong_address() { + Map house = new HashMap<>(); + house.put("name", "house2"); + house.put("address", "aaa"); + + with().body(house) + .when().post("http://localhost:8080/api/v0.1/gateway/house") + .then() + .statusCode(400) + .assertThat() + .body("error", equalTo("Bad Request")); + } + + @Test + public void update_house_returns_200_with_correct_name_and_address() { + Map house = new HashMap<>(); + house.put("name", "house2"); + house.put("address", "http://smart-home:8081"); + + with().body(house) + .when().put("http://localhost:8080/api/v0.1/gateway/house1") + .then() + .statusCode(200) + .assertThat() + .body("name", equalTo("house2")) + .body("address", equalTo("http://smart-home:8081")); + + house.put("name", "house1"); + house.put("address", "http://smart-home:8081"); + + with().body(house) + .when().put("http://localhost:8080/api/v0.1/gateway/house2") + .then() + .statusCode(200) + .assertThat() + .body("name", equalTo("house1")) + .body("address", equalTo("http://smart-home:8081")); + } + + +} diff --git a/src/test/java/RGBTest.java b/src/test/java/RGBTest.java new file mode 100644 index 0000000..ca342c1 --- /dev/null +++ b/src/test/java/RGBTest.java @@ -0,0 +1,360 @@ +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.with; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; + +public class RGBTest { + + @Test + public void rgb_get_returns_200_with_correct_label_and_type() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("rgb1")) + .body("enabled", equalTo(false)) + .body("red", instanceOf(Integer.class)) + .body("green", instanceOf(Integer.class)) + .body("blue", instanceOf(Integer.class)); + } + + @Test + public void rgb_get_returns_404_with_incorrect_label() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb2") + .then() + .log().all() + .log().body() + .statusCode(404) + .assertThat() + .body("status", equalTo("NOT_FOUND")); + } + + @Test + public void rgb_get_returns_404_with_incorrect_devType() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/RGBrrr/rgb1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void rgb_get_returns_404_with_empty_label() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void update_rgb_returns_200_with_correct_label_and_devType() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "red", 5); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(200) + .assertThat() + .body("label", equalTo("rgb1")) + .body("enabled", equalTo(true)); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(200) + .assertThat() + .body("label", equalTo("rgb1")) + .body("enabled", equalTo(true)) + .body("red", equalTo(5)); + + rgb = Map.of("label", "rgb1","deviceType","RGBLight", "enabled", false, "blue", 99); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(200) + .assertThat() + .body("label", equalTo("rgb1")) + .body("enabled", equalTo(false)) + .body("blue", equalTo(99)); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(200) + .assertThat() + .body("label", equalTo("rgb1")) + .body("enabled", equalTo(false)) + .body("blue", equalTo(99)); + } + + @Test + public void update_rgb_returns_404_with_incorrect_label() { + Map rgb = Map.of("label", "rgb2", "deviceType", "RGBLight", "enabled", true ); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb2") + .then() + .log().all() + .log().body() + .statusCode(404) + .assertThat() + .body("status", equalTo("NOT_FOUND")); + } + + @Test + public void update_rgb_returns_400_with_incorrect_body() { + Map rgb = Map.of("deviceType", "RGBLight", "enabled", true); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_404_with_incorrect_devType() { + Map rgb = Map.of("label", "rgb1", "deviceType", "rgb", "enabled", true ); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/RGBrrr/rgb1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void update_rgb_returns_404_with_empty_label() { + Map rgb = Map.of("label", "", "deviceType", "RGBLight", "enabled", true ); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void update_rgb_returns_400_with_red_out_of_range() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "red", 256); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + + rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "red", -1); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_wrong_red_type() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "red", "red"); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_green_out_of_range() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "green", 256); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + + rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "green", -1); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_wrong_green_type() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "green", "green"); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_blue_out_of_range() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "blue", 256); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + + rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "blue", -1); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_wrong_blue_type() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "blue", "blue"); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_enabled_not_boolean() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", "true", "red", 5); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_switchedOn_not_boolean() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "red", 5, "switchedOn", "true"); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_devType_not_string() { + Map rgb = Map.of("label", "rgb1", "deviceType", 1, "enabled", true, "red", 5); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_label_not_string() { + Map rgb = Map.of("label", 1, "deviceType", "RGBLight", "enabled", true, "red", 5); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_red_not_number() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "red", "red"); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_green_not_number() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "green", "green"); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void update_rgb_returns_400_with_blue_not_number() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true, "blue", "blue"); + + with().body(rgb) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + + @Test + public void rgb_post_returns_404() { + Map rgb = Map.of("label", "rgb1", "deviceType", "RGBLight", "enabled", true); + + with().body(rgb) + .when().post("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void rgb_delete_returns_404() { + with() + .when().delete("http://localhost:8080/api/v0.1/gateway/house1/device/rgb/rgb1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + +} diff --git a/src/test/java/ThermometerTest.java b/src/test/java/ThermometerTest.java new file mode 100644 index 0000000..3865470 --- /dev/null +++ b/src/test/java/ThermometerTest.java @@ -0,0 +1,284 @@ +import groovy.xml.StreamingDOMBuilder; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static io.restassured.RestAssured.get; +import static io.restassured.RestAssured.with; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.instanceOf; + +public class ThermometerTest { + + @Test + public void thermometer_get_returns_200_with_correct_label_and_type() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("thermometer1")) + .body("unit", equalTo("C")) + .body("enabled", equalTo(false)) + .body("temperature", instanceOf(Float.class)); + } + + @Test + public void thermometer_get_returns_404_with_incorrect_label() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer2") + .then() + .log().all() + .log().body() + .statusCode(404) + .assertThat() + .body("status", equalTo("NOT_FOUND")); + } + + @Test + public void thermometer_get_returns_404_with_incorrect_devType() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/Thermometerrrr/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + + @Test + public void thermometer_get_returns_404_with_empty_label() { + get("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void update_thermometer_returns_200_with_correct_label_and_devType() { + Map thermometer = Map.of("label","thermometer1","deviceType","Thermometer" ,"unit", "F", "enabled",true); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("thermometer1")) + .body("unit", equalTo("F")) + .body("enabled", equalTo(true)) + .body("temperature", instanceOf(Float.class)); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("thermometer1")) + .body("unit", equalTo("F")) + .body("enabled", equalTo(true)) + .body("temperature", instanceOf(Float.class)); + + thermometer= Map.of("label", "thermometer1", "deviceType", "Thermometer","unit", "C", "enabled", false); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("thermometer1")) + .body("unit", equalTo("C")) + .body("enabled", equalTo(false)) + .body("temperature", instanceOf(Float.class)); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("thermometer1")) + .body("unit", equalTo("C")) + .body("enabled", equalTo(false)) + .body("temperature", instanceOf(Float.class)); + } + + @Test + public void update_thermometer_returns_200_with_minimal_body() { + Map thermometer = Map.of("label","thermometer1","deviceType","Thermometer"); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("thermometer1")) + .body("unit", equalTo("C")) + .body("enabled", equalTo(false)) + .body("temperature", instanceOf(Float.class)); + + get("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(200).assertThat() + .body("label", equalTo("thermometer1")) + .body("unit", equalTo("C")) + .body("enabled", equalTo(false)) + .body("temperature", instanceOf(Float.class)); + } + + + @Test + public void thermometer_update_returns_404_with_incorrect_label() { + Map thermometer = Map.of("label","thermometer2","deviceType","Thermometer","unit", "F", "enabled",false); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer2") + .then() + .log().all() + .log().body() + .statusCode(404) + .assertThat() + .body("status", equalTo("NOT_FOUND")); + } + + @Test + public void thermometer_update_returns_400_with_incorrect_body() { + Map thermometer = Map.of("deviceType","Thermometer" ,"unit", "F", "enabled",false); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(400) + .assertThat(); + } + + @Test + public void thermometer_updates_returns_400_with_wrong_unit() { + Map thermometer = Map.of("label","thermometer1","deviceType","Thermometer" ,"unit", 1, "enabled",false); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(400) + .assertThat(); + } + + @Test + public void thermometer_update_returns_404_with_incorrect_devType() { + Map thermometer = Map.of("label","thermometer1","deviceType","Thermometer" ,"unit", "F", "enabled",false); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometerr/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void thermometer_update_returns_404_with_empty_label() { + Map thermometer = Map.of("unit", "F", "enabled",false); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + + @Test + public void thermometer_update_returns_400_with_wrong_unit_type() { + Map thermometer = Map.of("label","thermometer1","deviceType","Thermometer" ,"unit", 1, "enabled",false); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void thermometer_update_returns_400_with_wrong_enabled_type() { + Map thermometer = Map.of("label","thermometer1","deviceType","Thermometer" ,"unit", "F", "enabled","true"); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void thermometer_update_returns_400_with_wrong_temperature_type() { + Map thermometer = Map.of("label","thermometer1","deviceType","Thermometer" ,"unit", "F", "enabled",true, "temperature", "25.0"); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + + + @Test + public void thermometer_update_returns_400_with_wrong_label_type() { + Map thermometer = Map.of("label",1,"deviceType","Thermometer" ,"unit", "F", "enabled",true); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void thermometer_update_returns_400_with_wrong_devType_type() { + Map thermometer = Map.of("label","thermometer1","deviceType",1 ,"unit", "F", "enabled",true); + + with().body(thermometer) + .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(400); + } + + @Test + public void thermometer_post_returns_404() { + Map thermometer = Map.of("label","thermometer1","deviceType","Tshermometer" ,"unit", "F", "enabled",true); + + with().body(thermometer) + .when().post("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + @Test + public void thermometer_delete_returns_404() { + with() + .when().delete("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") + .then() + .log().all() + .log().body() + .statusCode(404); + } + + + + +} From 3f6bbd9115b7555cc238ada7774fc8094df705e4 Mon Sep 17 00:00:00 2001 From: Gituser010 Date: Thu, 25 Jul 2024 15:41:40 +0200 Subject: [PATCH 2/3] test updated to new Status --- src/test/java/DeviceTest.java | 6 +++--- src/test/java/DoorTest.java | 33 ++++++++++++++---------------- src/test/java/FireplaceTest.java | 18 ++++++++-------- src/test/java/ThermometerTest.java | 8 ++++---- 4 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/test/java/DeviceTest.java b/src/test/java/DeviceTest.java index 118d16f..150b010 100644 --- a/src/test/java/DeviceTest.java +++ b/src/test/java/DeviceTest.java @@ -48,7 +48,7 @@ public void device_returns_200_for_door() { .body("label", equalTo("door1")) .body("deviceType", equalTo("Door")) .body("enabled", instanceOf(Boolean.class)) - .body("status", either(equalTo("opened")).or(equalTo("closed"))); + .body("status", either(equalTo("Opened")).or(equalTo("Closed"))); } @Test @@ -59,7 +59,7 @@ public void device_returns_200_for_fireplace() { .body("label", equalTo("fireplace1")) .body("deviceType", equalTo("Fireplace")) .body("enabled", equalTo(false)) - .body("status", either(equalTo("extinguished")).or(equalTo("on_fire"))); + .body("status", either(equalTo("Extinguished")).or(equalTo("On_fire"))); } @@ -70,7 +70,7 @@ public void device_returns_200_for_thermometer() { .statusCode(200).assertThat() .body("label", equalTo("thermometer1")) .body("deviceType", equalTo("Thermometer")) - .body("enabled", equalTo(false)) + .body("enabled", instanceOf(Boolean.class)) .body("unit", equalTo("C")) .body("temperature", instanceOf(Float.class)); } diff --git a/src/test/java/DoorTest.java b/src/test/java/DoorTest.java index 5a992eb..e33b511 100644 --- a/src/test/java/DoorTest.java +++ b/src/test/java/DoorTest.java @@ -17,8 +17,7 @@ public void door_get_returns_200_with_correct_label_and_type() { .log().body() .statusCode(200).assertThat() .body("label", equalTo("door1")) - .body("enabled", equalTo(false)) - .body("status", equalTo("closed")); + .body("status", equalTo("Opened")); } @Test @@ -52,7 +51,7 @@ public void door_get_returns_404_with_empty_label() { @Test public void update_door_returns_200_with_correct_label_and_devType() { - Map door = Map.of("label","door1","deviceType","Door" ,"enabled",true, "status", "opened"); + Map door = Map.of("label","door1","deviceType","Door" ,"enabled",true, "status", "Closed"); with().body(door) .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") @@ -63,7 +62,7 @@ public void update_door_returns_200_with_correct_label_and_devType() { .assertThat() .body("label", equalTo("door1")) .body("enabled", equalTo(true)) - .body("status", equalTo("opened")); + .body("status", equalTo("Closed")); get("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") .then() @@ -73,9 +72,9 @@ public void update_door_returns_200_with_correct_label_and_devType() { .assertThat() .body("label", equalTo("door1")) .body("enabled", equalTo(true)) - .body("status", equalTo("opened")); + .body("status", equalTo("Closed")); - door= Map.of("label", "door1", "enabled", false, "status", "closed", "deviceType", "Door"); + door= Map.of("label", "door1", "enabled", false, "status", "Opened", "deviceType", "Door"); with().body(door) .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") @@ -86,7 +85,7 @@ public void update_door_returns_200_with_correct_label_and_devType() { .assertThat() .body("label", equalTo("door1")) .body("enabled", equalTo(false)) - .body("status", equalTo("closed")); + .body("status", equalTo("Opened")); get("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") .then() @@ -96,7 +95,7 @@ public void update_door_returns_200_with_correct_label_and_devType() { .assertThat() .body("label", equalTo("door1")) .body("enabled", equalTo(false)) - .body("status", equalTo("closed")); + .body("status", equalTo("Opened")); } @Test @@ -111,8 +110,8 @@ public void update_door_returns_200_with_minimal_body() { .statusCode(200) .assertThat() .body("label", equalTo("door1")) - .body("enabled", equalTo(false)) - .body("status", equalTo("closed")); + .body("enabled", instanceOf(Boolean.class)) + .body("status", equalTo("Opened")); get("http://localhost:8080/api/v0.1/gateway/house1/device/door/door1") .then() @@ -121,13 +120,13 @@ public void update_door_returns_200_with_minimal_body() { .statusCode(200) .assertThat() .body("label", equalTo("door1")) - .body("enabled", equalTo(false)) - .body("status", equalTo("closed")); + .body("enabled", instanceOf(Boolean.class)) + .body("status", equalTo("Opened")); } @Test - public void door_update_returns_404_with_incorrect_label() { + public void door_update_returns_400_with_incorrect_label() { Map door = Map.of("label","door2","deviceType","Door" ,"enabled",true, "status", "opened"); with().body(door) @@ -135,9 +134,7 @@ public void door_update_returns_404_with_incorrect_label() { .then() .log().all() .log().body() - .statusCode(404) - .assertThat() - .body("status", equalTo("NOT_FOUND")); + .statusCode(400); } @Test @@ -239,7 +236,7 @@ public void door_update_returns_400_with_wrong_enable_type() { @Test - public void door_update_returns_404_with_incorrect_devType() { + public void door_update_returns_400_with_incorrect_devType() { Map door = Map.of("label","door1","deviceType","Door" ,"enabled",true, "status", "opened"); with().body(door) @@ -247,7 +244,7 @@ public void door_update_returns_404_with_incorrect_devType() { .then() .log().all() .log().body() - .statusCode(404); + .statusCode(400); } @Test diff --git a/src/test/java/FireplaceTest.java b/src/test/java/FireplaceTest.java index 8745dea..addd9dd 100644 --- a/src/test/java/FireplaceTest.java +++ b/src/test/java/FireplaceTest.java @@ -19,7 +19,7 @@ public void fireplace_get_returns_200_with_correct_label_and_type() { .statusCode(200).assertThat() .body("label", equalTo("fireplace1")) .body("enabled", equalTo(false)) - .body("status", equalTo("extinguished")); + .body("status", equalTo("On_fire")); } @Test @@ -53,7 +53,7 @@ public void fireplace_get_returns_404_with_empty_label() { @Test public void update_fireplace_returns_200_with_correct_label_and_devType() { - Map fireplace = Map.of("label","fireplace1","deviceType","Fireplace" ,"enabled",true, "status", "on_fire"); + Map fireplace = Map.of("label","fireplace1","deviceType","Fireplace" ,"enabled",true, "status", "Extinguished"); with().body(fireplace) .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") @@ -62,7 +62,7 @@ public void update_fireplace_returns_200_with_correct_label_and_devType() { .statusCode(200).assertThat() .body("label", equalTo("fireplace1")) .body("enabled", equalTo(true)) - .body("status", equalTo("on_fire")); + .body("status", equalTo("Extinguished")); get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") .then() @@ -71,9 +71,9 @@ public void update_fireplace_returns_200_with_correct_label_and_devType() { .statusCode(200).assertThat() .body("label", equalTo("fireplace1")) .body("enabled", equalTo(true)) - .body("status", equalTo("on_fire")); + .body("status", equalTo("Extinguished")); - fireplace= Map.of("label", "fireplace1","deviceType","Fireplace", "enabled", false, "status", "extinguished"); + fireplace= Map.of("label", "fireplace1","deviceType","Fireplace", "enabled", false, "status", "On_fire"); with().body(fireplace) .when().put("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") @@ -83,7 +83,7 @@ public void update_fireplace_returns_200_with_correct_label_and_devType() { .statusCode(200).assertThat() .body("label", equalTo("fireplace1")) .body("enabled", equalTo(false)) - .body("status", equalTo("extinguished")); + .body("status", equalTo("On_fire")); get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") .then() @@ -92,7 +92,7 @@ public void update_fireplace_returns_200_with_correct_label_and_devType() { .statusCode(200).assertThat() .body("label", equalTo("fireplace1")) .body("enabled", equalTo(false)) - .body("status", equalTo("extinguished")); + .body("status", equalTo("On_fire")); } @Test @@ -106,7 +106,7 @@ public void update_fireplace_returns_200_with_minimal_body() { .statusCode(200).assertThat() .body("label", equalTo("fireplace1")) .body("enabled", equalTo(false)) - .body("status", equalTo("extinguished")); + .body("status", equalTo("On_fire")); get("http://localhost:8080/api/v0.1/gateway/house1/device/fireplace/fireplace1") .then() @@ -115,7 +115,7 @@ public void update_fireplace_returns_200_with_minimal_body() { .statusCode(200).assertThat() .body("label", equalTo("fireplace1")) .body("enabled", equalTo(false)) - .body("status", equalTo("extinguished")); + .body("status", equalTo("On_fire")); } @Test diff --git a/src/test/java/ThermometerTest.java b/src/test/java/ThermometerTest.java index 3865470..92da12c 100644 --- a/src/test/java/ThermometerTest.java +++ b/src/test/java/ThermometerTest.java @@ -19,7 +19,7 @@ public void thermometer_get_returns_200_with_correct_label_and_type() { .statusCode(200).assertThat() .body("label", equalTo("thermometer1")) .body("unit", equalTo("C")) - .body("enabled", equalTo(false)) + .body("enabled", equalTo(true)) .body("temperature", instanceOf(Float.class)); } @@ -98,7 +98,7 @@ public void update_thermometer_returns_200_with_correct_label_and_devType() { .statusCode(200).assertThat() .body("label", equalTo("thermometer1")) .body("unit", equalTo("C")) - .body("enabled", equalTo(false)) + .body("enabled", equalTo(true)) .body("temperature", instanceOf(Float.class)); } @@ -114,7 +114,7 @@ public void update_thermometer_returns_200_with_minimal_body() { .statusCode(200).assertThat() .body("label", equalTo("thermometer1")) .body("unit", equalTo("C")) - .body("enabled", equalTo(false)) + .body("enabled", equalTo(true)) .body("temperature", instanceOf(Float.class)); get("http://localhost:8080/api/v0.1/gateway/house1/device/thermometer/thermometer1") @@ -124,7 +124,7 @@ public void update_thermometer_returns_200_with_minimal_body() { .statusCode(200).assertThat() .body("label", equalTo("thermometer1")) .body("unit", equalTo("C")) - .body("enabled", equalTo(false)) + .body("enabled", equalTo(true)) .body("temperature", instanceOf(Float.class)); } From 0f7ab63bf778b23170283926f15bd888fb0885a2 Mon Sep 17 00:00:00 2001 From: Gituser010 Date: Tue, 30 Jul 2024 13:16:02 +0200 Subject: [PATCH 3/3] EOF fixed --- .gitignore | 2 +- docker-compose.yml | 2 +- init.py | 2 +- pom.xml | 2 +- src/main/java/org/example/Main.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 7b962cc..813a923 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,4 @@ build/ .vscode/ ### Mac OS ### -.DS_Store \ No newline at end of file +.DS_Store diff --git a/docker-compose.yml b/docker-compose.yml index f941865..02d49b4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,4 +11,4 @@ services: ports: - "8081:8081" expose: - - "8081" \ No newline at end of file + - "8081" diff --git a/init.py b/init.py index 2522cec..cefd68a 100755 --- a/init.py +++ b/init.py @@ -25,4 +25,4 @@ requests.post(house_url + "/api/v0.1/house/device/thermometer/", json=thermometerObject) requests.post(house_url + "/api/v0.1/house/device/rgb/", json=rgbObject) requests.post(house_url + "/api/v0.1/house/device/fireplace/", json=fireplaceObject) -print("Devices created") \ No newline at end of file +print("Devices created") diff --git a/pom.xml b/pom.xml index a83a26b..b2e3f5e 100644 --- a/pom.xml +++ b/pom.xml @@ -49,4 +49,4 @@ 17 - \ No newline at end of file + diff --git a/src/main/java/org/example/Main.java b/src/main/java/org/example/Main.java index 407f157..9a3edc1 100644 --- a/src/main/java/org/example/Main.java +++ b/src/main/java/org/example/Main.java @@ -4,4 +4,4 @@ public class Main { public static void main(String[] args) { System.out.println("Hello world!"); } -} \ No newline at end of file +}