Moved SQL test to test source set; integration tests now appear to work
parent
eaf7822731
commit
7bb9172707
|
@ -4,7 +4,9 @@ import java.sql.DriverManager;
|
|||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
@ -13,8 +15,12 @@ import javax.ws.rs.GET;
|
|||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import com.google.protobuf.Message;
|
||||
import meerkat.protobuf.BulletinBoardServer;
|
||||
import meerkat.protobuf.Bulletinboardserver;
|
||||
import meerkat.protobuf.Voting.MessageFilterList;
|
||||
import meerkat.rest.Constants;
|
||||
import meerkat.bulletinboard.sqlserver.BulletinBoardSQLServer;
|
||||
|
@ -98,13 +104,23 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer {
|
|||
|
||||
}
|
||||
|
||||
// @POST
|
||||
@Consumes(Constants.MEDIATYPE_PROTOBUF)
|
||||
@Override
|
||||
public boolean postMessage(BulletinBoardMessage msg) throws CommunicationException {
|
||||
return super.postMessage(msg);
|
||||
}
|
||||
|
||||
|
||||
@POST
|
||||
@Consumes(Constants.MEDIATYPE_PROTOBUF)
|
||||
@Produces(Constants.MEDIATYPE_PROTOBUF)
|
||||
public Message doPostMessage(BulletinBoardMessage msg)throws CommunicationException {
|
||||
boolean result = super.postMessage(msg);
|
||||
|
||||
return BulletinBoardServer.Boolean.newBuilder()
|
||||
.setValue(result)
|
||||
.build();
|
||||
}
|
||||
|
||||
// @GET
|
||||
@Consumes(Constants.MEDIATYPE_PROTOBUF)
|
||||
@Produces(Constants.MEDIATYPE_PROTOBUF)
|
||||
|
@ -114,8 +130,9 @@ public class SQLiteBulletinBoardServer extends BulletinBoardSQLServer {
|
|||
}
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public String test() {
|
||||
return "hello";
|
||||
return "Hello World";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class HelloProtoWebApp {
|
|||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// helloProtoBuf = new HelloProtoBuf();
|
||||
helloProtoBuf = new HelloProtoBuf();
|
||||
}
|
||||
|
||||
@GET
|
||||
|
|
|
@ -1,82 +0,0 @@
|
|||
package meerkat.bulletinboard.webapp;
|
||||
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import meerkat.rest.Constants;
|
||||
import meerkat.rest.Constants.*;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import meerkat.bulletinboard.sqlserver.SQLiteBulletinBoardServer;
|
||||
import meerkat.comm.CommunicationException;
|
||||
import meerkat.protobuf.Crypto.*;
|
||||
import meerkat.protobuf.Voting.*;
|
||||
import meerkat.rest.*;
|
||||
|
||||
@Path("/test")
|
||||
public class SQLiteServerTest {
|
||||
|
||||
private static String PROP_GETTY_URL = "gretty.httpBaseURI";
|
||||
private static String BASE_URL = "http://localhost:8081";//System.getProperty(PROP_GETTY_URL);
|
||||
private static String SQL_SERVER_URL = BASE_URL + "/SQLServer";
|
||||
|
||||
@GET
|
||||
public Response main(){
|
||||
byte[] b1 = {(byte) 1, (byte)2, (byte) 3, (byte) 4};
|
||||
byte[] b2 = {(byte) 11, (byte)12, (byte) 13, (byte) 14};
|
||||
byte[] b3 = {(byte) 21, (byte)22, (byte) 23, (byte) 24};
|
||||
|
||||
Response response;
|
||||
|
||||
BulletinBoardMessage msg;
|
||||
try{
|
||||
msg = BulletinBoardMessage.newBuilder()
|
||||
.setMsg(UnsignedBulletinBoardMessage.newBuilder()
|
||||
.addTags("Signature")
|
||||
.addTags("Trustee")
|
||||
.setData(ByteString.copyFrom(b1))
|
||||
.build())
|
||||
.setSig(Signature.newBuilder()
|
||||
.setType(SignatureType.DSA)
|
||||
.setData(ByteString.copyFrom(b2))
|
||||
.setSignerId(ByteString.copyFrom(b3))
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// SQLiteBulletinBoardServer bbs = new SQLiteBulletinBoardServer();
|
||||
//
|
||||
//
|
||||
// bbs.init();
|
||||
//
|
||||
// bbs.postMessage(msg);
|
||||
// response = Response.status(Status.OK).entity(bbs.testPrint()).build();
|
||||
//
|
||||
// bbs.close();
|
||||
|
||||
|
||||
|
||||
Client client = ClientBuilder.newClient()
|
||||
.register(ProtobufMessageBodyWriter.class)
|
||||
.register(ProtobufMessageBodyWriter.class);
|
||||
WebTarget webTarget = client.target(SQL_SERVER_URL);
|
||||
response = webTarget.request(MediaType.TEXT_HTML).post(Entity.entity(msg, Constants.MEDIATYPE_PROTOBUF));
|
||||
|
||||
} catch(Exception e){
|
||||
response = Response.status(Status.OK).entity(e.getMessage()).build();;
|
||||
}
|
||||
|
||||
// response = Response.status(Status.OK).entity("OK").build();
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
syntax = "proto3";
|
||||
|
||||
package meerkat;
|
||||
|
||||
option java_package = "meerkat.protobuf";
|
||||
|
||||
message Boolean {
|
||||
bool value = 1;
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import org.junit.Test;
|
||||
|
||||
public class HelloIntegrationTest {
|
||||
|
||||
private static String PROP_GETTY_URL = "gretty.httpBaseURI";
|
||||
private static String BASE_URL = System.getProperty(PROP_GETTY_URL);
|
||||
private static String HELLO_URL = BASE_URL + "/hello";
|
||||
|
||||
@Test
|
||||
public void testHello() throws Exception {
|
||||
Client client = ClientBuilder.newClient();
|
||||
WebTarget webTarget = client.target(HELLO_URL);
|
||||
String response = webTarget.request().get(String.class);
|
||||
System.out.println(response);
|
||||
assertThat(response, is("Hello, World!"));
|
||||
}
|
||||
}
|
|
@ -17,10 +17,10 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
|||
* Created by talm on 10/11/15.
|
||||
*/
|
||||
public class HelloProtoIntegrationTest {
|
||||
|
||||
private static String PROP_GETTY_URL = "gretty.httpBaseURI";
|
||||
private static String BASE_URL = System.getProperty(PROP_GETTY_URL);
|
||||
private static String HELLO_URL = BASE_URL + "/proto";
|
||||
private static String DEFAULT_BASE_URL = "http://localhost:8081/";
|
||||
private static String BASE_URL = System.getProperty(PROP_GETTY_URL, DEFAULT_BASE_URL);
|
||||
private static String HELLO_URL = "proto";
|
||||
|
||||
@Test
|
||||
public void testHello() throws Exception {
|
||||
|
@ -28,8 +28,9 @@ public class HelloProtoIntegrationTest {
|
|||
client.register(ProtobufMessageBodyReader.class);
|
||||
client.register(ProtobufMessageBodyWriter.class);
|
||||
|
||||
WebTarget webTarget = client.target(HELLO_URL);
|
||||
Voting.BulletinBoardMessage response = webTarget.request(Constants.MEDIATYPE_PROTOBUF).get(Voting.BulletinBoardMessage.class);
|
||||
WebTarget webTarget = client.target(BASE_URL).path(HELLO_URL);
|
||||
Voting.BulletinBoardMessage response = webTarget.request(Constants.MEDIATYPE_PROTOBUF)
|
||||
.get(Voting.BulletinBoardMessage.class);
|
||||
|
||||
System.out.println(response.getMsg().getData());
|
||||
|
||||
|
|
|
@ -0,0 +1,75 @@
|
|||
package meerkat.bulletinboard;
|
||||
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
import meerkat.protobuf.Crypto.Signature;
|
||||
import meerkat.protobuf.Crypto.SignatureType;
|
||||
import meerkat.protobuf.Voting.BulletinBoardMessage;
|
||||
import meerkat.protobuf.Voting.UnsignedBulletinBoardMessage;
|
||||
import meerkat.rest.Constants;
|
||||
import meerkat.rest.ProtobufMessageBodyReader;
|
||||
import meerkat.rest.ProtobufMessageBodyWriter;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.ws.rs.client.Client;
|
||||
import javax.ws.rs.client.ClientBuilder;
|
||||
import javax.ws.rs.client.Entity;
|
||||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
public class SQLiteServerIntegrationTest {
|
||||
|
||||
private static String PROP_GETTY_URL = "gretty.httpBaseURI";
|
||||
private static String DEFAULT_BASE_URL = "http://localhost:8081/";
|
||||
private static String BASE_URL = System.getProperty(PROP_GETTY_URL, DEFAULT_BASE_URL);
|
||||
private static String SQL_SERVER_URL = "SQLServer";
|
||||
|
||||
Client client;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
client = ClientBuilder.newClient();
|
||||
client.register(ProtobufMessageBodyReader.class);
|
||||
client.register(ProtobufMessageBodyWriter.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPost() throws Exception {
|
||||
byte[] b1 = {(byte) 1, (byte) 2, (byte) 3, (byte) 4};
|
||||
byte[] b2 = {(byte) 11, (byte) 12, (byte) 13, (byte) 14};
|
||||
byte[] b3 = {(byte) 21, (byte) 22, (byte) 23, (byte) 24};
|
||||
|
||||
Response response;
|
||||
|
||||
BulletinBoardMessage msg;
|
||||
|
||||
msg = BulletinBoardMessage.newBuilder()
|
||||
.setMsg(UnsignedBulletinBoardMessage.newBuilder()
|
||||
.addTags("Signature")
|
||||
.addTags("Trustee")
|
||||
.setData(ByteString.copyFrom(b1))
|
||||
.build())
|
||||
.setSig(Signature.newBuilder()
|
||||
.setType(SignatureType.DSA)
|
||||
.setData(ByteString.copyFrom(b2))
|
||||
.setSignerId(ByteString.copyFrom(b3))
|
||||
.build())
|
||||
.build();
|
||||
|
||||
// SQLiteBulletinBoardServer bbs = new SQLiteBulletinBoardServer();
|
||||
//
|
||||
//
|
||||
// bbs.init();
|
||||
//
|
||||
// bbs.postMessage(msg);
|
||||
// response = Response.status(Status.OK).entity(bbs.testPrint()).build();
|
||||
//
|
||||
// bbs.close();
|
||||
|
||||
System.err.println("******** Testing: " + SQL_SERVER_URL);
|
||||
WebTarget webTarget = client.target(BASE_URL).path(SQL_SERVER_URL);
|
||||
response = webTarget.request(Constants.MEDIATYPE_PROTOBUF).post(Entity.entity(msg, Constants.MEDIATYPE_PROTOBUF));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue