use of com.google.api.services.compute.model.Zone in project pipeline5 by hartwigmedical.
the class InstanceLifecycleManagerTest method shouldReturnExistingInstance.
@Test
public void shouldReturnExistingInstance() throws Exception {
Compute.Instances.List zoneOneInstances = mock(Compute.Instances.List.class);
Compute.Instances.List zoneTwoInstances = mock(Compute.Instances.List.class);
InstanceList zoneOneInstanceList = mock(InstanceList.class);
InstanceList zoneTwoInstanceList = mock(InstanceList.class);
when(instances.list(ARGUMENTS.project(), zoneOne)).thenReturn(zoneOneInstances);
when(instances.list(ARGUMENTS.project(), zoneTwo)).thenReturn(zoneTwoInstances);
when(zoneOneInstances.execute()).thenReturn(zoneOneInstanceList);
when(zoneTwoInstances.execute()).thenReturn(zoneTwoInstanceList);
Instance vmInstance = namedInstance(vmName);
Instance someInstance = namedInstance();
Instance someOtherInstance = namedInstance();
when(zoneOneInstanceList.getItems()).thenReturn(singletonList(someInstance));
when(zoneTwoInstanceList.getItems()).thenReturn(asList(someOtherInstance, vmInstance));
Compute.Zones zones = mock(Compute.Zones.class);
Compute.Zones.List zonesList = mock(Compute.Zones.List.class);
List<Zone> stubbedZones = asList(zone(zoneOne), zone(zoneTwo));
when(zonesList.execute()).thenReturn(new ZoneList().setItems(stubbedZones));
when(compute.zones()).thenReturn(zones);
when(zones.list(ARGUMENTS.project())).thenReturn(zonesList);
Optional<Instance> found = victim.findExistingInstance(vmName);
assertThat(found).isNotEmpty();
assertThat(found.get()).isEqualTo(vmInstance);
}
Aggregations