// Path: wechat-mp-autoconfigure/src/main/java/com/github/hippoom/wechat/mp/security/authentication/WeChatMpOAuth2AccessTokenAuthentication.java
// public class WeChatMpOAuth2AccessTokenAuthentication implements Authentication {
// 
//     private final WxMpOAuth2AccessToken accessToken;
// 
//     public WeChatMpOAuth2AccessTokenAuthentication(WxMpOAuth2AccessToken accessToken) {
//         this.accessToken = accessToken;
//     }
// 
//     @Override
//     public Collection<? extends GrantedAuthority> getAuthorities() {
//         return Collections.emptyList();
//     }
// 
//     @Override
//     public Object getCredentials() {
//         return null;
//     }
// 
//     @Override
//     public Object getDetails() {
//         return getOpenId();
//     }
// 
//     @Override
//     public Object getPrincipal() {
//         return getOpenId();
//     }
// 
//     @Override
//     public boolean isAuthenticated() {
//         return true;
//     }
// 
//     @Override
//     public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
// 
//     }
// 
//     @Override
//     public String getName() {
//         return accessToken.getOpenId();
//     }
// 
//     public OpenId getOpenId() {
//         return OpenId.valueOf(accessToken.getOpenId());
//     }
// }
// 
// Path: wechat-mp-test/src/main/java/com/github/hippoom/wechat/mp/test/fixture/WxMpOAuth2AccessTokenFixture.java
// public class WxMpOAuth2AccessTokenFixture {
// 
//     private WxMpOAuth2AccessToken target = new WxMpOAuth2AccessToken();
// 
//     private WxMpOAuth2AccessTokenFixture() {
//         target.setOpenId(OpenId.valueOf(UUID.randomUUID().toString()).getValue());
//         target.setAccessToken("accessToken");
//         target.setRefreshToken("refreshToken");
//         target.setExpiresIn(3600);
//         target.setScope("snsapi_base");
//     }
// 
//     /**
//      * Customize the {@link OpenId}.
//      *
//      * @param openId a custom {@link OpenId}
//      * @return this {@link WxMpOAuth2AccessTokenFixture}
//      */
//     public WxMpOAuth2AccessTokenFixture with(OpenId openId) {
//         target.setOpenId(openId.getValue());
//         return this;
//     }
// 
//     /**
//      * Build the {@link WxMpOAuth2AccessToken}.
//      *
//      * @return this {@link WxMpOAuth2AccessToken}
//      */
//     public WxMpOAuth2AccessToken build() {
//         return target;
//     }
// 
//     /**
//      * Static factory method for {@link WxMpOAuth2AccessTokenFixture}.
//      *
//      * @return a {@link WxMpOAuth2AccessTokenFixture} with default values
//      */
//     public static WxMpOAuth2AccessTokenFixture aWxMpOAuth2AccessToken() {
//         return new WxMpOAuth2AccessTokenFixture();
//     }
// }
// 
// Path: wechat-mp-autoconfigure/src/main/java/com/github/hippoom/wechat/oauth/OpenId.java
// @Value
// public class OpenId {
// 
//     private String value;
// 
//     private OpenId(String value) {
//         this.value = value;
//     }
// 
//     public static OpenId valueOf(String value) {
//         return new OpenId(value);
//     }
// }


import com.github.hippoom.wechat.mp.security.authentication.WeChatMpOAuth2AccessTokenAuthentication;
import com.github.hippoom.wechat.mp.test.fixture.WxMpOAuth2AccessTokenFixture;
import com.github.hippoom.wechat.oauth.OpenId;
import java.util.UUID;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.web.servlet.request.RequestPostProcessor;
package com.github.hippoom.wechat.mp.test.web.servlet.request;


// @formatter:off
/**
 * Test fixture for {@link WxMpOAuth2AccessTokenFixture}.
 * <pre class="code">
 *
 * import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
 * import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
 * import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 * import static com.github.hippoom.wechat.mp.test.web.servlet.request
 *     .WxMpOAuth2AccessTokenRequestPostProcessor.aWeChatMpUser;
 *
 * &#064;Test public void returns_wechat_user_profile() {
 *     this.mockMvc.perform(
 *         get("/rel/wechat/user/profile/me").with(aWeChatMpUser().withOpenId(userProfile.openId))
 *     ).andDo(print()).andExpect(status().isOk());
 * }
 *
 * </pre>
 *
 * @see RequestPostProcessor
 * @since 0.3.0
 */
//@formatter:on
public class WxMpOAuth2AccessTokenRequestPostProcessor implements RequestPostProcessor {

    private OpenId openId = OpenId.valueOf(UUID.randomUUID().toString());

    /**
     * Customize the {@link OpenId}.
     *
     * @param openId a custom {@link OpenId}
     * @return this {@link WxMpOAuth2AccessTokenRequestPostProcessor}
     */
    public WxMpOAuth2AccessTokenRequestPostProcessor with(OpenId openId) {
        this.openId = openId;
        return this;
    }

    /**
     * Customize the {@link OpenId}.
     *
     * @param openId a custom {@link OpenId} value
     * @return this {@link WxMpOAuth2AccessTokenRequestPostProcessor}
     */
    public WxMpOAuth2AccessTokenRequestPostProcessor withOpenId(String openId) {
        return with(OpenId.valueOf(openId));
    }

    @Override
    public MockHttpServletRequest postProcessRequest(
        MockHttpServletRequest mockHttpServletRequest) {
        WxMpOAuth2AccessToken accessToken = WxMpOAuth2AccessTokenFixture.aWxMpOAuth2AccessToken()
            .with(openId).build();
        RequestPostProcessor delegate =
            SecurityMockMvcRequestPostProcessors
// Path: wechat-mp-autoconfigure/src/main/java/com/github/hippoom/wechat/mp/security/authentication/WeChatMpOAuth2AccessTokenAuthentication.java
// public class WeChatMpOAuth2AccessTokenAuthentication implements Authentication {
// 
//     private final WxMpOAuth2AccessToken accessToken;
// 
//     public WeChatMpOAuth2AccessTokenAuthentication(WxMpOAuth2AccessToken accessToken) {
//         this.accessToken = accessToken;
//     }
// 
//     @Override
//     public Collection<? extends GrantedAuthority> getAuthorities() {
//         return Collections.emptyList();
//     }
// 
//     @Override
//     public Object getCredentials() {
//         return null;
//     }
// 
//     @Override
//     public Object getDetails() {
//         return getOpenId();
//     }
// 
//     @Override
//     public Object getPrincipal() {
//         return getOpenId();
//     }
// 
//     @Override
//     public boolean isAuthenticated() {
//         return true;
//     }
// 
//     @Override
//     public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
// 
//     }
// 
//     @Override
//     public String getName() {
//         return accessToken.getOpenId();
//     }
// 
//     public OpenId getOpenId() {
//         return OpenId.valueOf(accessToken.getOpenId());
//     }
// }
// 
// Path: wechat-mp-test/src/main/java/com/github/hippoom/wechat/mp/test/fixture/WxMpOAuth2AccessTokenFixture.java
// public class WxMpOAuth2AccessTokenFixture {
// 
//     private WxMpOAuth2AccessToken target = new WxMpOAuth2AccessToken();
// 
//     private WxMpOAuth2AccessTokenFixture() {
//         target.setOpenId(OpenId.valueOf(UUID.randomUUID().toString()).getValue());
//         target.setAccessToken("accessToken");
//         target.setRefreshToken("refreshToken");
//         target.setExpiresIn(3600);
//         target.setScope("snsapi_base");
//     }
// 
//     /**
//      * Customize the {@link OpenId}.
//      *
//      * @param openId a custom {@link OpenId}
//      * @return this {@link WxMpOAuth2AccessTokenFixture}
//      */
//     public WxMpOAuth2AccessTokenFixture with(OpenId openId) {
//         target.setOpenId(openId.getValue());
//         return this;
//     }
// 
//     /**
//      * Build the {@link WxMpOAuth2AccessToken}.
//      *
//      * @return this {@link WxMpOAuth2AccessToken}
//      */
//     public WxMpOAuth2AccessToken build() {
//         return target;
//     }
// 
//     /**
//      * Static factory method for {@link WxMpOAuth2AccessTokenFixture}.
//      *
//      * @return a {@link WxMpOAuth2AccessTokenFixture} with default values
//      */
//     public static WxMpOAuth2AccessTokenFixture aWxMpOAuth2AccessToken() {
//         return new WxMpOAuth2AccessTokenFixture();
//     }
// }
// 
// Path: wechat-mp-autoconfigure/src/main/java/com/github/hippoom/wechat/oauth/OpenId.java
// @Value
// public class OpenId {
// 
//     private String value;
// 
//     private OpenId(String value) {
//         this.value = value;
//     }
// 
//     public static OpenId valueOf(String value) {
//         return new OpenId(value);
//     }
// }


// Path: wechat-mp-test/src/main/java/com/github/hippoom/wechat/mp/test/web/servlet/request/WxMpOAuth2AccessTokenRequestPostProcessor.java
import com.github.hippoom.wechat.mp.security.authentication.WeChatMpOAuth2AccessTokenAuthentication;
import com.github.hippoom.wechat.mp.test.fixture.WxMpOAuth2AccessTokenFixture;
import com.github.hippoom.wechat.oauth.OpenId;
import java.util.UUID;
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors;
import org.springframework.test.web.servlet.request.RequestPostProcessor;

package com.github.hippoom.wechat.mp.test.web.servlet.request;


// @formatter:off
/**
 * Test fixture for {@link WxMpOAuth2AccessTokenFixture}.
 * <pre class="code">
 *
 * import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
 * import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
 * import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
 * import static com.github.hippoom.wechat.mp.test.web.servlet.request
 *     .WxMpOAuth2AccessTokenRequestPostProcessor.aWeChatMpUser;
 *
 * &#064;Test public void returns_wechat_user_profile() {
 *     this.mockMvc.perform(
 *         get("/rel/wechat/user/profile/me").with(aWeChatMpUser().withOpenId(userProfile.openId))
 *     ).andDo(print()).andExpect(status().isOk());
 * }
 *
 * </pre>
 *
 * @see RequestPostProcessor
 * @since 0.3.0
 */
//@formatter:on
public class WxMpOAuth2AccessTokenRequestPostProcessor implements RequestPostProcessor {

    private OpenId openId = OpenId.valueOf(UUID.randomUUID().toString());

    /**
     * Customize the {@link OpenId}.
     *
     * @param openId a custom {@link OpenId}
     * @return this {@link WxMpOAuth2AccessTokenRequestPostProcessor}
     */
    public WxMpOAuth2AccessTokenRequestPostProcessor with(OpenId openId) {
        this.openId = openId;
        return this;
    }

    /**
     * Customize the {@link OpenId}.
     *
     * @param openId a custom {@link OpenId} value
     * @return this {@link WxMpOAuth2AccessTokenRequestPostProcessor}
     */
    public WxMpOAuth2AccessTokenRequestPostProcessor withOpenId(String openId) {
        return with(OpenId.valueOf(openId));
    }

    @Override
    public MockHttpServletRequest postProcessRequest(
        MockHttpServletRequest mockHttpServletRequest) {
        WxMpOAuth2AccessToken accessToken = WxMpOAuth2AccessTokenFixture.aWxMpOAuth2AccessToken()
            .with(openId).build();
        RequestPostProcessor delegate =
            SecurityMockMvcRequestPostProcessors
                .authentication(new WeChatMpOAuth2AccessTokenAuthentication(accessToken));