diff --git a/qontract.json b/qontract.json index c655032..9090c2b 100644 --- a/qontract.json +++ b/qontract.json @@ -4,7 +4,7 @@ "provider": "git", "repository": "https://github.com/qontract/petstore-contracts.git", "test": [ - "run/qontract/examples/petstore/1.qontract" + "run/qontract/examples/petstore/1.1.qontract" ] } ] diff --git a/src/main/java/com/petstore/demo/controllers/MockHelper.kt b/src/main/java/com/petstore/demo/controllers/MockHelper.kt deleted file mode 100644 index a9da0c4..0000000 --- a/src/main/java/com/petstore/demo/controllers/MockHelper.kt +++ /dev/null @@ -1,75 +0,0 @@ -package com.petstore.demo.controllers - -import com.petstore.demo.model.DB.addOrder -import com.petstore.demo.model.DB.addPet -import com.petstore.demo.model.DB.cleanSlate -import com.petstore.demo.model.Order -import com.petstore.demo.model.Pet -import org.springframework.beans.factory.annotation.Value -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty -import org.springframework.context.annotation.Condition -import org.springframework.context.annotation.ConditionContext -import org.springframework.core.type.AnnotatedTypeMetadata -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestBody -import org.springframework.web.bind.annotation.RestController -import java.util.* - -@ConditionalOnProperty(name=["environment"], havingValue="test") -@RestController -class MockHelper { - @PostMapping("/_qontract/state") - fun serverState(@RequestBody state: HashMap) { - cleanSlate() - - when { - state.containsKey("id") -> { - if(state.getOrDefault("api", "") == "order") - addOrder(Order(id = Integer.parseInt(state.get("id").toString()), count = 0, status = "pending", type = "dog")) - else - addPet(newPetById(state, "id")) - } - state.containsKey("type") && state["type"] != "" -> { - val count = state.getOrDefault("count", 2) - if(count !is Int) - throw Exception("Received parameter count=$count but count was not a number.") - - if(state.getOrDefault("api", "") == "order") { - repeat(count) { - addOrder(Order(type = state["type"].toString(), count = 0, status = "pending")) - addPet(Pet(type = state["type"].toString(), name = "Random name", status = "available")) - } - } else { - repeat(count) { - addPet(Pet(type = state["type"].toString(), name = "Archie", status = "available")) - } - } - } - state.containsKey("name") && state["name"] != "" -> { - addPet(Pet(name = state["name"].toString(), type = "cat", status = "available")) - addPet(Pet(name = state["name"].toString(), type = "cat", status = "available")) - } - state.containsKey("status") && state["status"] != "" -> { - val count = 2 - - if(state.getOrDefault("api", "") == "order") { - repeat(count) { - addOrder(Order(status = state["status"].toString(), count = 0, type = "dog")) - } - } else { - repeat(count) { - addPet(Pet(status = state["status"].toString(), name = "Archie", type = "dog")) - } - } - } - state.containsKey("no_pets") -> { - - } - else -> { - throw Exception("Setup keys not recognized: ${state.keys}") - } - } - } - - private fun newPetById(state: HashMap, key: String) = Pet(name = "Archie", id = state[key].toString().toInt(), type = "dog", status = "available") -} diff --git a/src/main/java/com/petstore/demo/controllers/PetData.kt b/src/main/java/com/petstore/demo/controllers/PetData.kt deleted file mode 100644 index 6d7cf1f..0000000 --- a/src/main/java/com/petstore/demo/controllers/PetData.kt +++ /dev/null @@ -1,3 +0,0 @@ -package com.petstore.demo.controllers - -data class PetData(val id: Int = 0, val name: String?, val type: String?, val status: String?) \ No newline at end of file diff --git a/src/main/java/com/petstore/demo/model/DB.kt b/src/main/java/com/petstore/demo/model/DB.kt index 4814420..5f8a455 100644 --- a/src/main/java/com/petstore/demo/model/DB.kt +++ b/src/main/java/com/petstore/demo/model/DB.kt @@ -1,8 +1,8 @@ package com.petstore.demo.model object DB { - private val pets: MutableList = mutableListOf() - private val orders: MutableList = mutableListOf() + private val pets: MutableList = mutableListOf(Pet("Archibald", "dog", "available", 10), Pet("Gemini", "dog", "available", 20)) + private val orders: MutableList = mutableListOf(Order("dog", 2, "pending", 10), Order("cat", 1, "pending", 20)) fun addPet(pet: Pet) { pets.add(pet) }