Skip to content

Commit

Permalink
Add core Command model
Browse files Browse the repository at this point in the history
  • Loading branch information
rimonmostafiz committed Jul 24, 2020
1 parent 89916b0 commit 2189110
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
22 changes: 22 additions & 0 deletions 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;
}
}
14 changes: 14 additions & 0 deletions 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;
}
14 changes: 14 additions & 0 deletions 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());
}
}
36 changes: 36 additions & 0 deletions 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");
}
}

0 comments on commit 2189110

Please sign in to comment.