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

import be.iminds.ilabt.jfed.log.Logger;
import be.iminds.ilabt.jfed.lowlevel.ApiInfo;
import be.iminds.ilabt.jfed.lowlevel.GeniUserProvider;
import be.iminds.ilabt.jfed.lowlevel.JFedException;
import be.iminds.ilabt.jfed.lowlevel.TestbedInfoSource;
import be.iminds.ilabt.jfed.lowlevel.api.ProtogeniSliceAuthority;
import be.iminds.ilabt.jfed.lowlevel.connection.JFedConnectionProvider;
import be.iminds.ilabt.jfed.lowlevel.connection.SfaConnection;
import be.iminds.ilabt.jfed.preferences.JFedPreferences;
import be.iminds.ilabt.jfed.testing.base.ApiTest;
import be.iminds.ilabt.jfed.util.TargetAuthority;

import javax.inject.Inject;


/**
 * SimpleTestSliceAuthority: One simple test of "ProtoGeni Slice Authority API v1"
 *
 * This is little more than a connectivity test and one basic test of XmlRpc and GetVersion.
 *
 * Use TestSliceAuthority for a lot more tests of the "ProtoGeni Slice Authority API v1".
 */
public class ConnectivityTestSliceAuthority extends ApiTest {
    @Inject
    public ConnectivityTestSliceAuthority(Logger logger, TargetAuthority testedAuthority, GeniUserProvider geniUserProvider, JFedConnectionProvider connectionProvider, TestbedInfoSource testbedInfoSource, JFedPreferences jFedPreferences) {
        super(logger, testedAuthority, geniUserProvider, connectionProvider, testbedInfoSource, jFedPreferences);
    }

    public String getTestDescription() {
        return "One simple \"ProtoGeni Slice Authority API v1\" Test (XmlRpc and GetVersion). This is mainly useful to test connectivity to the tested SA.";
    }

    private ProtogeniSliceAuthority sa;


    public SfaConnection getConnection() throws JFedException {
        return (SfaConnection) connectionProvider.getConnectionByAuthority(user, user.getUserAuthorityServer(), new ApiInfo.Api(ApiInfo.ApiName.PROTOGENI_SA, 1));
    }

    public void setUp() {

        sa = new ProtogeniSliceAuthority(logger, jFedPreferences);
    }

    @Test
    public void testGetVersion() throws JFedException {
        System.out.println("GetVersion test starting");
        ProtogeniSliceAuthority.SliceAuthorityReply<String> reply = sa.getVersion(getConnection());
        assertTrue(reply.getGeniResponseCode().isSuccess());
        System.out.println("GetVersion test finished");
    }

}
