class CheramiClientImpl implements CheramiClient {

    @Override
    public void deleteConsumerGroup(DeleteConsumerGroupRequest request)
            throws EntityNotExistsError, BadRequestError, IOException {

        this.throwOnNullRequest(request);

        if (!request.isSetConsumerGroupName()) {
            throw new BadRequestError("request missing consumerGroupName parameter");
        }
        if (!request.isSetDestinationPath()) {
            throw new BadRequestError("request missing destinationPath parameter");
        }

        ThriftRequest<deleteConsumerGroup_args> thriftRequest = null;
        ThriftResponse<deleteConsumerGroup_result> thriftResponse = null;
        try {
            thriftRequest = buildThriftRequest("deleteConsumerGroup", new deleteConsumerGroup_args(request));
            thriftResponse = doRemoteCall(thriftRequest);
            deleteConsumerGroup_result result = thriftResponse.getBody(deleteConsumerGroup_result.class);
            if (thriftResponse.getResponseCode() == ResponseCode.OK) {
                return;
            }
            if (result != null && result.isSetEntityError()) {
                throw result.getEntityError();
            }
            if (result != null && result.isSetRequestError()) {
                throw result.getRequestError();
            }

            throw new IOException("deleteConsumerGroup failed with unknown error:" + result);
        } finally {
            if (thriftResponse != null) {
                thriftResponse.release();
            }
        }
    }

}

class CheramiClientImplTest {

    private static CheramiClientImpl client;
    private static MockFrontendService frontendService;
    private static final Logger logger;
    @Rule
    public ExpectedException thrown;

    @Test
    public void testDeleteConsumerGroup() throws Exception {

        //Create a ConsumerGroup to delete
        CreateConsumerGroupRequest request = new CreateConsumerGroupRequest();
        final String destination = "/foo/bar";
        final String consumerGroup = "TestConsumerGroup";
        final int lockTimeout = new Random().nextInt();
        final int maxDelivery = new Random().nextInt();
        final String email = "foo@bar.com";
        final int skipOlder = new Random().nextInt();
        final long timestamp = new Date().getTime();
        request.setDestinationPath(destination);
        request.setConsumerGroupName(consumerGroup);
        request.setLockTimeoutInSeconds(lockTimeout);
        request.setMaxDeliveryCount(maxDelivery);
        request.setOwnerEmail(email);
        request.setSkipOlderMessagesInSeconds(skipOlder);
        request.setStartFrom(timestamp);

        ConsumerGroupDescription response = client.createConsumerGroup(request);

        assert (response.getDestinationPath().equals(destination));
        assert (response.getConsumerGroupName().equals(consumerGroup));

        DeleteConsumerGroupRequest deleteRequest = new DeleteConsumerGroupRequest();

        deleteRequest.setDestinationPath(destination);
        deleteRequest.setConsumerGroupName(consumerGroup);
        // Simple test case where we delete an existing ConsumerGroup
        try {
            client.deleteConsumerGroup(deleteRequest);
        } catch (RuntimeException e) {
            assert (false);
        }

        // Client should not be able to delete a nonexistent ConsumerGroup
        thrown.expect(EntityNotExistsError.class);
        client.deleteConsumerGroup(deleteRequest);
    }

}