Search in sources :

Example 31 with SeleniumRobotVariableServerConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector in project seleniumRobot by bhecquet.

the class TestSeleniumRobotVariableServerConnector method testServerActiveAliveAndSecured.

/**
 * test exception is raised if no token is provided whereas server is secured
 * @throws UnirestException
 */
@Test(groups = { "ut" }, expectedExceptions = ConfigurationException.class)
public void testServerActiveAliveAndSecured() throws UnirestException {
    configureMockedVariableServerConnection();
    when(responseAliveString.getStatus()).thenReturn(401);
    SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", null);
}
Also used : SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 32 with SeleniumRobotVariableServerConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector in project seleniumRobot by bhecquet.

the class TestSeleniumRobotVariableServerConnector method testCreateEnvironmentWithToken.

/**
 * Check tokens are not added to request when not provided
 * @throws UnirestException
 */
@Test(groups = { "ut" })
public void testCreateEnvironmentWithToken() throws UnirestException {
    configureMockedVariableServerConnection();
    SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", "123");
    connector.createEnvironment();
    verify(createEnvironmentRequest, times(1)).header("Authorization", "Token 123");
}
Also used : SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 33 with SeleniumRobotVariableServerConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector in project seleniumRobot by bhecquet.

the class TestSeleniumRobotVariableServerConnector method testVariableUpdateExistingVariableThatDisappeard.

/**
 * issue #429: if variable has been deleted, recreate one
 * @throws UnirestException
 */
@Test(groups = { "ut" })
public void testVariableUpdateExistingVariableThatDisappeard() throws UnirestException {
    configureMockedVariableServerConnection();
    createServerMock(SERVER_URL, "PATCH", String.format(SeleniumRobotVariableServerConnector.EXISTING_VARIABLE_API_URL, 12), 404, "{}");
    SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", null);
    TestVariable existingVariable = new TestVariable(12, "key", "value", false, TestVariable.TEST_VARIABLE_PREFIX + "key");
    TestVariable variable = connector.upsertVariable(existingVariable, true);
    // check we tried a PATCH and then create the variable with a POST
    PowerMockito.verifyStatic(Unirest.class);
    Unirest.patch(ArgumentMatchers.contains(SeleniumRobotVariableServerConnector.VARIABLE_API_URL));
    PowerMockito.verifyStatic(Unirest.class);
    Unirest.post(ArgumentMatchers.contains(SeleniumRobotVariableServerConnector.VARIABLE_API_URL));
    Assert.assertEquals(variable.getValue(), "value");
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 34 with SeleniumRobotVariableServerConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector in project seleniumRobot by bhecquet.

the class TestSeleniumRobotVariableServerConnector method testVariableDereservationNullId.

@Test(groups = { "ut" })
public void testVariableDereservationNullId() throws UnirestException {
    configureMockedVariableServerConnection();
    SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", null);
    List<TestVariable> variables = Arrays.asList(new TestVariable("key", "value"));
    connector.unreserveVariables(variables);
    // only one dereservation should be called
    PowerMockito.verifyStatic(Unirest.class, times(0));
    Unirest.patch(ArgumentMatchers.contains(String.format(SeleniumRobotVariableServerConnector.EXISTING_VARIABLE_API_URL, 2)));
}
Also used : TestVariable(com.seleniumtests.core.TestVariable) SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 35 with SeleniumRobotVariableServerConnector

use of com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector in project seleniumRobot by bhecquet.

the class TestSeleniumRobotVariableServerConnector method testServerWithRedirect301.

/**
 * Issue #356: check we change URL if redirect 301 is encountered
 */
@Test(groups = { "ut" })
public void testServerWithRedirect301() {
    // connection for HTTP
    configureMockedVariableServerConnection();
    // connection for HTTPS
    configureMockedVariableServerConnection("https://localhost:2345");
    HttpResponse<String> response = mock(HttpResponse.class);
    when(response.getBody()).thenReturn("Moved Permanently");
    when(response.getHeaders()).thenReturn(headers);
    when(response.getStatus()).thenReturn(301);
    when(responseHttps.getBody()).thenReturn("OK");
    when(responseHttps.getStatus()).thenReturn(200);
    when(headers.getFirst("Location")).thenReturn("https://localhost:2345");
    when(getAliveRequest.asString()).thenReturn(response);
    when(getAliveRequestHttps.asString()).thenReturn(responseHttps);
    when(unirestInstance.get(SERVER_URL + "/variable/api/")).thenReturn(getAliveRequest);
    when(Unirest.get("https://localhost:2345/variable/api/")).thenReturn(getAliveRequestHttps);
    SeleniumRobotVariableServerConnector connector = new SeleniumRobotVariableServerConnector(true, SERVER_URL, "Test1", null);
    Assert.assertEquals(connector.getUrl(), "https://localhost:2345");
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) Test(org.testng.annotations.Test) ConnectorsTest(com.seleniumtests.ConnectorsTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

SeleniumRobotVariableServerConnector (com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector)36 ConnectorsTest (com.seleniumtests.ConnectorsTest)34 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)34 Test (org.testng.annotations.Test)34 TestVariable (com.seleniumtests.core.TestVariable)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 HttpRequest (kong.unirest.HttpRequest)2 ScenarioException (com.seleniumtests.customexception.ScenarioException)1 ArrayList (java.util.ArrayList)1 SkipException (org.testng.SkipException)1 BeforeMethod (org.testng.annotations.BeforeMethod)1