2323import com .google .api .gax .rpc .NotFoundException ;
2424import com .google .cloud .compute .v1 .Reservation ;
2525import compute .Util ;
26+ import java .io .ByteArrayOutputStream ;
2627import java .io .IOException ;
28+ import java .io .PrintStream ;
2729import java .util .List ;
2830import java .util .UUID ;
2931import java .util .concurrent .ExecutionException ;
3032import java .util .concurrent .TimeUnit ;
3133import java .util .concurrent .TimeoutException ;
3234import org .junit .Assert ;
35+ import org .junit .FixMethodOrder ;
3336import org .junit .jupiter .api .AfterAll ;
3437import org .junit .jupiter .api .Assertions ;
3538import org .junit .jupiter .api .BeforeAll ;
3639import org .junit .jupiter .api .Test ;
3740import org .junit .jupiter .api .Timeout ;
3841import org .junit .runner .RunWith ;
3942import org .junit .runners .JUnit4 ;
43+ import org .junit .runners .MethodSorters ;
4044
4145@ RunWith (JUnit4 .class )
4246@ Timeout (value = 25 , unit = TimeUnit .MINUTES )
47+ @ FixMethodOrder (MethodSorters .NAME_ASCENDING )
4348public class CrudOperationsReservationIT {
4449
4550 private static final String PROJECT_ID = System .getenv ("GOOGLE_CLOUD_PROJECT" );
@@ -59,15 +64,11 @@ public static void setUp()
5964 throws IOException , ExecutionException , InterruptedException , TimeoutException {
6065 requireEnvVar ("GOOGLE_APPLICATION_CREDENTIALS" );
6166 requireEnvVar ("GOOGLE_CLOUD_PROJECT" );
62- RESERVATION_NAME = "test-reserv " + javaVersion + "-"
67+ RESERVATION_NAME = "test-reservation " + javaVersion + "-"
6368 + UUID .randomUUID ().toString ().substring (0 , 8 );
6469
6570 // Cleanup existing stale resources.
66- Util .cleanUpExistingReservations ("test-reserv" + javaVersion , PROJECT_ID , ZONE );
67- TimeUnit .SECONDS .sleep (50 );
68-
69- CreateReservation .createReservation (
70- PROJECT_ID , RESERVATION_NAME , NUMBER_OF_VMS , ZONE );
71+ Util .cleanUpExistingReservations ("test-reservation" + javaVersion , PROJECT_ID , ZONE );
7172 }
7273
7374 @ AfterAll
@@ -83,7 +84,22 @@ public static void cleanup()
8384 }
8485
8586 @ Test
86- public void testGetReservation ()
87+ public void firstCreateReservationTest ()
88+ throws IOException , ExecutionException , InterruptedException , TimeoutException {
89+ final PrintStream out = System .out ;
90+ ByteArrayOutputStream stdOut = new ByteArrayOutputStream ();
91+ System .setOut (new PrintStream (stdOut ));
92+ CreateReservation .createReservation (
93+ PROJECT_ID , RESERVATION_NAME , NUMBER_OF_VMS , ZONE );
94+
95+ assertThat (stdOut .toString ()).contains ("Reservation created. Operation Status: DONE" );
96+
97+ stdOut .close ();
98+ System .setOut (out );
99+ }
100+
101+ @ Test
102+ public void secondGetReservationTest ()
87103 throws IOException {
88104 Reservation reservation = GetReservation .getReservation (
89105 PROJECT_ID , RESERVATION_NAME , ZONE );
@@ -93,7 +109,7 @@ public void testGetReservation()
93109 }
94110
95111 @ Test
96- public void testListReservation () throws IOException {
112+ public void thirdListReservationTest () throws IOException {
97113 List <Reservation > reservations =
98114 ListReservations .listReservations (PROJECT_ID , ZONE );
99115
0 commit comments