package com.bubbles.server.domain;

import com.bubbles.server.BubblesApplication;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.http.MediaType;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;

import static org.junit.Assert.assertEquals;

/**
 * Created by LMSH on 2015/5/12.
 */
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = BubblesApplication.class)
@WebAppConfiguration
@Transactional
@Sql("/test-user-data.sql")
public class UserRepositoryTest {

    @Autowired
    private WebApplicationContext wac;

    @Autowired
    private UserRepository userRepository;

    private MockMvc mockMvc;

    @Before
    public void setup() {
        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
    }

    @Test
    public void testUserResr() throws Exception {
        // test spring-data-rest
        this.mockMvc.perform(get("/users-rest/10000")
                .accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
                .andExpect(status().isOk())
                .andExpect(content().contentType("application/json;charset=UTF-8"))
                .andExpect(jsonPath("$.gender").value("m"));
    }

    @Test
    public void testSetScore() {
        userRepository.setScoreById(10000L, 500);
        User user = userRepository.findOne(10000L);
        assertEquals(500, user.getScore());
    }

    @Test
    public void testSetNickname() {
        userRepository.setNicknameById(10001L, "test-nickname");
        User user = userRepository.findOne(10001L);
        assertEquals("test-nickname", user.getNickname());
    }

    @Test
    public void testSetGender() {
        userRepository.setGenderById(10000L, "m");
        User user = userRepository.findOne(10000L);
        assertEquals("m", user.getGender());
    }
}
@@ -79,33 +79,8 @@
 on;%0A
-import org.junit.Before;%0A
 impo
@@ -267,51 +267,8 @@
 on;%0A
-import org.springframework.http.MediaType;%0A
 impo
@@ -389,193 +389,8 @@
 er;%0A
-import org.springframework.test.context.web.WebAppConfiguration;%0Aimport org.springframework.test.web.servlet.MockMvc;%0Aimport org.springframework.test.web.servlet.setup.MockMvcBuilders;%0A
 impo
@@ -454,239 +454,77 @@
 al;%0A
+%0A
 import 
-org.springframework.web.context.WebApplicationContext;%0A%0Aimport static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;%0Aimport static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;%0A
+java.util.List;%0A%0Aimport static org.junit.Assert.assertEquals;
 %0Aimp
@@ -557,22 +557,23 @@
 t.assert
-Equals
+NotNull
 ;%0A%0A/**%0A 
@@ -578,37 +578,53 @@
 %0A * 
-Created by LMSH on 2015/5/12.
+User Repository test.%0A * @author Mingshan Lei
 %0A */
@@ -736,29 +736,8 @@
 ss)%0A
-@WebAppConfiguration%0A
 @Tra
@@ -841,522 +841,288 @@
 ate 
-WebApplicationContext wac;%0A%0A    @Autowired%0A    private UserRepository userRepository;%0A%0A    private MockMvc mockMvc;%0A%0A    @Before%0A    public void setup() %7B%0A        this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(
+UserRepository userRepository;%0A%0A    @Test%0A    public void testFindByDeviceId() %7B%0A        List%3CUser%3E userList = userRepository.findByDeviceId(%2212266552212%22
 );%0A    
-%7D%0A%0A
     
-@Test%0A    public void testUserResr() throws Exception %7B%0A        // test spring-data-rest%0A        this.mockMvc.perform(get(%22/users-rest/10000%22)%0A                .accept(MediaType.parseMediaType(%22application/json;charset=UTF-8%22)))%0A                .andExpect(status().isOk
+// should only have one user in userList%0A        assertNotNull(userList);%0A        assertEquals(1, userList.size
 ())
+;
 %0A   
@@ -1130,141 +1130,50 @@
     
-        .andExpect(content().contentType(%22application/json;charset=UTF-8%22))%0A                .andExpect(jsonPath(%22$.gender%22).value(%22m%22
+assertEquals(10000, userList.get(0).getId(
 ));%0A
@@ -1316,32 +1316,61 @@
 indOne(10000L);%0A
+        assertNotNull(user);%0A
         assertEq
@@ -1563,24 +1563,53 @@
 ne(10001L);%0A
+        assertNotNull(user);%0A
         asse
@@ -1801,32 +1801,61 @@
 indOne(10000L);%0A
+        assertNotNull(user);%0A
         assertEq

fix test