Remove the CLI.
This commit is contained in:
-163
@@ -1,163 +0,0 @@
|
||||
package space.kklochko.jpa_hospital_example.cli.commands
|
||||
|
||||
import groovy.sql.Sql
|
||||
import jakarta.persistence.EntityManager
|
||||
import space.kklochko.jpa_hospital_example.cli.commands.factories.CommandFactory
|
||||
import space.kklochko.jpa_hospital_example.config.factories.LoadDataBaseConfigFromEnvFile
|
||||
import space.kklochko.jpa_hospital_example.config.models.DataBaseConfig
|
||||
import space.kklochko.jpa_hospital_example.db.factories.DataBaseConnection
|
||||
import space.kklochko.jpa_hospital_example.db.factories.EntityManagerConnection
|
||||
import space.kklochko.jpa_hospital_example.db.repositories.DepartmentRepository
|
||||
import space.kklochko.jpa_hospital_example.db.repositories.IndicatorRepository
|
||||
import space.kklochko.jpa_hospital_example.db.repositories.PatientRepository
|
||||
import spock.lang.Shared
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Stepwise
|
||||
import spock.lang.Subject
|
||||
|
||||
@Stepwise
|
||||
class CommandEntitySpec extends Specification {
|
||||
@Shared
|
||||
Sql sql
|
||||
|
||||
@Shared
|
||||
EntityManager manager
|
||||
|
||||
@Shared
|
||||
DataBaseConfig db
|
||||
|
||||
@Shared
|
||||
DataBaseConnection dbc
|
||||
|
||||
def setupSpec() {
|
||||
db = (new LoadDataBaseConfigFromEnvFile()).load("db.testing")
|
||||
dbc = new DataBaseConnection(db)
|
||||
|
||||
manager = (new EntityManagerConnection("testing")).connect()
|
||||
|
||||
sql = Sql.newInstance(db.getUrl(), db.getProperties().get("user"), db.getProperties().get("password"))
|
||||
}
|
||||
|
||||
def "Test insert commands"() {
|
||||
given: "I have a command data"
|
||||
CommandData data = new CommandData("insert", datatype, values)
|
||||
UUID id = UUID.fromString(data.arguments.get("id"))
|
||||
|
||||
and: "I have factory for the command"
|
||||
CommandFactory factory = new CommandFactory()
|
||||
@Subject
|
||||
CommandEntity command = factory.create(data, repository)
|
||||
|
||||
when: "The command is executed"
|
||||
def result = command.run()
|
||||
|
||||
then: "checking that the insert was successful"
|
||||
result
|
||||
id
|
||||
|
||||
and: "checking that the entry is added"
|
||||
def isExist = sql.firstRow(verifyStatement, id)
|
||||
isExist
|
||||
|
||||
cleanup: "remove the data"
|
||||
sql.execute("delete from " + datatype + "s")
|
||||
|
||||
where:
|
||||
datatype | values | repository || verifyStatement
|
||||
"indicator" | ["id": "3b3f62f4-75b4-11ee-99cb-c0e4349366ad",
|
||||
"type": "blood, blood",
|
||||
"values": "Good samples.",
|
||||
"timestamp": "2023-10-17 14:30:00"] | new IndicatorRepository(manager) || "SELECT type FROM indicators WHERE id = ?"
|
||||
"patient" | ["id": "bcbbcdb4-702c-11ee-9113-c0e4349366bd",
|
||||
"name": "Oleh",
|
||||
"age": "21",
|
||||
"phone": "380123451234"] | new PatientRepository(manager) || "SELECT name FROM patients WHERE id = ?"
|
||||
"department" | ["id": "bcbbcdb4-702c-11ee-9113-c0e4349366cd",
|
||||
"name": "First department",
|
||||
"location": "Stepan Bandera Street",
|
||||
"phone": "380123451244"] | new DepartmentRepository(manager) || "SELECT name FROM departments WHERE id = ?"
|
||||
}
|
||||
|
||||
def "Test update commands"() {
|
||||
given: "I have a command data"
|
||||
CommandData data = new CommandData("update", datatype, values)
|
||||
UUID id = UUID.fromString(data.arguments.get("id"))
|
||||
|
||||
and: "I have a fixture"
|
||||
sql.execute(fixture)
|
||||
|
||||
and: "I have factory for the command"
|
||||
CommandFactory factory = new CommandFactory()
|
||||
@Subject
|
||||
CommandEntity command = factory.create(data, repository)
|
||||
|
||||
when: "The command is executed"
|
||||
def result = command.run()
|
||||
|
||||
then: "checking that the insert was successful"
|
||||
result
|
||||
id
|
||||
|
||||
and: "checking that the entry is added"
|
||||
def isExist = sql.firstRow(verifyStatement, id)
|
||||
isExist
|
||||
|
||||
cleanup: "remove the data"
|
||||
sql.execute("delete from " + datatype + "s")
|
||||
|
||||
where:
|
||||
datatype | values | fixture | repository || verifyStatement
|
||||
"indicator" | ["id": "bcbbcdb4-702c-11ee-9113-c0e4349366ab",
|
||||
"type": "blood, blood",
|
||||
"values": "Good samples.",
|
||||
"timestamp": "2023-10-17 14:30:00"] | "insert into indicators (id, type, values, timestamp) values ('bcbbcdb4-702c-11ee-9113-c0e4349366ab', 'Samples', 'fine', '2023-10-17 16:30:00')"
|
||||
| new IndicatorRepository(manager) || "SELECT type FROM indicators WHERE id = ? AND type='blood, blood'"
|
||||
"patient" | ["id": "bcbbcdb4-702c-11ee-9113-c0e4349366bb",
|
||||
"name": "Oleh",
|
||||
"age": "21",
|
||||
"phone": "380123451234"] | "insert into patients (id, name, age, phone) values ('bcbbcdb4-702c-11ee-9113-c0e4349366bb', 'Maybe Oleh', 22, '380123451234')"
|
||||
| new PatientRepository(manager) || "SELECT name FROM patients WHERE id = ? AND name='Oleh'"
|
||||
"department" | ["id": "bcbbcdb4-702c-11ee-9113-c0e4349366cb",
|
||||
"name": "First department",
|
||||
"location": "Stepan Bandera Street",
|
||||
"phone": "380123451244"] | "insert into departments (id, name, location, phone) values ('bcbbcdb4-702c-11ee-9113-c0e4349366cb', 'Second department', 'Stepan Bandera Street', '380123451244')"
|
||||
| new DepartmentRepository(manager) || "SELECT name FROM departments WHERE id = ? AND name='First department'"
|
||||
}
|
||||
|
||||
def "Test delete commands"() {
|
||||
given: "I have a command data"
|
||||
CommandData data = new CommandData("remove", datatype, values)
|
||||
UUID id = UUID.fromString(data.arguments.get("id"))
|
||||
|
||||
and: "I have a fixture"
|
||||
sql.execute(fixture)
|
||||
|
||||
and: "I have factory for the command"
|
||||
CommandFactory factory = new CommandFactory()
|
||||
@Subject
|
||||
CommandEntity command = factory.create(data, repository)
|
||||
|
||||
when: "The command is executed"
|
||||
def result = command.run()
|
||||
|
||||
then: "checking that the insert was successful"
|
||||
result
|
||||
id
|
||||
|
||||
and: "checking that the entry is added"
|
||||
def isExist = sql.firstRow(verifyStatement, id)
|
||||
!isExist
|
||||
|
||||
cleanup: "remove the data"
|
||||
sql.execute("delete from " + datatype + "s")
|
||||
|
||||
where:
|
||||
datatype | values | fixture | repository || verifyStatement
|
||||
"indicator" | ["id": "bcbbcdb4-702c-11ee-9113-c0e4349366ab"] | "insert into indicators (id, type, values, timestamp) values ('bcbbcdb4-702c-11ee-9113-c0e4349366ab', 'Samples', 'fine', '2023-10-17 16:30:00')"
|
||||
| new IndicatorRepository(manager) || "SELECT type FROM indicators WHERE id = ?"
|
||||
"patient" | ["id": "bcbbcdb4-702c-11ee-9113-c0e4349366bb"] | "insert into patients (id, name, age, phone) values ('bcbbcdb4-702c-11ee-9113-c0e4349366bb', 'Maybe Oleh', 22, '380123451234')"
|
||||
| new PatientRepository(manager) || "SELECT name FROM patients WHERE id = ?"
|
||||
"department" | ["id": "bcbbcdb4-702c-11ee-9113-c0e4349366cb"] | "insert into departments (id, name, location, phone) values ('bcbbcdb4-702c-11ee-9113-c0e4349366cb', 'Second department', 'Stepan Bandera Street', '380123451244')"
|
||||
| new DepartmentRepository(manager) || "SELECT name FROM departments WHERE id = ?"
|
||||
}
|
||||
}
|
||||
-27
@@ -1,27 +0,0 @@
|
||||
package space.kklochko.jpa_hospital_example.cli.validators
|
||||
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Subject
|
||||
|
||||
class CommandValidatorSpec extends Specification {
|
||||
def "Parser parse the commands"() {
|
||||
given: "I have the validator"
|
||||
@Subject
|
||||
def validator = new CommandValidator(command)
|
||||
|
||||
when: "check if valid"
|
||||
boolean status = validator.isValid()
|
||||
|
||||
then: "the result must be as expected"
|
||||
status == expectedStatus
|
||||
|
||||
where:
|
||||
command || expectedStatus
|
||||
"insert indicator(id='1', type='blood', values='Good samples.', timestamp='2023-10-17 14:30:00')" || true
|
||||
"insert indicator(id='1', type='blood, blood', values='Good samples.', timestamp='2023-10-17 14:30:00')" || true
|
||||
"update indicator(id='1', type='blood, blood', values='Good samples.', timestamp='2023-10-17 14:30:00')" || true
|
||||
"remove indicator(id='1', type='blood, blood', values='Good samples.', timestamp='2023-10-17 14:30:00')" || true
|
||||
"readAll indicator()" || true
|
||||
}
|
||||
}
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package space.kklochko.jpa_hospital_example.cli.validators
|
||||
|
||||
import space.kklochko.jpa_hospital_example.cli.commands.CommandData
|
||||
import space.kklochko.jpa_hospital_example.cli.parsers.CommandParser
|
||||
import spock.lang.Specification
|
||||
import spock.lang.Subject
|
||||
|
||||
class InputStringFormatValidatorSpec extends Specification {
|
||||
def "Parser parse the commands"() {
|
||||
given: "I have the validator"
|
||||
@Subject
|
||||
def validator = new InputStringFormatValidator(command)
|
||||
|
||||
when: "check if valid"
|
||||
boolean status = validator.isValid()
|
||||
|
||||
then: "the result must be as expected"
|
||||
status == expectedStatus
|
||||
|
||||
where:
|
||||
command || expectedStatus
|
||||
"insert indicator(id='1', type='blood', values='Good samples.', timestamp='2023-10-17 14:30:00')" || true
|
||||
" insert indicator(id='1', type='blood, blood', values='Good samples.', timestamp='2023-10-17 14:30:00') " || false
|
||||
"insert indicator(id='1', type='blood, blood', values='Good samples.', timestamp='2023-10-17 14:30:00')" || true
|
||||
"readAll indicator()" || true
|
||||
" readAll indicator() " || false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user