@Test
public void testApplyGroupAlreadyExists() throws UnknownHostException {
final CloudStackApi client = createMock(CloudStackApi.class);
SecurityGroupApi secClient = createMock(SecurityGroupApi.class);
ZoneApi zoneClient = createMock(ZoneApi.class);
AsyncJobApi jobClient = createMock(AsyncJobApi.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.getSecurityGroupApi()).andReturn(secClient)
.anyTimes();
expect(client.getZoneApi()).andReturn(zoneClient);
expect(client.getAsyncJobApi()).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);