package com.coding4people.mosquitoreport.api.controllers;

import static org.junit.Assert.assertEquals;

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.models.User;
import com.coding4people.mosquitoreport.api.repositories.UserRepository;

public class ProfileControllerTest extends WithServer {
    @Mock
    UserRepository userRepository;

    User currentUser = new User();;

    @Override
    protected ResourceConfig configure() {
        return super.configure().register(ProfileController.class);
    }
    
    @Override
    protected User getCurrentUser() {
        return currentUser;
    }

    @Test
    public void testGet() {
        currentUser.setGuid("my guid");
        currentUser.setEmail("my email");
        currentUser.setFirstname("my firstname");
        currentUser.setLastname("my lastname");
        currentUser.setLocation("my location");
        currentUser.setFacebookurl("my facebookurl");
        currentUser.setTwitter("my twitter");
        currentUser.setProfilepictureguid("my profilepictureguid");

        Response response = target().path("/profile").request().get();

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

        User user = response.readEntity(User.class);

        assertEquals("my guid", user.getGuid());
        assertEquals("my email", user.getEmail());
        assertEquals("my firstname", user.getFirstname());
        assertEquals("my lastname", user.getLastname());
        assertEquals("my location", user.getLocation());
        assertEquals("my facebookurl", user.getFacebookurl());
        assertEquals("my twitter", user.getTwitter());
        assertEquals("my profilepictureguid", user.getProfilepictureguid());
    }
}

@@ -96,24 +96,102 @@
 ertEquals;%0D%0A
+import static org.mockito.Mockito.verify;%0D%0A%0D%0Aimport javax.ws.rs.client.Entity;
 %0D%0Aimport jav
@@ -374,24 +374,117 @@
 ithServer;%0D%0A
+import com.coding4people.mosquitoreport.api.controllers.ProfileController.ProfilePostInput;%0D%0A
 import com.c
@@ -2193,11 +2193,1621 @@
 %0A    %7D%0D%0A
+    %0D%0A    @Test%0D%0A    public void testPost() %7B%0D%0A        currentUser.setGuid(%22my guid%22);%0D%0A        currentUser.setEmail(%22my email%22);%0D%0A        currentUser.setFirstname(%22my firstname%22);%0D%0A        currentUser.setLastname(%22my lastname%22);%0D%0A        currentUser.setLocation(%22my location%22);%0D%0A        currentUser.setFacebookurl(%22my facebookurl%22);%0D%0A        currentUser.setTwitter(%22my twitter%22);%0D%0A        currentUser.setProfilepictureguid(%22my profilepictureguid%22);%0D%0A        %0D%0A        ProfilePostInput input = new ProfilePostInput();%0D%0A        input.setFirstname(%22new firstname%22);%0D%0A        input.setLastname(%22new lastname%22);%0D%0A        input.setLocation(%22new location%22);%0D%0A        input.setFacebookurl(%22new facebookurl%22);%0D%0A        input.setTwitter(%22new twitter%22);%0D%0A        %0D%0A        Response response = target().path(%22/profile%22).request().post(Entity.json(input));%0D%0A        %0D%0A        assertEquals(200, response.getStatus());%0D%0A        assertEquals(%22application/json;charset=UTF-8%22, response.getHeaderString(%22Content-type%22));%0D%0A%0D%0A        verify(userRepository).save(currentUser);%0D%0A        %0D%0A        User user = response.readEntity(User.class);%0D%0A        assertEquals(%22my guid%22, user.getGuid());%0D%0A        assertEquals(%22my email%22, user.getEmail());%0D%0A        assertEquals(%22new firstname%22, user.getFirstname());%0D%0A        assertEquals(%22new lastname%22, user.getLastname());%0D%0A        assertEquals(%22new location%22, user.getLocation());%0D%0A        assertEquals(%22new facebookurl%22, user.getFacebookurl());%0D%0A        assertEquals(%22new twitter%22, user.getTwitter());%0D%0A        assertEquals(%22my profilepictureguid%22, user.getProfilepictureguid());%0D%0A    %7D%0D%0A
 %7D%0D%0A

Test profile post