代码调整

This commit is contained in:
2023-06-05 15:06:52 +08:00
parent e37fbf4f47
commit 0bfcdfd1b5
3 changed files with 695 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
import com.njcn.web.utils.RestTemplateUtil;
import lombok.SneakyThrows;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.oauth2.common.OAuth2AccessToken;
import org.springframework.security.oauth2.provider.endpoint.TokenEndpoint;
import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI;
/**
* @author hongawen
* @version 1.0.0
* @date 2021年12月14日 12:55
*/
public class AuthTest extends BaseJunitTest {
@Autowired
private TokenEndpoint tokenEndpoint;
@SneakyThrows
@Test
public void test(){
// tokenEndpoint. &client_id=njcn&client_secret=njcnpqs oAuth2AccessToken
System.out.println("hello");
String userUrl = "http://127.0.0.1:10214/oauth/token";
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(userUrl)
.queryParam("grant_type", "password")
.queryParam("client_id", "njcn")
.queryParam("client_secret", "njcnpqs")
.queryParam("username", "root")
.queryParam("password", "@#001njcnpqs");
URI uri = builder.build().encode().toUri();
ResponseEntity<OAuth2AccessToken> userEntity = RestTemplateUtil.post(uri, OAuth2AccessToken.class);
System.out.println(1);
}
}

View File

@@ -0,0 +1,16 @@
import com.njcn.auth.AuthApplication;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.web.WebAppConfiguration;
/**
* @author hongawen
* @version 1.0.0
* @date 2021年12月10日 15:05
*/
@RunWith(SpringRunner.class)
@WebAppConfiguration
@SpringBootTest(classes = AuthApplication.class)
public class BaseJunitTest {
}