Show AsynchronousDistributedPersisterTest.java syntax highlighted
package test.planner;
import java.io.File;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import persister.Backlog;
import persister.ConnectionFailedException;
import persister.ForbiddenOperationException;
import persister.IndexCardNotFoundException;
import persister.Iteration;
import persister.NotConnectedException;
import persister.PlannerDataChangeListener;
import persister.Project;
import persister.StoryCard;
import persister.distributed.ClientCommunicator;
import persister.distributed.ServerCommunicator;
import persister.impl.data.BacklogDataObject;
import persister.impl.data.IterationDataObject;
import persister.impl.data.StoryCardDataObject;
public class AsynchronousDistributedPersisterTest extends PersisterTest implements PlannerDataChangeListener {
private static ServerCommunicator server, server5051, server5052;
private ClientCommunicator asynchPers, asynchPers5051EmptyFile, asynchPers5052CompleteFile;
private Object callbackReceived;
private String testMethod;
/***************************************************************************
* SETUP *
**************************************************************************/
@BeforeClass
public static void init() {
try {
System.out.println("Canonical: "+(new File(".")).getCanonicalPath());
resetProjectFiles();
server = new ServerCommunicator("." + File.separator + "TestDirectory" , "ProjectFile", 5050);
server5051 = new ServerCommunicator("." + File.separator + "TestDirectory" , "EmptyProject", 5051);
server5052 = new ServerCommunicator("." + File.separator + "TestDirectory" , "ProjectWithBacklogIterationAndStoryCards", 5052);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@AfterClass
public static void shutdownServer() {
server.disconnect();
}
@Before
public void setUp() {
try {
asynchPers = new ClientCommunicator("localhost", 5050);
asynchPers.addPlannerDataChangeListener(this);
asynchPers5051EmptyFile = new ClientCommunicator("localhost", 5051);
asynchPers5051EmptyFile.addPlannerDataChangeListener(this);
asynchPers5052CompleteFile = new ClientCommunicator("localhost", 5052);
asynchPers5052CompleteFile.addPlannerDataChangeListener(this);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@After
public void tearDown() {
asynchPers.removePlannerDataChangeListener(this);
}
/***************************************************************************
* CONNECTION *
**************************************************************************/
@org.junit.Test
public void testConnect() {
callbackReceived = null;
testMethod = "testConnect";
try {
asynchPers.connect();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Assert.assertEquals("createdProject", callbackReceived);
testMethod = null;
} catch (ConnectionFailedException e) {
e.printStackTrace();
}
}
public void createdProject(Project p) {
callbackReceived = "createdProject";
if (testMethod.equals("testConnect")) {
Assert.assertEquals(testMethod, "testConnect");
Assert.assertEquals(p.getName(), "ProjectFile");
}
else {
//Assert.assertEquals(testMethod, "testLoad");
List<StoryCard> backlogStories = p.getBacklog()
.getStoryCardChildren();
List<Iteration> iterations = p.getIterationChildren();
Assert.assertTrue("Incorrect number os stories in backlog",
backlogStories.size() == 1);
Assert.assertTrue("Incorrect number os stories in backlog",
iterations.size() == 1);
List<StoryCard> iterationStories = p.getIterationChildren()
.iterator().next().getStoryCardChildren();
Assert.assertTrue("Incorrect number os stories in backlog",
iterationStories.size() == 1);
}
}
/****************************************************************************/
@org.junit.Test
public void testLoad() {
testMethod = "testLoad";
callbackReceived = null;
try {
asynchPers.load("ProjectWithBacklogIterationAndStoryCards");
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("createdProject", callbackReceived);
testMethod = null;
}
/*************************************************************************/
// @org.junit.Test
// public void testGetProjectNames() {
// callbackReceived = null;
// asynchPers.getProjectNames();
// Assert.assertEquals(callbackReceived, "gotProjectNames");
// }
//
public void gotProjectNames(List<String> str) {
callbackReceived = "gotProjectNames";
Assert.assertTrue("List of project names has unexpected length", str
.size() == 6);
}
/*******************************************************************/
@org.junit.Test
public void testUndeleteIteration() {
Iteration iteration = new IterationDataObject();
iteration.setId(905);
iteration.setParent(1);
iteration.setName("undeletedIteration");
callbackReceived = null;
testMethod = "testUndeleteIteration";
try {
asynchPers.undeleteIteration(iteration);
} catch (NotConnectedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IndexCardNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (ForbiddenOperationException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("undeletedIteration", callbackReceived);
testMethod = null;
}
public void undeletedIteration(Iteration iteration) {
callbackReceived = "undeletedIteration";
Assert.assertEquals(iteration.getId(), (long) 905);
Assert.assertEquals(iteration.getName(), "undeletedIteration");
}
//
//
// /*********************************************************************/
@org.junit.Test
public void testCreateBacklog() {
callbackReceived = null;
testMethod = "testCreateBacklog";
try {
asynchPers5051EmptyFile.createBacklog(25, 25, 25, 25);
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ForbiddenOperationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("createdBacklog", callbackReceived);
testMethod = null;
}
public void createdBacklog(Backlog backlog) {
callbackReceived = "createdBacklog";
Assert.assertEquals(backlog.getHeight(), 25);
Assert.assertEquals(backlog.getWidth(), 25);
Assert.assertEquals(backlog.getLocationX(), 25);
Assert.assertEquals(backlog.getLocationY(), 25);
}
//
// /**********************************************************************/
//
@org.junit.Test
public void testMoveStoryCardToNewParent() {
callbackReceived = null;
testMethod = "testMoveStoryCardToNewParent";
try {
try {
StoryCard sc = new StoryCardDataObject();
sc.setParent(2);
sc.setId(6);
asynchPers5052CompleteFile.moveStoryCardToNewParent(sc, 4, 50,
50);
} catch (IndexCardNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("movedStoryCardToNewParent", callbackReceived);
testMethod = null;
}
public void movedStoryCardToNewParent(StoryCard storycard) {
callbackReceived = "movedStoryCardToNewParent";
Assert.assertEquals(storycard.getId(), (long) 6);
Assert.assertEquals(storycard.getParent(), (long) 4);
}
///*************************************************************************************/
//
//
@org.junit.Test
public void testCreateStoryCard()
{
callbackReceived = null;
testMethod = "testCreateStoryCard";
try {
//asynchPers.createIteration("iter", "testCreateIterationAsyn", 44, 55, 66, 77, 3, new Timestamp(0), new Timestamp(500000));
try {
asynchPers.createStoryCard("sc", "testCreateStoryCardAsyn", 22, 33, 44, 55, 2, 3, 4, 7, 3, "P");
} catch (IndexCardNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (NotConnectedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("createdStoryCard", callbackReceived);
testMethod = null;
}
public void createdStoryCard(StoryCard storycard) {
callbackReceived = "createdStoryCard";
Assert.assertEquals(storycard.getName(), "sc");
}
//
// /************************************************************************/
//
@org.junit.Test
public void testCreateIteration()
{
callbackReceived = null;
testMethod = "testCreateIteration";
try {
asynchPers.createIteration("iter", "testCreateIterationAsyn", 44, 55, 66, 77, 3, new Timestamp(0), new Timestamp(500000));
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("createdIteration", callbackReceived);
testMethod = null;
}
public void createdIteration(Iteration iteration) {
callbackReceived = "createdIteration";
Assert.assertEquals(iteration.getName(), "iter");
}
//
// /**************************************************************************************/
//
@org.junit.Test
public void testDeleteBacklog()
{
callbackReceived = null;
testMethod = "testDeleteBacklog";
try {
try {
asynchPers.deleteBacklog(2);
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ForbiddenOperationException e) {
Assert.assertTrue("Backlog cannot be deleted", true);
//e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
testMethod = null;
}
public void deletedBacklog(long id) {
Assert.assertTrue("Deleteing a backlog is forbidden but happened", false);
}
// /******************************************************************************/
@org.junit.Test
public void testDeleteIteration()
{
callbackReceived = null;
testMethod = "testDeleteIteration";
try {
try {
asynchPers5052CompleteFile.deleteIteration(4);
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IndexCardNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("deletedIteration", callbackReceived);
testMethod = null;
}
public void deletedIteration(long id) {
callbackReceived = "deletedIteration";
Assert.assertEquals(4, 4);
}
/*******************************************************************/
@org.junit.Test
public void testDeleteStoryCard()
{
callbackReceived = null;
testMethod = "testDeleteStoryCard";
try {
try {
asynchPers5052CompleteFile.deleteStoryCard(6);
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IndexCardNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("deletedStoryCard", callbackReceived);
testMethod = null;
}
public void deletedStoryCard(long id) {
callbackReceived = "deletedStoryCard";
Assert.assertEquals(6, 6);
}
/*******************************************************************/
@org.junit.Test
public void testUndeleteStoryCard()
{
callbackReceived = null;
testMethod = "testUndeleteStoryCard";
StoryCard sc = new StoryCardDataObject();
sc.setId(1000);
sc.setParent(2);
sc.setName("undeletedStoryCard");
try {
try {
asynchPers.undeleteStoryCard(sc);
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IndexCardNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (ForbiddenOperationException e) {
//e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("undeletedStoryCard", callbackReceived);
testMethod = null;
}
public void undeletedStoryCard(StoryCard storyCard) {
callbackReceived = "undeletedStoryCard";
Assert.assertEquals(storyCard.getId(), (long)1000);
Assert.assertEquals(storyCard.getParent(),(long) 2);
}
/*******************************************************************/
@org.junit.Test
public void testUpdateBacklog()
{
callbackReceived = null;
testMethod = "testUpdateBacklog";
Backlog b = new BacklogDataObject(0, 1, 11, 11, 11, 11);
//b.setParent(1);
try {
try {
asynchPers.updateBacklog(b);
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IndexCardNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("updatedBacklog", callbackReceived);
testMethod = null;
}
public void updatedBacklog(Backlog backlog) {
callbackReceived = "updatedBacklog";
Assert.assertEquals(backlog.getLocationX(), 11);
}
/******************************************************************/
@org.junit.Test
public void testUpdateIteration()
{
callbackReceived = null;
testMethod = "testUpdateStoryCard";
Iteration i = new IterationDataObject("updateIteration",
"description empty", 200, 100, 401, 500, (float) 55.0,
new Timestamp(0), new Timestamp(500000));
i.setId(4);
i.setParent(1);
try {
try {
asynchPers5052CompleteFile.updateIteration(i);
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IndexCardNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("updatedIteration", callbackReceived);
testMethod = null;
}
public void updatedIteration(Iteration iteration) {
callbackReceived = "updatedIteration";
Assert.assertEquals(iteration.getWidth(), 200);
Assert.assertEquals(iteration.getHeight(), 100);
}
/**************************************************************************/
@org.junit.Test
public void testUpdateStoryCard()
{
callbackReceived = null;
testMethod = "testUpdateStoryCard";
StoryCard sc = new StoryCardDataObject(2, "testUpdateStoryCard","", 43, 22,
22, 22, 3, 3, 3, 3, "P");
sc.setId(6);
try {
try {
asynchPers5052CompleteFile.updateStoryCard(sc);
} catch (NotConnectedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (IndexCardNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Thread.sleep(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Assert.assertEquals("updatedStoryCard", callbackReceived);
testMethod = null;
}
public void updatedStoryCard(StoryCard storyCard) {
callbackReceived = "updatedStoryCard";
Assert.assertEquals(storyCard.getHeight(), 22);
Assert.assertEquals(storyCard.getWidth(), 43);
}
/*******************************************************************/
// @org.junit.Test
// public void testloadProjectAndCreateIteration()
// {
// callbackReceived = null;
// testMethod = "testloadProjectAndCreateIteration";
//
// try {
// asynchPers.load("ProjectWithBacklogIterationAndStoryCards");
// } catch (NotConnectedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
//
// try {
// asynchPers.createIteration("iter", "testCreateIterationAsyn", 44, 55, 66, 77, 3, new Timestamp(0), new Timestamp(500000));
// } catch (NotConnectedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// try{
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// Assert.assertEquals("createdProject", callbackReceived);
//
// try{
// Thread.sleep(100);
// } catch (InterruptedException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// Assert.assertEquals("createdIteration", callbackReceived);
// testMethod = null;
// }
/************************************************************************/
public void updatedProjectName(Project project) {
// TODO Auto-generated method stub
}
public void projectInXML(String xmlFileContents) {
// TODO Auto-generated method stub
}
public void asynchronousException(Exception exception) {
Assert.fail("Unexpected exception was raised: "+ exception.getMessage() + "\n" + exception.getStackTrace());
}
}
See more files for this project here