-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e86346
commit 49f28d3
Showing
6 changed files
with
162 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
RestaurantManagementAPI/src/main/kotlin/com/blazc/model/Product.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
RestaurantManagementAPI/src/main/kotlin/com/blazc/model/Restaurant.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
RestaurantManagementAPI/src/test/kotlin/com/blazc/ProductControllerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.blazc | ||
|
||
import com.blazc.model.Product | ||
import io.quarkus.test.junit.QuarkusTest | ||
import io.restassured.RestAssured.given | ||
import jakarta.json.Json | ||
import org.bson.types.ObjectId | ||
import org.hamcrest.CoreMatchers.`is` | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
|
||
@QuarkusTest | ||
class ProductControllerTest { | ||
|
||
private val restaurantId: ObjectId = ObjectId.get() | ||
private lateinit var createdProduct: Product | ||
|
||
@BeforeEach | ||
fun createProduct() { | ||
val productJson = Json.createObjectBuilder() | ||
.add("id", ObjectId.get().toString()) | ||
.add("restaurantId", restaurantId.toString()) | ||
.add("name", "Hamburger") | ||
.add("price", 599) | ||
.build() | ||
|
||
val response = given() | ||
.contentType("application/json") | ||
.body(productJson.toString()) | ||
.`when`().post("/product") | ||
.then() | ||
.statusCode(200) | ||
.contentType("application/json") | ||
.body("name", `is`("Hamburger")) | ||
.extract() | ||
.response() | ||
|
||
createdProduct = response.body.`as`(Product::class.java) | ||
} | ||
|
||
@Test | ||
fun testUpdateProduct() { | ||
val productJson = Json.createObjectBuilder() | ||
.add("id", createdProduct.id.toString()) | ||
.add("restaurantId", createdProduct.restaurantId.toString()) | ||
.add("name", "Cheeseburger") | ||
.add("price", 699) | ||
.build() | ||
|
||
given() | ||
.contentType("application/json") | ||
.body(productJson.toString()) | ||
.`when`().put("/product") | ||
.then() | ||
.statusCode(200) | ||
.contentType("application/json") | ||
.body("name", `is`("Cheeseburger")) | ||
.body("price", `is`(699)) | ||
} | ||
|
||
@Test | ||
fun testGetProductById() { | ||
given() | ||
.contentType("application/json") | ||
.`when`().get("/product/${createdProduct.id}") | ||
.then() | ||
.statusCode(200) | ||
.contentType("application/json") | ||
.body("id", `is`(createdProduct.id.toString())) | ||
} | ||
|
||
@Test | ||
fun testDeleteProduct() { | ||
given() | ||
.`when`().delete("/product/${createdProduct.id}") | ||
.then() | ||
.statusCode(200) | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
RestaurantManagementAPI/src/test/kotlin/com/blazc/RestaurantControllerTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.blazc | ||
|
||
import com.blazc.model.Restaurant | ||
import io.quarkus.test.junit.QuarkusTest | ||
import io.restassured.RestAssured | ||
import jakarta.json.Json | ||
import org.bson.types.ObjectId | ||
import org.hamcrest.CoreMatchers | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.Test | ||
|
||
@QuarkusTest | ||
class RestaurantControllerTest { | ||
|
||
private lateinit var createdRestaurant: Restaurant | ||
|
||
@BeforeEach | ||
fun createRestaurant() { | ||
val json = Json.createObjectBuilder() | ||
.add("id", ObjectId.get().toString()) | ||
.add("name", "Burger King") | ||
.add("address", "1234 Main St") | ||
.add("contact", "555-555-5555") | ||
.build() | ||
|
||
val response = RestAssured.given() | ||
.contentType("application/json") | ||
.body(json.toString()) | ||
.`when`().post("/restaurant") | ||
.then() | ||
.statusCode(200) | ||
.contentType("application/json") | ||
.body("name", CoreMatchers.`is`("Burger King")) | ||
.extract() | ||
.response() | ||
|
||
createdRestaurant = response.body.`as`(Restaurant::class.java) | ||
} | ||
|
||
@Test | ||
fun testUpdateRestaurant() { | ||
val productJson = Json.createObjectBuilder() | ||
.add("id", createdRestaurant.id.toString()) | ||
.add("name", "McDonalds") | ||
.add("address", "1234 Main St") | ||
.add("contact", "555-555-5556") | ||
.build() | ||
|
||
RestAssured.given() | ||
.contentType("application/json") | ||
.body(productJson.toString()) | ||
.`when`().put("/restaurant") | ||
.then() | ||
.statusCode(200) | ||
.contentType("application/json") | ||
.body("contact", CoreMatchers.`is`("555-555-5556")) | ||
} | ||
|
||
@Test | ||
fun testGetRestaurantById() { | ||
RestAssured.given() | ||
.contentType("application/json") | ||
.`when`().get("/restaurant/${createdRestaurant.id}") | ||
.then() | ||
.statusCode(200) | ||
.contentType("application/json") | ||
.body("id", CoreMatchers.`is`(createdRestaurant.id.toString())) | ||
} | ||
|
||
@Test | ||
fun testDeleteRestaurant() { | ||
RestAssured.given() | ||
.`when`().delete("/restaurant/${createdRestaurant.id}") | ||
.then() | ||
.statusCode(200) | ||
} | ||
|
||
} |