Add Unit Test System & Fix player details
This commit is contained in:
parent
d3c9ad22e5
commit
f23e139b9f
12 changed files with 242 additions and 27 deletions
|
@ -2,6 +2,7 @@
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
|
||||||
<classpathentry kind="src" path="src"/>
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="src" path="test"/>
|
||||||
<classpathentry exported="true" kind="lib" path="json-simple-1.1.1.jar"/>
|
<classpathentry exported="true" kind="lib" path="json-simple-1.1.1.jar"/>
|
||||||
<classpathentry exported="true" kind="lib" path="mysql-connector-java-8.0.28.jar"/>
|
<classpathentry exported="true" kind="lib" path="mysql-connector-java-8.0.28.jar"/>
|
||||||
<classpathentry exported="true" kind="lib" path="password4j-1.6.3.jar"/>
|
<classpathentry exported="true" kind="lib" path="password4j-1.6.3.jar"/>
|
||||||
|
|
|
@ -3,27 +3,14 @@ package be.jeffcheasey88.peeratcode;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.net.ssl.SSLServerSocket;
|
import javax.net.ssl.SSLServerSocket;
|
||||||
import javax.net.ssl.SSLServerSocketFactory;
|
import javax.net.ssl.SSLServerSocketFactory;
|
||||||
|
|
||||||
import org.jose4j.jwa.AlgorithmConstraints.ConstraintType;
|
|
||||||
import org.jose4j.jwk.JsonWebKey;
|
|
||||||
import org.jose4j.jwk.PublicJsonWebKey;
|
|
||||||
import org.jose4j.jwk.RsaJsonWebKey;
|
import org.jose4j.jwk.RsaJsonWebKey;
|
||||||
import org.jose4j.jwk.RsaJwkGenerator;
|
import org.jose4j.jwk.RsaJwkGenerator;
|
||||||
import org.jose4j.jws.AlgorithmIdentifiers;
|
|
||||||
import org.jose4j.jws.JsonWebSignature;
|
|
||||||
import org.jose4j.jwt.JwtClaims;
|
|
||||||
import org.jose4j.jwt.consumer.ErrorCodes;
|
|
||||||
import org.jose4j.jwt.consumer.InvalidJwtException;
|
|
||||||
import org.jose4j.jwt.consumer.JwtConsumer;
|
|
||||||
import org.jose4j.jwt.consumer.JwtConsumerBuilder;
|
|
||||||
import org.jose4j.lang.JoseException;
|
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
import be.jeffcheasey88.peeratcode.repository.DatabaseRepository;
|
||||||
import be.jeffcheasey88.peeratcode.routes.BadgeDetails;
|
import be.jeffcheasey88.peeratcode.routes.BadgeDetails;
|
||||||
|
|
|
@ -34,22 +34,31 @@ public class Class {
|
||||||
content = matcher.group(3);
|
content = matcher.group(3);
|
||||||
Pattern empty = Pattern.compile("^\\s*$");
|
Pattern empty = Pattern.compile("^\\s*$");
|
||||||
while(!(empty.matcher(content).matches())){
|
while(!(empty.matcher(content).matches())){
|
||||||
int quotes = content.indexOf(';');
|
int quotes = indexOf(content,";");
|
||||||
int braces = content.indexOf('{');
|
int braces = indexOf(content,"\\{");
|
||||||
int equals = content.indexOf('=');
|
int equals = indexOf(content,"=");
|
||||||
if(quotes < braces && quotes < equals){
|
if(quotes < braces && quotes < equals){
|
||||||
Variable variable = new Variable();
|
Variable variable = new Variable();
|
||||||
int index = variable.parse(content);
|
int index = variable.parse(content);
|
||||||
this.vars.add(variable);
|
this.vars.add(variable);
|
||||||
content = content.substring(index);
|
content = content.substring(index);
|
||||||
}else if(equals >= 0 && equals < braces){
|
}else if(equals < braces){
|
||||||
//variable with value
|
//variable with value
|
||||||
System.out.println(content);
|
System.out.println(content);
|
||||||
System.out.println("equals < braces");
|
System.out.println("equals < braces");
|
||||||
Variable variable = new Variable();
|
boolean quote = false;
|
||||||
int index = variable.parse(content);
|
Variable last = null;
|
||||||
this.vars.add(variable);
|
do {
|
||||||
content = content.substring(index);
|
Variable variable = (last == null) ? new Variable() : new Variable(last.getModifier(), last.getType());
|
||||||
|
int index = variable.parse(content);
|
||||||
|
this.vars.add(variable);
|
||||||
|
content = content.substring(index);
|
||||||
|
quote = content.startsWith(",");
|
||||||
|
if(quote) {
|
||||||
|
content = content.substring(1);
|
||||||
|
last = variable;
|
||||||
|
}
|
||||||
|
}while(quote);
|
||||||
break;
|
break;
|
||||||
}else{
|
}else{
|
||||||
Function func = new Function();
|
Function func = new Function();
|
||||||
|
@ -62,6 +71,10 @@ public class Class {
|
||||||
return matcher.group(1).length();
|
return matcher.group(1).length();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int indexOf(String value, String target){
|
||||||
|
return value.split(target)[0].length();
|
||||||
|
}
|
||||||
|
|
||||||
public int getModifier(){
|
public int getModifier(){
|
||||||
return this.modifier;
|
return this.modifier;
|
||||||
}
|
}
|
||||||
|
@ -70,6 +83,10 @@ public class Class {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Variable> getVariables(){
|
||||||
|
return this.vars;
|
||||||
|
}
|
||||||
|
|
||||||
public void show(){
|
public void show(){
|
||||||
System.out.println(Modifier.toString(modifier)+" "+this.name+"{");
|
System.out.println(Modifier.toString(modifier)+" "+this.name+"{");
|
||||||
for(Variable v : this.vars) v.show(1);
|
for(Variable v : this.vars) v.show(1);
|
||||||
|
|
|
@ -15,6 +15,11 @@ public class Variable {
|
||||||
|
|
||||||
public Variable(){}
|
public Variable(){}
|
||||||
|
|
||||||
|
public Variable(int modifier, String type){
|
||||||
|
this.modifier = modifier;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
//int i = 4;
|
//int i = 4;
|
||||||
//int i,j,k,l=1;
|
//int i,j,k,l=1;
|
||||||
//int lm ;
|
//int lm ;
|
||||||
|
@ -28,6 +33,8 @@ public class Variable {
|
||||||
System.out.println(content);
|
System.out.println(content);
|
||||||
Matcher matcher = PATTERN.matcher(content);
|
Matcher matcher = PATTERN.matcher(content);
|
||||||
matcher.matches();
|
matcher.matches();
|
||||||
|
|
||||||
|
int offset = matcher.group(1).length();
|
||||||
|
|
||||||
boolean hasEquals = false;
|
boolean hasEquals = false;
|
||||||
boolean fromMinus = false;
|
boolean fromMinus = false;
|
||||||
|
@ -47,21 +54,25 @@ public class Variable {
|
||||||
if(value.isEmpty()){
|
if(value.isEmpty()){
|
||||||
do {
|
do {
|
||||||
body = body.substring(1);
|
body = body.substring(1);
|
||||||
|
offset++;
|
||||||
}while(indexOf(body, "\\s+") == 0);
|
}while(indexOf(body, "\\s+") == 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this.value = new Value(value);
|
this.value = new Value(value);
|
||||||
body = body.substring(value.length()+1);
|
body = body.substring(value.length()+1);
|
||||||
|
offset+=value.length()+1;
|
||||||
break;
|
break;
|
||||||
}else if(fromMinus){
|
}else if(fromMinus){
|
||||||
System.out.println("fromMinus "+value);
|
System.out.println("fromMinus "+value);
|
||||||
this.name = value;
|
this.name = value;
|
||||||
body = body.substring(value.length()+1);
|
body = body.substring(value.length()+1);
|
||||||
|
offset+=value.length()+1;
|
||||||
break;
|
break;
|
||||||
} else if(min == space){
|
} else if(min == space){
|
||||||
if(value.isEmpty()){
|
if(value.isEmpty()){
|
||||||
do {
|
do {
|
||||||
body = body.substring(1);
|
body = body.substring(1);
|
||||||
|
offset++;
|
||||||
}while(indexOf(body, "\\s+") == 0);
|
}while(indexOf(body, "\\s+") == 0);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -76,9 +87,12 @@ public class Variable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
body = body.substring(value.length()+1);
|
body = body.substring(value.length()+1);
|
||||||
|
offset+=value.length()+1;
|
||||||
}else if(min == equals){
|
}else if(min == equals){
|
||||||
|
if(this.name == null) this.name = value;
|
||||||
hasEquals = true;
|
hasEquals = true;
|
||||||
body = body.substring(value.length()+1);
|
body = body.substring(value.length()+1);
|
||||||
|
offset+=value.length()+1;
|
||||||
}else if(min == minus){
|
}else if(min == minus){
|
||||||
value = value+"<";
|
value = value+"<";
|
||||||
System.out.println("MINUS");
|
System.out.println("MINUS");
|
||||||
|
@ -95,16 +109,21 @@ public class Variable {
|
||||||
}
|
}
|
||||||
this.type = value;
|
this.type = value;
|
||||||
body = body.substring(value.length());
|
body = body.substring(value.length());
|
||||||
|
offset+=value.length();
|
||||||
while(indexOf(body, "\\s+") == 0){
|
while(indexOf(body, "\\s+") == 0){
|
||||||
body = body.substring(1);
|
body = body.substring(1);
|
||||||
|
offset++;
|
||||||
}
|
}
|
||||||
fromMinus = true;
|
fromMinus = true;
|
||||||
System.out.println("fromMinus on "+body);
|
System.out.println("fromMinus on "+body);
|
||||||
}else if(min == quote){
|
}else if(min == quote){
|
||||||
|
if(this.name != null) break;
|
||||||
this.name = value;
|
this.name = value;
|
||||||
body = body.substring(value.length());
|
body = body.substring(value.length());
|
||||||
|
offset+=value.length();
|
||||||
break;
|
break;
|
||||||
}else {
|
}else {
|
||||||
|
offset+=value.length()+1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +132,7 @@ public class Variable {
|
||||||
show(0);
|
show(0);
|
||||||
System.out.println("-------------");
|
System.out.println("-------------");
|
||||||
|
|
||||||
return 1;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int indexOf(String value, String target){
|
private int indexOf(String value, String target){
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class PlayerDetails implements Response {
|
||||||
@Override
|
@Override
|
||||||
public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception {
|
public void exec(Matcher matcher, User user, HttpReader reader, HttpWriter writer) throws Exception {
|
||||||
Player player;
|
Player player;
|
||||||
if (matcher.groupCount() > 0) {
|
if (matcher.group(1) != null){
|
||||||
player = databaseRepo.getPlayerDetails(matcher.group(1));
|
player = databaseRepo.getPlayerDetails(matcher.group(1));
|
||||||
} else {
|
} else {
|
||||||
player = databaseRepo.getPlayerDetails(user.getId());
|
player = databaseRepo.getPlayerDetails(user.getId());
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class Client extends Thread{
|
||||||
}
|
}
|
||||||
|
|
||||||
private User isLogin(HttpReader reader) throws Exception{
|
private User isLogin(HttpReader reader) throws Exception{
|
||||||
String auth = HttpUtil.readAutorization(reader);
|
String auth = HttpUtil.readAuthorization(reader);
|
||||||
if(auth == null) return null;
|
if(auth == null) return null;
|
||||||
try {
|
try {
|
||||||
JwtConsumer jwtConsumer = new JwtConsumerBuilder()
|
JwtConsumer jwtConsumer = new JwtConsumerBuilder()
|
||||||
|
@ -54,6 +54,7 @@ public class Client extends Thread{
|
||||||
JwtClaims jwtClaims = jwtConsumer.processToClaims(auth);
|
JwtClaims jwtClaims = jwtConsumer.processToClaims(auth);
|
||||||
return new User(jwtClaims);
|
return new User(jwtClaims);
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
|
e.printStackTrace();
|
||||||
HttpUtil.responseHeaders(writer, 401, "Access-Control-Allow-Origin: *");
|
HttpUtil.responseHeaders(writer, 401, "Access-Control-Allow-Origin: *");
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -74,9 +74,9 @@ public class HttpUtil {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Pattern AUTORIZATION = Pattern.compile("Autorization: Bearer (.*)");
|
private static Pattern AUTORIZATION = Pattern.compile("Authorization: Bearer (.*)");
|
||||||
|
|
||||||
public static String readAutorization(HttpReader reader) throws Exception {
|
public static String readAuthorization(HttpReader reader) throws Exception {
|
||||||
String line;
|
String line;
|
||||||
String key = null;
|
String key = null;
|
||||||
while(((line = reader.readLine()) != null) && (line.length() > 0)){
|
while(((line = reader.readLine()) != null) && (line.length() > 0)){
|
||||||
|
|
|
@ -73,6 +73,8 @@ public class Router{
|
||||||
|
|
||||||
claims.setClaim("id", id);
|
claims.setClaim("id", id);
|
||||||
|
|
||||||
|
claims.setSubject("Nani ???");
|
||||||
|
|
||||||
JsonWebSignature jws = new JsonWebSignature();
|
JsonWebSignature jws = new JsonWebSignature();
|
||||||
jws.setPayload(claims.toJson());
|
jws.setPayload(claims.toJson());
|
||||||
jws.setKey(rsaJsonWebKey.getPrivateKey());
|
jws.setKey(rsaJsonWebKey.getPrivateKey());
|
||||||
|
|
|
@ -7,7 +7,7 @@ public class User {
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
public User(JwtClaims jwtClaims){
|
public User(JwtClaims jwtClaims){
|
||||||
this.id = (int) jwtClaims.getClaimValue("id");
|
this.id = ((Long)jwtClaims.getClaimValue("id")).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId(){
|
public int getId(){
|
||||||
|
|
|
@ -4,6 +4,8 @@ import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import be.jeffcheasey88.peeratcode.parser.java.Variable.Value;
|
import be.jeffcheasey88.peeratcode.parser.java.Variable.Value;
|
||||||
|
@ -92,4 +94,55 @@ class VariableTest {
|
||||||
fail(e);
|
fail(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case6(){
|
||||||
|
try {
|
||||||
|
Class clazz = new Class();
|
||||||
|
clazz.parse("public class Test{ int i ,j,k,l=1; } ");
|
||||||
|
|
||||||
|
List<Variable> vars = clazz.getVariables();
|
||||||
|
assertEquals(vars.size(), 4);
|
||||||
|
for(int i = 0; i < 3; i++){
|
||||||
|
Variable v = vars.get(i);
|
||||||
|
assertEquals(0, v.getModifier());
|
||||||
|
assertEquals("int", v.getType());
|
||||||
|
assertEquals((char)('i'+i), v.getName().charAt(0));
|
||||||
|
assertNull(v.getValue());
|
||||||
|
}
|
||||||
|
Variable v = vars.get(3);
|
||||||
|
assertEquals(0, v.getModifier());
|
||||||
|
assertEquals("int", v.getType());
|
||||||
|
assertEquals('l', v.getName().charAt(0));
|
||||||
|
assertEquals("1", ((Value)v.getValue()).value());
|
||||||
|
}catch(Exception e){
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void case7(){
|
||||||
|
try {
|
||||||
|
Class clazz = new Class();
|
||||||
|
clazz.parse("public class Test{ int i =j=k=l=4; } ");
|
||||||
|
|
||||||
|
List<Variable> vars = clazz.getVariables();
|
||||||
|
assertEquals(vars.size(), 4);
|
||||||
|
for(int i = 0; i < 3; i++){
|
||||||
|
Variable v = vars.get(i);
|
||||||
|
assertEquals(0, v.getModifier());
|
||||||
|
assertEquals("int", v.getType());
|
||||||
|
assertEquals((char)('i'+i), v.getName().charAt(0));
|
||||||
|
assertEquals((char)('i'+i+1), ((Value)v.getValue()).value());
|
||||||
|
}
|
||||||
|
Variable v = vars.get(3);
|
||||||
|
assertEquals(0, v.getModifier());
|
||||||
|
assertEquals("int", v.getType());
|
||||||
|
assertEquals('l', v.getName().charAt(0));
|
||||||
|
assertEquals("4", ((Value)v.getValue()).value());
|
||||||
|
}catch(Exception e){
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -0,0 +1,53 @@
|
||||||
|
package be.jeffcheasey88.peeratcode.routes;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.AfterAll;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.TestInstance;
|
||||||
|
import org.junit.jupiter.api.TestInstance.Lifecycle;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.Main;
|
||||||
|
import be.jeffcheasey88.peeratcode.webclient.WebClient;
|
||||||
|
|
||||||
|
@TestInstance(Lifecycle.PER_CLASS)
|
||||||
|
class PlayerDetailsTests {
|
||||||
|
|
||||||
|
private Thread server;
|
||||||
|
private WebClient client;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
void init(){
|
||||||
|
server = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
try {
|
||||||
|
Main.main(null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
server.start();
|
||||||
|
client = new WebClient("localhost", 80);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterAll
|
||||||
|
void close(){
|
||||||
|
server.interrupt();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void test(){
|
||||||
|
try {
|
||||||
|
client.auth("JeffCheasey88", "TheoPueDesPieds");
|
||||||
|
client.route("/player/","GET");
|
||||||
|
|
||||||
|
client.assertResponseCode(200);
|
||||||
|
} catch (Exception e){
|
||||||
|
fail(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
82
test/be/jeffcheasey88/peeratcode/webclient/WebClient.java
Normal file
82
test/be/jeffcheasey88/peeratcode/webclient/WebClient.java
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
package be.jeffcheasey88.peeratcode.webclient;
|
||||||
|
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
|
||||||
|
import be.jeffcheasey88.peeratcode.webserver.HttpReader;
|
||||||
|
import be.jeffcheasey88.peeratcode.webserver.HttpWriter;
|
||||||
|
|
||||||
|
public class WebClient {
|
||||||
|
|
||||||
|
private static Pattern AUTORIZATION = Pattern.compile("Authorization: Bearer (.*)");
|
||||||
|
|
||||||
|
private Socket socket;
|
||||||
|
private HttpReader reader;
|
||||||
|
private HttpWriter writer;
|
||||||
|
|
||||||
|
private String token;
|
||||||
|
private int responseCode;
|
||||||
|
private List<String> headers;
|
||||||
|
|
||||||
|
private String host;
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
public WebClient(String host, int port){
|
||||||
|
this.host = host;
|
||||||
|
this.port = port;
|
||||||
|
this.headers = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureConnection() throws Exception{
|
||||||
|
this.socket = new Socket(this.host, this.port);
|
||||||
|
this.reader = new HttpReader(socket);
|
||||||
|
this.writer = new HttpWriter(socket);
|
||||||
|
this.responseCode = -1;
|
||||||
|
this.headers.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void auth(String user, String password) throws Exception{
|
||||||
|
JSONObject login = new JSONObject();
|
||||||
|
login.put("pseudo", user);
|
||||||
|
login.put("passwd", password);
|
||||||
|
route("/login", "POST", login.toJSONString());
|
||||||
|
|
||||||
|
for(String line : this.headers){
|
||||||
|
Matcher matcher = AUTORIZATION.matcher(line);
|
||||||
|
if(matcher.matches()){
|
||||||
|
this.token = matcher.group(1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void route(String route, String type, String... content) throws Exception{
|
||||||
|
ensureConnection();
|
||||||
|
this.writer.write(type+" "+route+" HTTP/1.1\n");
|
||||||
|
if(this.token != null) this.writer.write("Authorization: Bearer "+this.token+"\n");
|
||||||
|
|
||||||
|
this.writer.write("\n");
|
||||||
|
for(String value : content) this.writer.write(value+"\n");
|
||||||
|
this.writer.flush();
|
||||||
|
|
||||||
|
this.responseCode = Integer.parseInt(this.reader.readLine().split("\\s+")[1]);
|
||||||
|
String line;
|
||||||
|
while(((line = reader.readLine()) != null) && line.length() > 0) this.headers.add(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void assertResponseCode(int expected){
|
||||||
|
try {
|
||||||
|
if(expected != responseCode) fail("Expected http reponse code <"+expected+"> but found <"+responseCode+">");
|
||||||
|
} catch (Exception e){
|
||||||
|
fail("Failed to get the response code: "+e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue