/*
 * Copyright 2011 Splunk, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"): you may
 * not use this file except in compliance with the License. You may obtain
 * a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.splunk.sdk.tests.com.splunk;

import com.splunk.*;
import com.splunk.sdk.Program;
import com.splunk.Service;

import java.io.IOException;

import junit.framework.TestCase;
import junit.framework.Assert;

import org.junit.*;

public class FiredAlertTest extends TestCase {
    Program program = new Program();

    public FiredAlertTest() {}

    Service connect() throws IOException {
        return new Service(
            program.host, program.port, program.scheme)
                .login(program.username, program.password);
    }

    private Service waitForSplunk() throws Exception {
        // there is still a race condition here: if the restart takes more
        // than 5 seconds to percolate through splunk, apps will not be
        // reset
        int retry = 10;
        while (retry > 0) {
            Thread.sleep(5000); // 5 seconds
            retry = retry-1;
            try {
                return connect();
            }
            catch (Exception e) {
                // server not back yet
            }
        }
        Assert.fail("Splunk service did not restart");
        return null;
    }


    @Before public void setUp() {
        this.program.init(); // Pick up .splunkrc settings
    }

    @Test public void testFiredAlerts() throws Exception {
        Service service = connect();
        EntityCollection<FiredAlert> alerts = service.getFiredAlerts();

        if (alerts.values().size() == 0) {
            System.out.println("WARNING: no fired elerts detected");
            return;
        }

        for (FiredAlert entity: alerts.values()) {
            entity.getAction();
            entity.getAlertType();
            entity.getExpirationTime();
            entity.getSavedSearchName();
            entity.getSeverity();
            entity.getSid();
            entity.getTriggerTime();
        }
    }
}
@@ -1142,600 +1142,8 @@
  %7D%0A%0A
-    private Service waitForSplunk() throws Exception %7B%0A        // there is still a race condition here: if the restart takes more%0A        // than 5 seconds to percolate through splunk, apps will not be%0A        // reset%0A        int retry = 10;%0A        while (retry %3E 0) %7B%0A            Thread.sleep(5000); // 5 seconds%0A            retry = retry-1;%0A            try %7B%0A                return connect();%0A            %7D%0A            catch (Exception e) %7B%0A                // server not back yet%0A            %7D%0A        %7D%0A        Assert.fail(%22Splunk service did not restart%22);%0A        return null;%0A    %7D%0A%0A%0A
     

remove cut/pasted vestigal code from test.