@Test
public void testApplyGroupAlreadyExists() throws UnknownHostException {
final CloudStackClient client = createMock(CloudStackClient.class);
SecurityGroupClient secClient = createMock(SecurityGroupClient.class);
ZoneClient zoneClient = createMock(ZoneClient.class);
AsyncJobClient jobClient = createMock(AsyncJobClient.class);
SecurityGroup group = createMock(SecurityGroup.class);
Zone zone = createMock(Zone.class);
expect(group.getId()).andReturn("sec-1234").anyTimes();
expect(zone.isSecurityGroupsEnabled()).andReturn(true);
expect(client.getSecurityGroupClient()).andReturn(secClient)
.anyTimes();
expect(client.getZoneClient()).andReturn(zoneClient);
expect(client.getAsyncJobClient()).andReturn(jobClient).anyTimes();
expect(zoneClient.getZone("zone-abc2")).andReturn(zone);
expect(secClient.createSecurityGroup("group-1")).andThrow(new IllegalStateException());
expect(secClient.getSecurityGroupByName("group-1")).andReturn(group);
replay(client, secClient, zoneClient, zone, group);