3838import org .junit .jupiter .api .AfterAll ;
3939import org .junit .jupiter .api .Assertions ;
4040import org .junit .jupiter .api .BeforeAll ;
41+ import org .junit .jupiter .api .MethodOrderer ;
42+ import org .junit .jupiter .api .Order ;
4143import org .junit .jupiter .api .Test ;
44+ import org .junit .jupiter .api .TestMethodOrder ;
4245import org .junit .jupiter .api .Timeout ;
4346import org .junit .runner .RunWith ;
4447import org .junit .runners .JUnit4 ;
4548
4649@ RunWith (JUnit4 .class )
47- @ Timeout (value = 25 , unit = TimeUnit .MINUTES )
50+ @ Timeout (value = 6 , unit = TimeUnit .MINUTES )
51+ @ TestMethodOrder (MethodOrderer .OrderAnnotation .class )
4852public class ReservationIT {
4953
5054 private static final String PROJECT_ID = System .getenv ("GOOGLE_CLOUD_PROJECT" );
51- private static final String ZONE = "us-west1 -a" ;
55+ private static final String ZONE = "asia-south1 -a" ;
5256 private static final String REGION = ZONE .substring (0 , ZONE .lastIndexOf ('-' ));
53- private static ReservationsClient reservationsClient ;
54- private static String RESERVATION_NAME_GLOBAL ;
55- private static String RESERVATION_NAME_REGIONAL ;
56- private static String GLOBAL_INSTANCE_TEMPLATE_URI ;
57- private static String REGIONAL_INSTANCE_TEMPLATE_URI ;
5857 static String javaVersion = System .getProperty ("java.version" ).substring (0 , 2 );
58+ private static ReservationsClient reservationsClient ;
59+ private static final String RESERVATION_NAME_GLOBAL = "test-reservation-global-" + javaVersion
60+ + "-" + UUID .randomUUID ().toString ().substring (0 , 8 );
61+ private static final String RESERVATION_NAME_REGIONAL = "test-reservation-regional-"
62+ + javaVersion + "-" + UUID .randomUUID ().toString ().substring (0 , 8 );
5963 private static final String GLOBAL_INSTANCE_TEMPLATE_NAME =
6064 "test-global-inst-temp-" + javaVersion + "-" + UUID .randomUUID ().toString ().substring (0 , 8 );
61- private static final String REGIONAL_INSTANCE_TEMPLATE_NAME =
62- "test-regional-inst-temp-" + javaVersion + "-"
63- + UUID .randomUUID ().toString ().substring (0 , 8 );
65+ private static final String REGIONAL_INSTANCE_TEMPLATE_NAME = "test-regional-inst-temp-"
66+ + javaVersion + "-" + UUID .randomUUID ().toString ().substring (0 , 8 );
67+ private static final String GLOBAL_INSTANCE_TEMPLATE_URI = String .format (
68+ "projects/%s/global/instanceTemplates/%s" , PROJECT_ID , GLOBAL_INSTANCE_TEMPLATE_NAME );
69+ private static final String REGIONAL_INSTANCE_TEMPLATE_URI =
70+ String .format ("projects/%s/regions/%s/instanceTemplates/%s" ,
71+ PROJECT_ID , REGION , REGIONAL_INSTANCE_TEMPLATE_NAME );
6472 private static final int NUMBER_OF_VMS = 3 ;
6573
6674 // Check if the required environment variables are set.
@@ -89,16 +97,6 @@ public static void setUp()
8997 // Initialize the client once for all tests
9098 reservationsClient = ReservationsClient .create ();
9199
92- RESERVATION_NAME_GLOBAL = "test-reservation-global-" + javaVersion + "-"
93- + UUID .randomUUID ().toString ().substring (0 , 8 );
94- RESERVATION_NAME_REGIONAL = "test-reservation-regional-" + javaVersion + "-"
95- + UUID .randomUUID ().toString ().substring (0 , 8 );
96- GLOBAL_INSTANCE_TEMPLATE_URI = String .format ("projects/%s/global/instanceTemplates/%s" ,
97- PROJECT_ID , GLOBAL_INSTANCE_TEMPLATE_NAME );
98- REGIONAL_INSTANCE_TEMPLATE_URI =
99- String .format ("projects/%s/regions/%s/instanceTemplates/%s" ,
100- PROJECT_ID , REGION , REGIONAL_INSTANCE_TEMPLATE_NAME );
101-
102100 // Create instance template with GLOBAL location.
103101 CreateInstanceTemplate .createInstanceTemplate (PROJECT_ID , GLOBAL_INSTANCE_TEMPLATE_NAME );
104102 assertThat (stdOut .toString ())
@@ -152,6 +150,7 @@ public static void cleanup()
152150 }
153151
154152 @ Test
153+ @ Order (1 )
155154 public void testCreateReservationWithGlobalInstanceTemplate ()
156155 throws IOException , ExecutionException , InterruptedException , TimeoutException {
157156 CreateReservationForInstanceTemplate .createReservationForInstanceTemplate (
@@ -177,4 +176,17 @@ public void testCreateReservationWithRegionInstanceTemplate()
177176 Assert .assertTrue (reservation .getZone ().contains (ZONE ));
178177 Assert .assertEquals (RESERVATION_NAME_REGIONAL , reservation .getName ());
179178 }
179+
180+ @ Test
181+ @ Order (2 )
182+ public void testUpdateVmsForReservation ()
183+ throws IOException , ExecutionException , InterruptedException , TimeoutException {
184+ int newNumberOfVms = 5 ;
185+ UpdateVmsForReservation .updateVmsForReservation (
186+ PROJECT_ID , ZONE , RESERVATION_NAME_GLOBAL , newNumberOfVms );
187+ Reservation reservation = GetReservation .getReservation (
188+ PROJECT_ID , RESERVATION_NAME_GLOBAL , ZONE );
189+
190+ Assert .assertEquals (newNumberOfVms , reservation .getSpecificReservation ().getCount ());
191+ }
180192}
0 commit comments