use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestTestTasks method testUpdateNewVariable.
/**
* Check upsert of a new variable
* Verify server is called and configuration is updated according to the new value
* @param testNGCtx
* @param xmlTest
* @throws Exception
*/
@Test(groups = { "ut" })
public void testUpdateNewVariable(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
try {
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:1234");
PowerMockito.whenNew(SeleniumRobotVariableServerConnector.class).withArguments(eq(true), eq("http://localhost:1234"), anyString(), eq(null)).thenReturn(variableServer);
when(variableServer.isAlive()).thenReturn(true);
TestVariable varToReturn = new TestVariable(10, "key", "value", false, TestVariable.TEST_VARIABLE_PREFIX + "key");
when(variableServer.upsertVariable(any(TestVariable.class), anyBoolean())).thenReturn(varToReturn);
ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
initThreadContext(testNGCtx, "myTest", testResult);
TestTasks.createOrUpdateParam("key", "value");
// check upsert has been called
verify(variableServer).upsertVariable(new TestVariable("key", "value"), true);
// check configuration is updated
Assert.assertEquals(SeleniumTestsContextManager.getThreadContext().getConfiguration().get("key"), varToReturn);
} finally {
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
}
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestTestTasks method testUpdateReservableVariableWithTTL.
/**
* Check that if TTL and reservable is set, all information are passer to server
* @param testNGCtx
* @param xmlTest
* @throws Exception
*/
@Test(groups = { "ut" })
public void testUpdateReservableVariableWithTTL(final ITestContext testNGCtx, final XmlTest xmlTest) throws Exception {
try {
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE, "true");
System.setProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL, "http://localhost:1234");
PowerMockito.whenNew(SeleniumRobotVariableServerConnector.class).withArguments(eq(true), eq("http://localhost:1234"), anyString(), eq(null)).thenReturn(variableServer);
when(variableServer.isAlive()).thenReturn(true);
TestVariable varToReturn = new TestVariable(10, "key", "value", false, TestVariable.TEST_VARIABLE_PREFIX + "key");
when(variableServer.upsertVariable(any(TestVariable.class), anyBoolean())).thenReturn(varToReturn);
ITestResult testResult = GenericTest.generateResult(testNGCtx, getClass());
initThreadContext(testNGCtx, "myTest", testResult);
TestTasks.createOrUpdateParam("key", "value", false, 1, true);
// check upsert has been called
verify(variableServer).upsertVariable(new TestVariable(null, "key", "value", true, "key", 1, null), false);
} finally {
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_ACTIVE);
System.clearProperty(SeleniumTestsContext.SELENIUMROBOTSERVER_URL);
}
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestTestVariable method testInterpolateValue.
@Test(groups = { "ut" })
public void testInterpolateValue() {
SeleniumTestsContextManager.getThreadContext().getConfiguration().put("path", new TestVariable("path", "/foo/bar"));
Assert.assertEquals(new TestVariable("url", "http://mysite${path}").getValue(), "http://mysite/foo/bar");
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestTestVariable method testFromJSon.
/**
* Test variable without date
*/
@Test(groups = { "ut" })
public void testFromJSon() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", 1);
jsonObject.put("name", "key");
jsonObject.put("value", "value");
jsonObject.put("reservable", false);
jsonObject.put("environment", 1);
jsonObject.put("application", 2);
jsonObject.put("version", 3);
TestVariable var = TestVariable.fromJsonObject(jsonObject);
Assert.assertEquals(var.getId(), (Integer) 1);
Assert.assertEquals(var.getName(), "key");
Assert.assertEquals(var.getValue(), "value");
Assert.assertEquals(var.isReservable(), false);
Assert.assertEquals(var.getInternalName(), "key");
Assert.assertNull(var.getCreationDate());
}
use of com.seleniumtests.core.TestVariable in project seleniumRobot by bhecquet.
the class TestTestVariable method testFromJSonWithDate.
/**
* Test variable with date
*/
@Test(groups = { "ut" })
public void testFromJSonWithDate() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", 1);
jsonObject.put("name", "key");
jsonObject.put("value", "value");
jsonObject.put("reservable", false);
jsonObject.put("environment", 1);
jsonObject.put("application", 2);
jsonObject.put("version", 3);
jsonObject.put("creationDate", "2018-07-12T08:42:56.156727Z");
TestVariable var = TestVariable.fromJsonObject(jsonObject);
Assert.assertEquals(var.getId(), (Integer) 1);
Assert.assertEquals(var.getName(), "key");
Assert.assertEquals(var.getValue(), "value");
Assert.assertEquals(var.isReservable(), false);
Assert.assertEquals(var.getInternalName(), "key");
Assert.assertEquals(var.getCreationDate(), LocalDateTime.of(2018, 7, 12, 8, 42, 56, 156727000));
}
Aggregations