From 218911085502e47ffc75b74fdbde88496723b46b Mon Sep 17 00:00:00 2001 From: Rimon Mostafiz Date: Fri, 24 Jul 2020 19:14:38 +0600 Subject: [PATCH] Add core Command model --- .../elasticlight/core/Command.java | 22 ++++++++++++ .../rimonmostafiz/elasticlight/core/Head.java | 14 ++++++++ .../rimonmostafiz/elasticlight/core/Verb.java | 14 ++++++++ .../elasticlight/core/CommandTest.java | 36 +++++++++++++++++++ 4 files changed, 86 insertions(+) create mode 100644 src/main/java/com/rimonmostafiz/elasticlight/core/Command.java create mode 100644 src/main/java/com/rimonmostafiz/elasticlight/core/Head.java create mode 100644 src/main/java/com/rimonmostafiz/elasticlight/core/Verb.java create mode 100644 src/test/java/com/rimonmostafiz/elasticlight/core/CommandTest.java diff --git a/src/main/java/com/rimonmostafiz/elasticlight/core/Command.java b/src/main/java/com/rimonmostafiz/elasticlight/core/Command.java new file mode 100644 index 0000000..049722a --- /dev/null +++ b/src/main/java/com/rimonmostafiz/elasticlight/core/Command.java @@ -0,0 +1,22 @@ +package com.rimonmostafiz.elasticlight.core; + +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * @author Rimon Mostafiz + */ +@Data +@AllArgsConstructor +public class Command { + private Verb verb; + private String path; + private String body; + private Head head; + + public Command() { + this.path = ""; + this.verb = Verb.GET; + this.head = Head.JSON; + } +} diff --git a/src/main/java/com/rimonmostafiz/elasticlight/core/Head.java b/src/main/java/com/rimonmostafiz/elasticlight/core/Head.java new file mode 100644 index 0000000..fb8e90e --- /dev/null +++ b/src/main/java/com/rimonmostafiz/elasticlight/core/Head.java @@ -0,0 +1,14 @@ +package com.rimonmostafiz.elasticlight.core; + +import lombok.AllArgsConstructor; + +/** + * @author Rimon Mostafiz + */ +@AllArgsConstructor +public enum Head { + JSON("application/json"), + ND_JSON("application/ndjson"); + + public String value; +} diff --git a/src/main/java/com/rimonmostafiz/elasticlight/core/Verb.java b/src/main/java/com/rimonmostafiz/elasticlight/core/Verb.java new file mode 100644 index 0000000..25c61a6 --- /dev/null +++ b/src/main/java/com/rimonmostafiz/elasticlight/core/Verb.java @@ -0,0 +1,14 @@ +package com.rimonmostafiz.elasticlight.core; + +import org.springframework.http.HttpMethod; + +/** + * @author Rimon Mostafiz + */ +public enum Verb { + GET, POST, PUT, DELETE; + + public HttpMethod resolve() { + return HttpMethod.resolve(this.name()); + } +} diff --git a/src/test/java/com/rimonmostafiz/elasticlight/core/CommandTest.java b/src/test/java/com/rimonmostafiz/elasticlight/core/CommandTest.java new file mode 100644 index 0000000..3f1279f --- /dev/null +++ b/src/test/java/com/rimonmostafiz/elasticlight/core/CommandTest.java @@ -0,0 +1,36 @@ +package com.rimonmostafiz.elasticlight.core; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +/** + * @author Rimon Mostafiz + */ +@SpringBootTest +class CommandTest { + + private Command command; + + @BeforeEach + public void before() { + this.command = new Command(); + } + + @Test + public void defaultValue() { + Assertions.assertNotNull(command, "command null"); + + Assertions.assertNotNull(this.command.getVerb(), "command.verb null"); + Assertions.assertEquals(command.getVerb(), Verb.GET, "command.verb is not GET"); + + Assertions.assertNotNull(this.command.getPath(), "command.path null"); + Assertions.assertEquals(this.command.getPath(), "", "command.path not empty"); + + Assertions.assertNull(this.command.getBody(), "command.body is not null"); + + Assertions.assertNotNull(this.command.getHead(), "command.head is null"); + Assertions.assertEquals(this.command.getHead(), Head.JSON, "command.head is not JSON"); + } +} \ No newline at end of file