//2013-02-19 johnpfeiffer
package com.oxygencloud.sdk.util;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import com.oxygen.sdk.O2Agent;
import com.oxygen.sdk.exception.O2InvalidSessionException;
import com.oxygen.sdk.exception.O2NetworkException;
import com.oxygen.sdk.exception.O2RuleException;
import com.oxygen.sdk.exception.O2UnexpectedException;
public class OxygenLoginIntegrationTest {
private OxygenLogin defaultTester;
private String apiURL = "https://api.example.net/gateway";
private String apiKey = "mykey433799cdc5bdf0d56a62";
private String user = "my-user-qa";
private String password = "my-password";
@Before
public void setUp() throws Exception {
defaultTester = new OxygenLogin.Builder().apiURL( apiURL ).apiKey( apiKey ).oxygenUserId( user ).oxygenPassword( password ).build();
}
@Test
public void SessionId_Is_Not_Null() {
assertNotNull( defaultTester.getSessionId() );
System.out.println( "SessionId_Is_Not_Null: " + defaultTester.getSessionId() );
}
@Test
public void Agent_Is_Not_Null() {
assertNotNull( defaultTester.getAgent() );
System.out.println( "Agent_Is_Not_Null: " + defaultTester.getAgent() );
}
@Test
public void Validate_Login_By_Agent_Get_Login_URL() {
O2Agent agent = defaultTester.getAgent();
String loginURL = "";
try {
loginURL = agent.getLoginURL( apiKey );
} catch( O2InvalidSessionException e ) {
fail( "O2InvalidSessionException" + e.getMessage() );
} catch( O2NetworkException e ) {
fail( "O2NetworkException" + e.getMessage() );
} catch( O2RuleException e ) {
fail( "O2RuleException" + e.getMessage() );
} catch( O2UnexpectedException e ) {
fail( "O2UnexpectedException" + e.getMessage() );
}
System.out.println( "Validate_Login_By_Agent_Get_Login_URL: " + loginURL );
}
@Test
public void Successful_Login_Duration_Is_Less_Than_5_Seconds() {
long loginDuration = defaultTester.getLoginDurationInMilliseconds();
System.out.println( "Successful_Login_Duration_Is_Less_Than_5_Seconds: login in " + loginDuration + " ms");
assertTrue( loginDuration > 0 ); //guard assertion
assertTrue( loginDuration < 5000 );
}
} //end class