11package edu .wpi .grip .core .serialization ;
22
33import com .google .common .eventbus .EventBus ;
4- import com .google .common .eventbus .Subscribe ;
54import com .google .inject .Guice ;
65import com .google .inject .Injector ;
76import com .google .inject .Key ;
87import com .google .inject .TypeLiteral ;
98import edu .wpi .grip .core .*;
10- import edu .wpi .grip .core .events .OperationAddedEvent ;
119import edu .wpi .grip .core .operations .Operations ;
10+ import edu .wpi .grip .core .settings .ProjectSettings ;
1211import edu .wpi .grip .core .sources .ImageFileSource ;
1312import edu .wpi .grip .generated .CVOperations ;
1413import edu .wpi .grip .util .Files ;
2221
2322import static junit .framework .TestCase .assertEquals ;
2423
24+ /**
25+ * This tests for backwards compatibility by opening a project file containing ALL the steps of GRIP
26+ * at the time of this file's creation.
27+ */
2528public class CompatibilityTest {
2629
27- private static final URI testphotoURI = Files .testphotoURI ;
28- private static final URI testprojectURI = Files .testprojectURI ;
30+ private static final URI testphotoURI = Files .testphotoURI ; //The location of the photo source for the test
31+ private static final URI testprojectURI = Files .testprojectURI ; //The location of the save file for the test
2932
3033 private Connection .Factory <Object > connectionFactory ;
3134 private ImageFileSource .Factory imageSourceFactory ;
3235 private Step .Factory stepFactory ;
3336 private Pipeline pipeline ;
3437 private Project project ;
35-
38+ private ProjectSettings settings ;
3639
3740 private List <Operation > operationList ;
3841 private Optional <Throwable > throwableOptional ;
3942 private EventBus eventBus ;
4043
41- private class OperationGrabber {
42- @ Subscribe
43- public void onOperationAddedEvent (OperationAddedEvent event ) {
44- operationList .add (event .getOperation ());
45- }
46- }
47-
4844 @ Before
4945 public void setUp () throws Exception {
5046
@@ -58,15 +54,18 @@ public void setUp() throws Exception {
5854 eventBus = injector .getInstance (EventBus .class );
5955 pipeline = injector .getInstance (Pipeline .class );
6056 project = injector .getInstance (Project .class );
57+ settings = injector .getInstance (ProjectSettings .class );
6158 stepFactory = injector .getInstance (Step .Factory .class );
6259
60+ //Add the operations so that GRIP will recognize them
6361 Operations .addOperations (eventBus );
6462 CVOperations .addOperations (eventBus );
6563
6664 //Set up the test project file to work with this machine
6765 String fileName = testprojectURI .toString ().substring (5 );
6866 String photoFileName = testphotoURI .toString ().substring (5 );
6967
68+ //Open the project save file and read it into a string so that we can alter it
7069 File file = new File (fileName );
7170
7271 Reader temp = new FileReader (file );
@@ -76,11 +75,19 @@ public void setUp() throws Exception {
7675 oldtext += line + "\r \n " ;
7776 }
7877 reader .close ();
79- String newtext = oldtext .replaceAll ("REPLACEME" , photoFileName );
80-
81- //TODO: replace "preferences" section to work with this machine
78+ String newtext = oldtext .replaceAll ("REPLACEME" , photoFileName );//This gives the correct location of the test photo needed to the project file
79+ //The following alters the project settings in the project file to the defaults given in the "settings" variable
80+ newtext = newtext .replaceAll ("<teamNumber>.*</teamNumber>" , "<teamNumber>" + settings .getTeamNumber () + "</teamNumber>" );
81+ newtext = newtext .replaceAll ("<publishAddress>.*</publishAddress>" , "<publishAddress>" + settings .getPublishAddress () + "</publishAddress>" );
82+ newtext = newtext .replaceAll ("<deployAddress>.*</deployAddress>" , "<deployAddress>" + settings .getDeployAddress () + "</deployAddress>" );
83+ newtext = newtext .replaceAll ("<deployDir>.*</deployDir>" , "<deployDir>" + settings .getDeployDir () + "</deployDir>" );
84+ newtext = newtext .replaceAll ("<deployUser>.*</deployUser>" , "<deployUser>" + settings .getDeployUser () + "</deployUser>" );
85+ newtext = newtext .replaceAll ("<deployJavaHome>.*</deployJavaHome>" , "<deployJavaHome>" + settings .getDeployJavaHome () + "</deployJavaHome>" );
86+
87+ //Write the altered project file text
8288 FileWriter writer2 = new FileWriter (file );
8389 writer2 .write (newtext );
90+
8491 writer2 .close ();
8592
8693 //Open the test file as a project
@@ -89,8 +96,7 @@ public void setUp() throws Exception {
8996
9097 @ Test
9198 public void testFoo () throws Exception {
92-
93- assertEquals ("blarg" , 3 , 3 );
94-
99+ assertEquals ("The expected number of steps were not found" , 50 , pipeline .getSteps ().size ());
100+ assertEquals ("The expected number of sources were not found" , 2 , pipeline .getSources ().size ());
95101 }
96102}
0 commit comments