// Path: spanners-mvc/src/main/java/org/dontpanic/spanners/springmvc/domain/User.java
// public class User implements UserDetails {
// 
//     private String username;
//     private String password;
//     private Boolean enabled;
// 
//     public User() {
//     }
// 
//     public User(String username, String password, Boolean enabled) {
//         this.username = username;
//         this.password = password;
//         this.enabled = enabled;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void setUsername(String username) {
//         this.username = username;
//     }
// 
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public Boolean getEnabled() {
//         return enabled;
//     }
// 
//     public void setEnabled(Boolean enabled) {
//         this.enabled = enabled;
//     }
// 
//     @Override
//     public boolean isAccountNonExpired() {
//         return true;
//     }
// 
//     @Override
//     public boolean isAccountNonLocked() {
//         return true;
//     }
// 
//     @Override
//     public boolean isCredentialsNonExpired() {
//         return true;
//     }
// 
//     @Override
//     public boolean isEnabled() {
//         return enabled;
//     }
// 
//     @Override
//     public Collection<? extends GrantedAuthority> getAuthorities() {
//         return Collections.emptySet();
//     }
// }


import org.dontpanic.spanners.springmvc.domain.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.client.RestClientTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.client.ResponseCreator;
import static org.junit.Assert.*;
import static org.springframework.http.HttpMethod.*;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
package org.dontpanic.spanners.springmvc.services;



/**
 * Unit tests for the Rest user details service
 * Created by stevie on 14/07/16.
 */
@RunWith(SpringRunner.class)
@RestClientTest(RestUserDetailsService.class)
public class RestUserDetailsServiceTest {

    private static final String USERNAME = "jbloggs";
    private static final String PASSWORD = "password123";
    private static final boolean ENABLED = true;
    private static final MediaType APPLICATION_HAL_JSON = MediaType.valueOf("application/hal+json;charset=UTF-8");

    @Autowired
    private MockRestServiceServer server;
    @Autowired
    private RestUserDetailsService service;


    @Test
    public void testLoadUserByUsername() {

        server.expect(requestTo("/" + USERNAME)).andExpect(method(GET))
                .andRespond(withHalJsonResponse("/user_jbloggs_GET.txt"));

        UserDetails userDetails = service.loadUserByUsername(USERNAME);
        assertNotNull(userDetails);
    }


    @Test
    public void testCreateUser() throws Exception {

        server.expect(requestTo("/")).andExpect(method(POST))
                .andRespond(withStatus(HttpStatus.CREATED));

// Path: spanners-mvc/src/main/java/org/dontpanic/spanners/springmvc/domain/User.java
// public class User implements UserDetails {
// 
//     private String username;
//     private String password;
//     private Boolean enabled;
// 
//     public User() {
//     }
// 
//     public User(String username, String password, Boolean enabled) {
//         this.username = username;
//         this.password = password;
//         this.enabled = enabled;
//     }
// 
//     public String getUsername() {
//         return username;
//     }
// 
//     public void setUsername(String username) {
//         this.username = username;
//     }
// 
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public Boolean getEnabled() {
//         return enabled;
//     }
// 
//     public void setEnabled(Boolean enabled) {
//         this.enabled = enabled;
//     }
// 
//     @Override
//     public boolean isAccountNonExpired() {
//         return true;
//     }
// 
//     @Override
//     public boolean isAccountNonLocked() {
//         return true;
//     }
// 
//     @Override
//     public boolean isCredentialsNonExpired() {
//         return true;
//     }
// 
//     @Override
//     public boolean isEnabled() {
//         return enabled;
//     }
// 
//     @Override
//     public Collection<? extends GrantedAuthority> getAuthorities() {
//         return Collections.emptySet();
//     }
// }


// Path: spanners-mvc/src/test/java/org/dontpanic/spanners/springmvc/services/RestUserDetailsServiceTest.java
import org.dontpanic.spanners.springmvc.domain.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.client.RestClientTest;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.test.web.client.ResponseCreator;
import static org.junit.Assert.*;
import static org.springframework.http.HttpMethod.*;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;

package org.dontpanic.spanners.springmvc.services;



/**
 * Unit tests for the Rest user details service
 * Created by stevie on 14/07/16.
 */
@RunWith(SpringRunner.class)
@RestClientTest(RestUserDetailsService.class)
public class RestUserDetailsServiceTest {

    private static final String USERNAME = "jbloggs";
    private static final String PASSWORD = "password123";
    private static final boolean ENABLED = true;
    private static final MediaType APPLICATION_HAL_JSON = MediaType.valueOf("application/hal+json;charset=UTF-8");

    @Autowired
    private MockRestServiceServer server;
    @Autowired
    private RestUserDetailsService service;


    @Test
    public void testLoadUserByUsername() {

        server.expect(requestTo("/" + USERNAME)).andExpect(method(GET))
                .andRespond(withHalJsonResponse("/user_jbloggs_GET.txt"));

        UserDetails userDetails = service.loadUserByUsername(USERNAME);
        assertNotNull(userDetails);
    }


    @Test
    public void testCreateUser() throws Exception {

        server.expect(requestTo("/")).andExpect(method(POST))
                .andRespond(withStatus(HttpStatus.CREATED));

        UserDetails user = new User(USERNAME, PASSWORD, ENABLED);