Skip to content

Commit

Permalink
Progress on ServerTests, now grabs specs from server
Browse files Browse the repository at this point in the history
  • Loading branch information
RetroHack committed Mar 24, 2015
1 parent 632c2a6 commit 705ca88
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 26 deletions.
56 changes: 31 additions & 25 deletions JavaTests/Test/ControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
import FileSystem.FileAccess;
import ServerClientShared.FieldWithContent;
import ServerClientShared.FieldWithoutContent;
import ServerClientShared.ImageFieldWithContent;
import ServerClientShared.ImageFieldWithoutContent;
import ServerClientShared.Incident;
import ServerClientShared.StringFieldWithContent;
import ServerClientShared.StringFieldWithoutContent;
import java.net.URISyntaxException;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -86,9 +90,11 @@ public void getFormSpecTest()
System.out.println("Database connection failed");
}

//TODO
//ArrayList<FieldWithoutContent> testSpec=SocketStuff.doStuff(testChannel, testOwner);
//int i=5;
//Using Sockets, actually grab the spec for march13 and check if it is right.
ArrayList<FieldWithoutContent> testSpec=SocketStuff.getSpec(testChannel, testOwner);
assertTrue(testSpec.get(0) instanceof StringFieldWithoutContent);
assertTrue(testSpec.get(1) instanceof ImageFieldWithoutContent);
int i=5;

}

Expand All @@ -109,35 +115,35 @@ public void postThings()
try
{
DBAccess dbTest= new DBAccess();
assertTrue(dbTest.getFormSpecLocation(testChannel, testOwner).equals("okenso.4"));
//FileAccess fAccess= new FileAccess();

//Safety Test so we can send a valid post. If something changes in the testchannel, this should make
//the test fail before it can submit invalid posts.
//String fileName = dbAccess.getFormSpecLocation(testChannel, testOwner); //get spec's file name in filesystem
//ArrayList<FieldWithoutContent> specList= fAccess.getFormSpec("okenso.4"); //retreive form spec
//int postNum = dbAccess.newPost(testChannel, testOwner, "xxLegolasxxYoloxx");


int i=5;

assertTrue(dbTest.getFormSpecLocation(testChannel, testOwner).equals("okenso.4"));
}
catch(SQLException SQLe)
{
throw new RuntimeException("Database initialization failed");

throw new RuntimeException("Database initialization failed");
}
/*catch (URISyntaxException URISe)
{
throw new RuntimeException("Filesystem not consistent, error initializing path");
}*/
//Using Sockets, actually grab the spec for march13 and check if it is right.
ArrayList<FieldWithoutContent> testSpec=SocketStuff.getSpec(testChannel, testOwner);
assertTrue(testSpec.get(0) instanceof StringFieldWithoutContent);
assertTrue(testSpec.get(1) instanceof ImageFieldWithoutContent);


//IN PROGRESS
//Then, create an Incident, then send it to the server.


//ArrayList<FieldWithoutContent> spec=controller.getForm(testChannel, testOwner);
/*StringFieldWithoutContent t1 = new StringFieldWithoutContent("Test Description", true);
StringFieldWithContent stringCon = new StringFieldWithContent(t1);
stringCon.setContent("THIS IS A TEST. DO NOT PANIC");


byte[] image = new byte[]{1,2,4};
ImageFieldWithoutContent t2 = new ImageFieldWithoutContent("Description", true);
ImageFieldWithContent imageCon = new ImageFieldWithContent(t2);
ArrayList<FieldWithContent> filledIncident=new ArrayList();
filledIncident.add(stringCon);
filledIncident.add(imageCon);
Incident testIncident = new Incident(filledIncident,testChannel,testOwner,"xxLegolasxxYoloxx");
SocketStuff.makePost(testIncident);*/
}


Expand Down
43 changes: 42 additions & 1 deletion JavaTests/Test/SocketStuff.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import ServerClientShared.Commands;
import ServerClientShared.FieldWithoutContent;
import ServerClientShared.Incident;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;
import static junit.framework.Assert.assertNotNull;


/**
Expand All @@ -15,7 +17,7 @@
*/
public class SocketStuff
{
public static ArrayList<FieldWithoutContent> doStuff(String channelName,String channelOwner)
public static ArrayList<FieldWithoutContent> getSpec(String channelName,String channelOwner)
{
ObjectOutputStream outStream; //wrapped stream to client
ObjectInputStream inStream; //stream from client
Expand Down Expand Up @@ -72,4 +74,43 @@ public static ArrayList<FieldWithoutContent> doStuff(String channelName,String c
return fieldsToBeFilled;

}

public static void makePost(Incident incidentToSend)
{
ObjectOutputStream outStream; //wrapped stream to client
ObjectInputStream inStream; //stream from client
Socket outSocket;

try //create socket
{
SocketWrapper socketWrapper = new SocketWrapper();
outSocket = socketWrapper.getOutSocket();
outStream = socketWrapper.getOut();
inStream = socketWrapper.getIn();
}
catch(IOException e)
{
throw new RuntimeException("Creating socket error(mP)");
}


try
{
//TODO identify with the server whether I am asking for an incident spec or sending an incident.
System.out.println("Attempting to send incident.");
outStream.writeObject(Commands.IOCommand.SEND_INCIDENT);
outStream.writeObject(incidentToSend);
outStream.flush();
//TODO is a reply really not necessary?

inStream.close();
outStream.close();
outSocket.close();
System.out.println("Connection Closed");
}
catch (IOException e)
{
throw new RuntimeException("Connection failed.(mP)");
}
}
}

0 comments on commit 705ca88

Please sign in to comment.