Search in sources :

Example 1 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class BackendServicesTest method derivesApplicationIdsOnOriginsWhenUsingYamlConstructor.

@Test
public void derivesApplicationIdsOnOriginsWhenUsingYamlConstructor() {
    BackendService before = BackendService.newBackendServiceBuilder().id("generic_app").origins(newOriginBuilder("localhost", 8080).id("origin1").build()).build();
    BackendServices backendServices = new BackendServices(singletonList(before));
    Origin origin = first(backendServices.first().origins());
    assertThat(origin.applicationId(), is(id("generic_app")));
}
Also used : Origin(com.hotels.styx.api.extension.Origin) BackendService(com.hotels.styx.api.extension.service.BackendService) Test(org.junit.jupiter.api.Test)

Example 2 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class YamlApplicationsProviderTest method readsBackendAppsWithHttpConfiguration.

@Test
public void readsBackendAppsWithHttpConfiguration() throws Exception {
    List<BackendService> backends = backendsAsList(loadApplicationsFrom(ORIGINS_FILE));
    BackendService httpApp = backends.get(0);
    assertThat(httpApp.protocol(), is(HTTP));
    assertThat(httpApp.tlsSettings(), is(Optional.empty()));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class YamlApplicationsProviderTest method readsBackendsAppsWithHttpsConfiguration.

@Test
public void readsBackendsAppsWithHttpsConfiguration() throws Exception {
    List<BackendService> backends = backendsAsList(loadApplicationsFrom(ORIGINS_FILE));
    BackendService secureApp = backends.get(1);
    assertThat(secureApp.protocol(), is(HTTPS));
    assertThat(secureApp.tlsSettings(), is(Optional.of(new TlsSettings.Builder().authenticate(true).sslProvider("JDK").additionalCerts(certificate("my certificate", "/path/to/mycert"), certificate("alt certificatfe", "/path/to/altcert")).trustStorePath("/path/to/truststore").trustStorePassword("truststore-123").build())));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class YamlApplicationsProviderTest method readsBackendsAppsWithOldHttpsConfiguration.

@Test
public void readsBackendsAppsWithOldHttpsConfiguration() throws Exception {
    List<BackendService> backends = backendsAsList(loadApplicationsFrom(OLD_ORIGINS_FILE));
    BackendService secureApp = backends.get(1);
    assertThat(secureApp.protocol(), is(HTTPS));
    assertThat(secureApp.tlsSettings(), is(Optional.of(new TlsSettings.Builder().authenticate(true).sslProvider("JDK").additionalCerts(certificate("my certificate", "/path/to/mycert"), certificate("alt certificatfe", "/path/to/altcert")).trustStorePath("/path/to/truststore").trustStorePassword("truststore-123").build())));
}
Also used : BackendService(com.hotels.styx.api.extension.service.BackendService) TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with BackendService

use of com.hotels.styx.api.extension.service.BackendService in project styx by ExpediaGroup.

the class FileBackedRegistryTest method announcesInitialStateWhenStarts.

@Test
public void announcesInitialStateWhenStarts() throws IOException {
    Resource configurationFile = mockResource("/styx/config", new ByteArrayInputStream(originalContent));
    registry = new FileBackedRegistry<>(configurationFile, bytes -> List.of(backendService), any -> true);
    registry.addListener(listener);
    await(registry.reload());
    verify(listener).onChange(eq(changeSet().added(backendService).build()));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Registry(com.hotels.styx.api.extension.service.spi.Registry) ReloadResult(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StyxFutures.await(com.hotels.styx.common.StyxFutures.await) IOException(java.io.IOException) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ReloadResult.unchanged(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.unchanged) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) List(java.util.List) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(com.hotels.styx.api.Resource) JustATestException(com.hotels.styx.support.JustATestException) Matchers.eq(org.mockito.Matchers.eq) BackendService(com.hotels.styx.api.extension.service.BackendService) ReloadResult.reloaded(com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.reloaded) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Mockito.mock(org.mockito.Mockito.mock) ByteArrayInputStream(java.io.ByteArrayInputStream) Resource(com.hotels.styx.api.Resource) Test(org.junit.jupiter.api.Test)

Aggregations

BackendService (com.hotels.styx.api.extension.service.BackendService)37 Test (org.junit.jupiter.api.Test)36 Registry (com.hotels.styx.api.extension.service.spi.Registry)11 JustATestException (com.hotels.styx.support.JustATestException)8 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)7 MicrometerRegistry (com.hotels.styx.api.MicrometerRegistry)7 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)7 MeterRegistry (com.hotels.styx.api.MeterRegistry)6 Resource (com.hotels.styx.api.Resource)6 MemoryBackedRegistry (com.hotels.styx.infrastructure.MemoryBackedRegistry)6 IOException (java.io.IOException)6 HttpHandler (com.hotels.styx.api.HttpHandler)5 ReloadResult (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult)5 ReloadResult.reloaded (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.reloaded)5 ReloadResult.unchanged (com.hotels.styx.api.extension.service.spi.Registry.ReloadResult.unchanged)5 StyxFutures.await (com.hotels.styx.common.StyxFutures.await)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)5 List (java.util.List)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5