package co.je.conductor.domain.business;

import static org.junit.Assert.*;

import org.eclipse.jetty.http.HttpMethod;
import org.junit.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;

public class HttpValidatorTest {
    
    @Test
    public void testIsPostOrPutRequest_OK() {
        
        String post = HttpMethod.POST.name();
        assertEquals(true, HttpValidator.isPostOrPutRequest(post)); 
        
        String put = "PUT";
        assertEquals(true, HttpValidator.isPostOrPutRequest(put));
        
        String postMixedCase = "PoSt";
        assertEquals(true, HttpValidator.isPostOrPutRequest(postMixedCase));
        
        String putMixedCase = "pUt";
        assertEquals(true, HttpValidator.isPostOrPutRequest(putMixedCase));
        
        String get = "GET";
        assertEquals(false, HttpValidator.isPostOrPutRequest(get));
        
        String delete = "delete";
        assertEquals(false, HttpValidator.isPostOrPutRequest(delete));
        
        String anyString = "hallo";
        assertEquals(false, HttpValidator.isPostOrPutRequest(anyString));
    }
    
    @Test
    public void testIsPostOrPutRequest_NOK_nullMethod() {
        
        String nullString = null;
        assertEquals(false, HttpValidator.isPostOrPutRequest(nullString)); 
    }
    
    @Test
    public void testIsPostOrPutRequest_NOK_emptyMethod() {
        
        String emptyString = "";
        assertEquals(false, HttpValidator.isPostOrPutRequest(emptyString)); 
    }
    
    @Test
    public void testRequestHasPayload_OK() {
        
        JsonNode numberNode = JsonNodeFactory.instance.numberNode(1);
        assertEquals(true, HttpValidator.requestHasPayload(numberNode));
        
        JsonNode booleanNode = JsonNodeFactory.instance.booleanNode(false);
        assertEquals(true, HttpValidator.requestHasPayload(booleanNode));
        
        JsonNode binaryNode = JsonNodeFactory.instance.binaryNode("hallo".getBytes());
        assertEquals(true, HttpValidator.requestHasPayload(binaryNode));
        
        JsonNode arrayNode = JsonNodeFactory.instance.arrayNode();
        assertEquals(true, HttpValidator.requestHasPayload(arrayNode));
        
        JsonNode nullNode = JsonNodeFactory.instance.nullNode();
        assertEquals(false, HttpValidator.requestHasPayload(nullNode));
    }
    
    @Test
    public void testRequestHasPayload_NOK_nullPayload() {
        
        JsonNode nullObject = null;
        assertEquals(false, HttpValidator.requestHasPayload(nullObject));
    }
}
@@ -1616,32 +1616,117 @@
 OK() %7B%0A        %0A
+        JsonNodeFactory jsonNodeFactoryInstance = JsonNodeFactory.instance;%0A        %0A
         JsonNode
@@ -1735,25 +1735,25 @@
 umberNode = 
-J
+j
 sonNodeFacto
@@ -1746,34 +1746,33 @@
  jsonNodeFactory
-.i
+I
 nstance.numberNo
@@ -1887,25 +1887,25 @@
 oleanNode = 
-J
+j
 sonNodeFacto
@@ -1898,34 +1898,33 @@
  jsonNodeFactory
-.i
+I
 nstance.booleanN
@@ -2040,33 +2040,33 @@
 de binaryNode = 
-J
+j
 sonNodeFactory.i
@@ -2055,34 +2055,33 @@
  jsonNodeFactory
-.i
+I
 nstance.binaryNo
@@ -2211,25 +2211,25 @@
 arrayNode = 
-J
+j
 sonNodeFacto
@@ -2222,34 +2222,33 @@
  jsonNodeFactory
-.i
+I
 nstance.arrayNod
@@ -2357,25 +2357,25 @@
  nullNode = 
-J
+j
 sonNodeFacto
@@ -2372,26 +2372,25 @@
 nNodeFactory
-.i
+I
 nstance.null

Refactor a unit test in order to improve code clarity. Closes #6.