Search in sources :

Example 1 with HttpEndpoint

use of io.gravitee.gateway.http.core.endpoint.HttpEndpoint in project gravitee-gateway by gravitee-io.

the class DefaultEndpointLifecycleManagerTest method shouldStartEndpoint.

@Test
public void shouldStartEndpoint() throws Exception {
    io.gravitee.definition.model.Endpoint endpoint = mock(io.gravitee.definition.model.endpoint.HttpEndpoint.class);
    when(endpoint.getName()).thenReturn("endpoint");
    when(endpoint.isBackup()).thenReturn(false);
    when(endpoint.getType()).thenReturn(EndpointType.HTTP);
    when(proxy.getEndpoints()).thenReturn(Collections.singleton(endpoint));
    when(applicationContext.getBean(Connector.class, endpoint)).thenReturn(mock(Connector.class));
    endpointLifecycleManager.start();
    HttpEndpoint httpClientEndpoint = (HttpEndpoint) endpointLifecycleManager.get("endpoint");
    assertNotNull(httpClientEndpoint);
    verify(applicationContext, times(1)).getBean(eq(Connector.class), any(Endpoint.class));
    verify(httpClientEndpoint.connector(), times(1)).start();
    assertEquals(httpClientEndpoint, endpointLifecycleManager.get("endpoint"));
    assertNull(endpointLifecycleManager.get("unknown"));
    assertFalse(endpointLifecycleManager.endpoints().isEmpty());
}
Also used : Connector(io.gravitee.gateway.api.Connector) Endpoint(io.gravitee.gateway.api.endpoint.Endpoint) HttpEndpoint(io.gravitee.gateway.http.core.endpoint.HttpEndpoint) HttpEndpoint(io.gravitee.gateway.http.core.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 2 with HttpEndpoint

use of io.gravitee.gateway.http.core.endpoint.HttpEndpoint in project gravitee-gateway by gravitee-io.

the class MultiTenantAwareEndpointLifecycleManagerTest method shouldStartEndpoint_inTenant.

@Test
public void shouldStartEndpoint_inTenant() throws Exception {
    io.gravitee.definition.model.Endpoint endpoint = mock(io.gravitee.definition.model.endpoint.HttpEndpoint.class);
    when(endpoint.getName()).thenReturn("endpoint");
    when(endpoint.getTenants()).thenReturn(Collections.singletonList("europe"));
    when(endpoint.isBackup()).thenReturn(false);
    when(endpoint.getType()).thenReturn(EndpointType.HTTP);
    when(proxy.getEndpoints()).thenReturn(Collections.singleton(endpoint));
    when(applicationContext.getBean(Connector.class, endpoint)).thenReturn(mock(Connector.class));
    endpointLifecycleManager.start();
    HttpEndpoint httpClientEndpoint = (HttpEndpoint) endpointLifecycleManager.get("endpoint");
    assertNotNull(httpClientEndpoint);
    verify(applicationContext, times(1)).getBean(eq(Connector.class), any(Endpoint.class));
    verify(httpClientEndpoint.connector(), times(1)).start();
    assertEquals(httpClientEndpoint, endpointLifecycleManager.get("endpoint"));
    assertNull(endpointLifecycleManager.get("unknown"));
    assertFalse(endpointLifecycleManager.endpoints().isEmpty());
}
Also used : Connector(io.gravitee.gateway.api.Connector) Endpoint(io.gravitee.gateway.api.endpoint.Endpoint) HttpEndpoint(io.gravitee.gateway.http.core.endpoint.HttpEndpoint) HttpEndpoint(io.gravitee.gateway.http.core.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 3 with HttpEndpoint

use of io.gravitee.gateway.http.core.endpoint.HttpEndpoint in project gravitee-gateway by gravitee-io.

the class DefaultEndpointLifecycleManager method start.

public void start(io.gravitee.definition.model.Endpoint endpoint) {
    try {
        logger.info("Create new endpoint: name[{}] type[{}] target[{}]", endpoint.getName(), endpoint.getType(), endpoint.getTarget());
        if (endpoint.getType() == EndpointType.HTTP) {
            // TODO: Later, when multiple endpoint type will be supported,
            // select the connector factory according to the endpoint type
            Connector connector = applicationContext.getBean(Connector.class, endpoint);
            connector.start();
            HttpEndpoint httpEndpoint = new HttpEndpoint((io.gravitee.definition.model.endpoint.HttpEndpoint) endpoint, connector);
            endpoints.add(httpEndpoint);
            endpointsByName.put(endpoint.getName(), httpEndpoint);
            endpointsTarget.put(endpoint.getName(), endpoint.getTarget());
        }
    } catch (Exception ex) {
        logger.error("Unexpected error while creating endpoint connector", ex);
    }
}
Also used : Connector(io.gravitee.gateway.api.Connector) HttpEndpoint(io.gravitee.gateway.http.core.endpoint.HttpEndpoint)

Example 4 with HttpEndpoint

use of io.gravitee.gateway.http.core.endpoint.HttpEndpoint in project gravitee-gateway by gravitee-io.

the class DefaultEndpointLifecycleManagerTest method shouldStopEndpoint.

@Test
public void shouldStopEndpoint() throws Exception {
    // First, start an endpoint
    io.gravitee.definition.model.Endpoint endpoint = mock(io.gravitee.definition.model.endpoint.HttpEndpoint.class);
    when(endpoint.getName()).thenReturn("endpoint");
    when(endpoint.isBackup()).thenReturn(false);
    when(endpoint.getType()).thenReturn(EndpointType.HTTP);
    when(proxy.getEndpoints()).thenReturn(Collections.singleton(endpoint));
    when(applicationContext.getBean(Connector.class, endpoint)).thenReturn(mock(Connector.class));
    endpointLifecycleManager.start();
    assertFalse(endpointLifecycleManager.endpoints().isEmpty());
    HttpEndpoint httpClientEndpoint = (HttpEndpoint) endpointLifecycleManager.get("endpoint");
    // Then, stop endpoint
    endpointLifecycleManager.stop();
    // Verify that the HTTP client is correctly stopped
    verify(httpClientEndpoint.connector(), times(1)).stop();
    assertTrue(endpointLifecycleManager.endpoints().isEmpty());
}
Also used : Connector(io.gravitee.gateway.api.Connector) HttpEndpoint(io.gravitee.gateway.http.core.endpoint.HttpEndpoint) Test(org.junit.Test)

Example 5 with HttpEndpoint

use of io.gravitee.gateway.http.core.endpoint.HttpEndpoint in project gravitee-gateway by gravitee-io.

the class MultiTenantAwareEndpointLifecycleManagerTest method shouldStartEndpoint_noTenant.

@Test
public void shouldStartEndpoint_noTenant() throws Exception {
    io.gravitee.definition.model.Endpoint endpoint = mock(io.gravitee.definition.model.endpoint.HttpEndpoint.class);
    when(endpoint.getName()).thenReturn("endpoint");
    when(endpoint.isBackup()).thenReturn(false);
    when(endpoint.getType()).thenReturn(EndpointType.HTTP);
    when(proxy.getEndpoints()).thenReturn(Collections.singleton(endpoint));
    when(applicationContext.getBean(Connector.class, endpoint)).thenReturn(mock(Connector.class));
    endpointLifecycleManager.start();
    HttpEndpoint httpClientEndpoint = (HttpEndpoint) endpointLifecycleManager.get("endpoint");
    assertNotNull(httpClientEndpoint);
    verify(applicationContext, times(1)).getBean(eq(Connector.class), any(Endpoint.class));
    verify(httpClientEndpoint.connector(), times(1)).start();
    assertEquals(httpClientEndpoint, endpointLifecycleManager.get("endpoint"));
    assertNull(endpointLifecycleManager.get("unknown"));
    assertFalse(endpointLifecycleManager.endpoints().isEmpty());
}
Also used : Connector(io.gravitee.gateway.api.Connector) Endpoint(io.gravitee.gateway.api.endpoint.Endpoint) HttpEndpoint(io.gravitee.gateway.http.core.endpoint.HttpEndpoint) HttpEndpoint(io.gravitee.gateway.http.core.endpoint.HttpEndpoint) Test(org.junit.Test)

Aggregations

Connector (io.gravitee.gateway.api.Connector)5 HttpEndpoint (io.gravitee.gateway.http.core.endpoint.HttpEndpoint)5 Test (org.junit.Test)4 Endpoint (io.gravitee.gateway.api.endpoint.Endpoint)3