import org.apache.http.HttpStatus;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import java.util.Hashtable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import kidozen.client.KZApplication;
import kidozen.client.ServiceEvent;
import kidozen.client.ServiceEventListener;
import kidozen.client.authentication.WRAPv09IdentityProvider;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/**
* Created by christian on 9/17/14.
*/
@RunWith(RobolectricTestRunner.class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Config(manifest= Config.NONE)
public class CustomAuthTest {
public static final int TEST_TIMEOUT_IN_MINUTES = 1;
KZApplication kidozen = null;
@Test
public void ShouldAuthenticateUsingCustomIP() throws Exception {
final CountDownLatch lcd = new CountDownLatch(1);
kidozen = new KZApplication(AppSettings.KZ_TENANT, AppSettings.KZ_APP, AppSettings.KZ_KEY,false);
kidozen.Initialize( new ServiceEventListener() {
@Override
public void onFinish(ServiceEvent e) {
lcd.countDown();
assertThat(e.StatusCode, equalTo(HttpStatus.SC_OK));
}
});
lcd.await(TEST_TIMEOUT_IN_MINUTES, TimeUnit.MINUTES);
final CountDownLatch alcd = new CountDownLatch(1);
WRAPv09IdentityProvider ip = new WRAPv09IdentityProvider(AppSettings.KZ_USER,AppSettings.KZ_PASS,"https://identity.kidozen.com/wrapv0.9","http://auth.kidozen.com/");
ip.assertionFormat = "SAML";
kidozen.Authenticate(ip, new ServiceEventListener() {
@Override
public void onFinish(ServiceEvent e) {
alcd.countDown();
assertThat(e.StatusCode, equalTo(HttpStatus.SC_OK));
}
});
assertEquals(true, kidozen.UserIsAuthenticated);
alcd.await(TEST_TIMEOUT_IN_MINUTES, TimeUnit.MINUTES);
}
}