package be.iminds.ilabt.jfed.lowlevel.api;

import be.iminds.ilabt.jfed.lowlevel.AbstractApi;
import be.iminds.ilabt.jfed.lowlevel.GeniAMResponseCode;
import be.iminds.ilabt.jfed.lowlevel.connection.ConnectionConfig;
import be.iminds.ilabt.jfed.lowlevel.connection.JFedConnection;
import be.iminds.ilabt.jfed.util.JSonHelper;
import be.iminds.ilabt.jfed.util.XmlUtil;
import org.apache.http.StatusLine;
import org.testng.annotations.Test;

import java.util.Date;
import java.util.Map;
import java.util.List;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.testng.Assert.*;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

public class AbstractFederationApiTest {

    @Test
    public void testIsBusyReply() throws Exception {
        String replyJsonString = "{ \"protogeni_error_url\": \"https://www.wall2.ilabt.iminds.be/spewlogfile.php3?logfile=9bc4ae32a482f77c6f3825f86e691b12\", " +
                "\"output\": \"slice is busy; try again later\", " +
                "\"protogeni_error_log\": \"urn:publicid:IDN+wall2.ilabt.iminds.be+log+9bc4ae32a482f77c6f3825f86e691b12\", " +
                "\"code\": 14, \"value\": 0 " +
                "} ";

        Map replyJsonHt = (Map) JSonHelper.jsonStringToXmlRpcLikeObject(replyJsonString);

        AbstractApi.XMLRPCCallDetailsWithCodeValueError xmlrpcCallDetailsWithCodeValueError =
                new AbstractApi.XMLRPCCallDetailsWithCodeValueError(
                null /*connectionConfig*/,
                null /*serverUrl*/,
                null /*requestHttpRequestLine*/, null /*requestHttpHeaders*/, null /*requestHttpContent*/,
                null /*resultHttpStatusLine*/, null /*resultHttpHeaders*/, replyJsonString /*resultHttpContent*/,
                null /*request*/,
                replyJsonHt /*result*/,
                new Date() /*startTime*/,
                new Date() /*stopTime*/,
                null /*exception*/,
                null /*connection*/
        );

        assertThat(AbstractFederationApi.isBusyApiReply(xmlrpcCallDetailsWithCodeValueError), is(true));
    }
}