package com.coding4people.mosquitoreport.api.controllers;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;

import org.glassfish.jersey.server.ResourceConfig;
import org.junit.Test;
import org.mockito.Mock;

import com.coding4people.mosquitoreport.api.WithServer;
import com.coding4people.mosquitoreport.api.controllers.AuthEmailController.AuthInput;
import com.coding4people.mosquitoreport.api.models.Email;
import com.coding4people.mosquitoreport.api.repositories.EmailRepository;

public class AuthControllerTest extends WithServer {
    @Mock
    private EmailRepository emailRepository;

    @Override
    protected ResourceConfig configure() {
        return super.configure().register(AuthEmailController.class);
    }
    
    @Test
    public void testAuthFailed() {
    	AuthInput data = new AuthInput();
        data.setEmail("test@test.org");
        data.setPassword("fakepassword");
        
        Email email = new Email();
        email.setEmail("test@test.org");
        email.setPassword("$2a$12$JZP7DXIzHFnqBI0aj/d0p.ub4SPRe7Dph/OEcTwCJxdODbXLoERbe");

        when(emailRepository.load("test@test.org")).thenReturn(email);

        Response response = target().path("/auth/email").request().post(Entity.json(data));

        assertEquals(403, response.getStatus());

        verify(emailRepository).load("test@test.org");
    }

    //@Test
    public void testAuthSuccess() {
    	AuthInput data = new AuthInput();
        data.setEmail("me@ro.ger.io");
        data.setPassword("asdfgh");
        
        Email email = new Email();
        email.setEmail("me@ro.ger.io");
        email.setPassword("$2a$12$JZP7DXIzHFnqBI0aj/d0p.ub4SPRe7Dph/OEcTwCJxdODbXLoERbe");

        when(emailRepository.load("test@test.org")).thenReturn(email);

        Response response = target().path("/auth/email").request().post(Entity.json(data));

        assertEquals(200, response.getStatus());
        assertEquals("application/json;charset=UTF-8", response.getHeaderString("Content-type"));

        Email result = response.readEntity(Email.class);
        verify(emailRepository).load("test@test.org");
        assertEquals("test@test.org", result.getEmail());
    }
}

@@ -100,16 +100,60 @@
 quals;%0D%0A
+import static org.junit.Assert.assertTrue;%0D%0A
 import s
@@ -183,24 +183,24 @@
 to.verify;%0D%0A
-
 import stati
@@ -354,16 +354,42 @@
 onfig;%0D%0A
+import org.junit.Before;%0D%0A
 import o
@@ -710,16 +710,72 @@
 sitory;%0D
+%0Aimport com.fasterxml.jackson.databind.node.ObjectNode;%0D
 %0A%0D%0Apubli
@@ -878,24 +878,52 @@
 ository;%0D%0A%0D%0A
+    private Email email;%0D%0A%0D%0A
     @Overrid
@@ -1047,20 +1047,340 @@
 %0A    %7D%0D%0A
+%0D%0A
     
+@Before%0D%0A    public void setUp() throws Exception %7B%0D%0A        super.setUp();%0D%0A%0D%0A        email = new Email();%0D%0A        email.setUserguid(%2200000000-0000-0000-0000-000000000000%22);%0D%0A        email.setEmail(%22test@test.org%22);%0D%0A        email.setPassword(%22$2a$12$6XwAD7Zr62LpR7lcJ4Ulk.D.PieyA2eRPLpFSA0bQ5hsVZU0tcDta%22);%0D%0A    %7D%0D%0A
 %0D%0A    @T
@@ -1416,33 +1416,36 @@
 Failed() %7B%0D%0A    
-%09
+    
 AuthInput data =
@@ -1550,188 +1550,8 @@
 %22);%0D
-%0A        %0D%0A        Email email = new Email();%0D%0A        email.setEmail(%22test@test.org%22);%0D%0A        email.setPassword(%22$2a$12$JZP7DXIzHFnqBI0aj/d0p.ub4SPRe7Dph/OEcTwCJxdODbXLoERbe%22);%0D
 %0A%0D%0A 
@@ -1843,10 +1843,8 @@
     
-//
 @Tes
@@ -1891,9 +1891,12 @@
     
-%09
+    
 Auth
@@ -1953,236 +1953,58 @@
 il(%22
-me@ro.ger.io%22);%0D%0A        data.setPassword(%22asdfgh%22);%0D%0A        %0D%0A        Email email = new Email();%0D%0A        email.setEmail(%22me@ro.ger.io%22);%0D%0A        email.setPassword(%22$2a$12$JZP7DXIzHFnqBI0aj/d0p.ub4SPRe7Dph/OEcTwCJxdODbXLoERbe
+test@test.org%22);%0D%0A        data.setPassword(%22123456
 %22);%0D
@@ -2334,21 +2334,26 @@
         
-Email
+ObjectNode
  result 
@@ -2374,21 +2374,26 @@
 dEntity(
-Email
+ObjectNode
 .class);
@@ -2468,48 +2468,31 @@
 sert
-Equals(%22test@test.org%22, result.getEmail(
+True(result.has(%22token%22
 ));%0D

Add testAuthSuccess