Search in sources :

Example 11 with JMXHelper

use of org.openqa.selenium.remote.server.jmx.JMXHelper in project zalenium by zalando.

the class CloudTestingRemoteProxyTest method defaultValuesAreAlwaysNull.

@Test
public void defaultValuesAreAlwaysNull() {
    try {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=Hub");
        ManagementFactory.getPlatformMBeanServer().getObjectInstance(objectName);
        new JMXHelper().unregister(objectName);
    } catch (MalformedObjectNameException | InstanceNotFoundException e) {
    // Might be that the object does not exist, it is ok. Nothing to do, this is just a cleanup task.
    }
    GridRegistry registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
    RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(30003, CloudTestingRemoteProxy.class.getCanonicalName());
    CloudTestingRemoteProxy proxy = CloudTestingRemoteProxy.getNewInstance(request, registry);
    Assert.assertNull(proxy.getAccessKeyProperty());
    Assert.assertNull(proxy.getAccessKeyValue());
    Assert.assertNotNull(proxy.getCloudTestingServiceUrl());
    Assert.assertNull(proxy.getUserNameProperty());
    Assert.assertNull(proxy.getUserNameValue());
    Assert.assertNotNull(proxy.getRemoteHost());
    Assert.assertNull(proxy.getVideoFileExtension());
    Assert.assertNull(proxy.getProxyName());
    Assert.assertNull(proxy.getProxyClassName());
    Assert.assertNull(proxy.getTestInformation("seleniumSessionId"));
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Hub(org.openqa.grid.web.Hub) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) InstanceNotFoundException(javax.management.InstanceNotFoundException) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) GridRegistry(org.openqa.grid.internal.GridRegistry) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 12 with JMXHelper

use of org.openqa.selenium.remote.server.jmx.JMXHelper in project zalenium by zalando.

the class DockerSeleniumRemoteProxyTest method setUp.

@Before
public void setUp() {
    // Change the factory to return our version of the Container Client
    if (this.currentIsKubernetesValue.get()) {
        // This is needed in order to use a fresh version of the mock, otherwise the return values
        // are gone, and returning them always is not the normal behaviour.
        this.containerClient = KubernetesContainerMock.getMockedKubernetesContainerClient();
        ContainerFactory.setKubernetesContainerClient((KubernetesContainerClient) containerClient);
    } else {
        ContainerFactory.setContainerClientGenerator(() -> containerClient);
    }
    ContainerFactory.setIsKubernetes(this.currentIsKubernetesValue);
    try {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=Hub");
        ManagementFactory.getPlatformMBeanServer().getObjectInstance(objectName);
        new JMXHelper().unregister(objectName);
    } catch (MalformedObjectNameException | InstanceNotFoundException e) {
    // Might be that the object does not exist, it is ok. Nothing to do, this is just a cleanup task.
    }
    registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
    // Creating the configuration and the registration request of the proxy (node)
    RegistrationRequest request = TestUtils.getRegistrationRequestForTesting(40000, DockerSeleniumRemoteProxy.class.getCanonicalName());
    request.getConfiguration().capabilities.clear();
    request.getConfiguration().capabilities.addAll(TestUtils.getDockerSeleniumCapabilitiesForTesting());
    // Creating the proxy
    proxy = DockerSeleniumRemoteProxy.getNewInstance(request, registry);
    proxy.setContainerClient(containerClient);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Hub(org.openqa.grid.web.Hub) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) InstanceNotFoundException(javax.management.InstanceNotFoundException) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) RegistrationRequest(org.openqa.grid.common.RegistrationRequest) ObjectName(javax.management.ObjectName) Before(org.junit.Before)

Example 13 with JMXHelper

use of org.openqa.selenium.remote.server.jmx.JMXHelper in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method setUp.

@Before
public void setUp() {
    // Change the factory to return our version of the Container Client
    if (this.currentIsKubernetesValue.get()) {
        // This is needed in order to use a fresh version of the mock, otherwise the return values
        // are gone, and returning them always is not the normal behaviour.
        this.containerClient = KubernetesContainerMock.getMockedKubernetesContainerClient();
        ContainerFactory.setKubernetesContainerClient((KubernetesContainerClient) containerClient);
    } else {
        ContainerFactory.setContainerClientGenerator(() -> containerClient);
    }
    ContainerFactory.setIsKubernetes(this.currentIsKubernetesValue);
    try {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=Hub");
        ManagementFactory.getPlatformMBeanServer().getObjectInstance(objectName);
        new JMXHelper().unregister(objectName);
    } catch (MalformedObjectNameException | InstanceNotFoundException e) {
    // Might be that the object does not exist, it is ok. Nothing to do, this is just a cleanup task.
    }
    registry = ZaleniumRegistry.newInstance(new Hub(new GridHubConfiguration()));
    // Creating the configuration and the registration request of the proxy (node)
    request = TestUtils.getRegistrationRequestForTesting(30000, DockerSeleniumStarterRemoteProxy.class.getCanonicalName());
    // Creating the proxy
    DockerSeleniumStarterRemoteProxy.setContainerClient(containerClient);
    DockerSeleniumStarterRemoteProxy.setSleepIntervalMultiplier(0);
    DockerSeleniumStarterRemoteProxy proxy = DockerSeleniumStarterRemoteProxy.getNewInstance(request, registry);
    timeZone = DockerSeleniumStarterRemoteProxy.getConfiguredTimeZone();
    screenSize = DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize();
    // Spying on the proxy to see if methods are invoked or not
    spyProxy = spy(proxy);
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) Hub(org.openqa.grid.web.Hub) JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) InstanceNotFoundException(javax.management.InstanceNotFoundException) GridHubConfiguration(org.openqa.grid.internal.utils.configuration.GridHubConfiguration) ObjectName(javax.management.ObjectName) Before(org.junit.Before)

Example 14 with JMXHelper

use of org.openqa.selenium.remote.server.jmx.JMXHelper in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method fallbackToDefaultAmountValuesWhenVariablesAreNotIntegers.

@Test
public void fallbackToDefaultAmountValuesWhenVariablesAreNotIntegers() throws MalformedObjectNameException {
    // Mock the environment class that serves as proxy to retrieve env variables
    Environment environment = mock(Environment.class, withSettings().useConstructor());
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_DESIRED_CONTAINERS)).thenReturn("ABC_NON_INTEGER");
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_MAX_DOCKER_SELENIUM_CONTAINERS)).thenReturn("ABC_NON_INTEGER");
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_SCREEN_HEIGHT)).thenReturn("ABC_NON_INTEGER");
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_SCREEN_WIDTH)).thenReturn("ABC_NON_INTEGER");
    when(environment.getEnvVariable(DockerSeleniumStarterRemoteProxy.ZALENIUM_TZ)).thenReturn("ABC_NON_STANDARD_TIME_ZONE");
    when(environment.getIntEnvVariable(any(String.class), any(Integer.class))).thenCallRealMethod();
    when(environment.getStringEnvVariable(any(String.class), any(String.class))).thenCallRealMethod();
    DockerSeleniumStarterRemoteProxy.setEnv(environment);
    try {
        ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:30000\"");
        new JMXHelper().unregister(objectName);
    } finally {
        DockerSeleniumStarterRemoteProxy.getNewInstance(request, registry);
    }
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_AMOUNT_DESIRED_CONTAINERS, DockerSeleniumStarterRemoteProxy.getDesiredContainersOnStartup());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_AMOUNT_DOCKER_SELENIUM_CONTAINERS_RUNNING, DockerSeleniumStarterRemoteProxy.getMaxDockerSeleniumContainers());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_SCREEN_SIZE.getHeight(), DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize().getHeight());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_SCREEN_SIZE.getWidth(), DockerSeleniumStarterRemoteProxy.getConfiguredScreenSize().getWidth());
    Assert.assertEquals(DockerSeleniumStarterRemoteProxy.DEFAULT_TZ.getID(), DockerSeleniumStarterRemoteProxy.getConfiguredTimeZone().getID());
}
Also used : JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) Environment(de.zalando.ep.zalenium.util.Environment) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 15 with JMXHelper

use of org.openqa.selenium.remote.server.jmx.JMXHelper in project zalenium by zalando.

the class DockerSeleniumStarterRemoteProxyTest method afterMethod.

@After
public void afterMethod() throws MalformedObjectNameException {
    ObjectName objectName = new ObjectName("org.seleniumhq.grid:type=RemoteProxy,node=\"http://localhost:30000\"");
    new JMXHelper().unregister(objectName);
    registry.removeIfPresent(spyProxy);
    DockerSeleniumStarterRemoteProxy.setSleepIntervalMultiplier(1000);
    DockerSeleniumStarterRemoteProxy.restoreEnvironment();
    DockerSeleniumStarterRemoteProxy.processedCapabilitiesList.clear();
    ContainerFactory.setContainerClientGenerator(originalDockerContainerClient);
    ContainerFactory.setIsKubernetes(originalIsKubernetesValue);
    ContainerFactory.setKubernetesContainerClient(originalKubernetesContainerClient);
}
Also used : JMXHelper(org.openqa.selenium.remote.server.jmx.JMXHelper) ObjectName(javax.management.ObjectName) After(org.junit.After)

Aggregations

ObjectName (javax.management.ObjectName)22 JMXHelper (org.openqa.selenium.remote.server.jmx.JMXHelper)22 RegistrationRequest (org.openqa.grid.common.RegistrationRequest)10 InstanceNotFoundException (javax.management.InstanceNotFoundException)9 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 GridHubConfiguration (org.openqa.grid.internal.utils.configuration.GridHubConfiguration)9 Hub (org.openqa.grid.web.Hub)9 After (org.junit.After)8 Before (org.junit.Before)8 CommonProxyUtilities (de.zalando.ep.zalenium.util.CommonProxyUtilities)6 Test (org.junit.Test)6 Environment (de.zalando.ep.zalenium.util.Environment)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 DockerSeleniumRemoteProxy (de.zalando.ep.zalenium.proxy.DockerSeleniumRemoteProxy)3 DockerContainerMock (de.zalando.ep.zalenium.util.DockerContainerMock)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ExternalSessionKey (org.openqa.grid.internal.ExternalSessionKey)2 TestSession (org.openqa.grid.internal.TestSession)2 WebDriverRequest (org.openqa.grid.web.servlet.handler.WebDriverRequest)2 JsonElement (com.google.gson.JsonElement)1