Search in sources :

Example 1 with StyxObjectStore

use of com.hotels.styx.routing.db.StyxObjectStore in project styx by ExpediaGroup.

the class ServiceProviderHandlerTest method returnsNotFoundStatusWithNonHandledUrl.

@Test
public void returnsNotFoundStatusWithNonHandledUrl() {
    StyxObjectStore<StyxObjectRecord<StyxService>> empty = new StyxObjectStore<>();
    ServiceProviderHandler handler = new ServiceProviderHandler(empty);
    HttpRequest request = HttpRequest.get("/not/my/url").build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), equalTo(NOT_FOUND));
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) StyxObjectStore(com.hotels.styx.routing.db.StyxObjectStore) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 2 with StyxObjectStore

use of com.hotels.styx.routing.db.StyxObjectStore in project styx by ExpediaGroup.

the class ProviderListHandlerTest method showsEndpointsForAllConfiguredProviders.

@Test
public void showsEndpointsForAllConfiguredProviders() throws JsonProcessingException {
    JsonNode config = new ObjectMapper().readTree("{\"setting1\" : \"A\", \"setting2\" : \"A\"}");
    StyxObjectStore<StyxObjectRecord<StyxService>> store = new StyxObjectStore<>();
    store.insert("Service-A1", new StyxObjectRecord<>("ServiceA", new HashSet<>(), config, new SampleServiceA("Service-A-1")));
    store.insert("Service-A2", new StyxObjectRecord<>("ServiceA", new HashSet<>(), config, new SampleServiceA("Service-A-2")));
    store.insert("Service-B", new StyxObjectRecord<>("ServiceB", new HashSet<>(), config, new SampleServiceB("Service-B")));
    ProviderListHandler handler = new ProviderListHandler(store);
    HttpResponse response = Mono.from(handler.handle(get("/").build(), requestContext())).block();
    assertThat(response.status(), equalTo(OK));
    assertThat(response.bodyAs(UTF_8), stringContainsInOrder("Service-A1 (ServiceA)", "<a href=\"/admin/providers/Service-A1/status\">/admin/providers/Service-A1/status</a>", "Service-A2 (ServiceA)", "<a href=\"/admin/providers/Service-A2/status\">/admin/providers/Service-A2/status</a>", "Service-B (ServiceB)", "<a href=\"/admin/providers/Service-B/withslash/\">/admin/providers/Service-B/withslash/</a>", "<a href=\"/admin/providers/Service-B/noslash\">/admin/providers/Service-B/noslash</a>", "<a href=\"/admin/providers/Service-B/\">/admin/providers/Service-B/</a>"));
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) StyxObjectStore(com.hotels.styx.routing.db.StyxObjectStore) HttpResponse(com.hotels.styx.api.HttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with StyxObjectStore

use of com.hotels.styx.routing.db.StyxObjectStore in project styx by ExpediaGroup.

the class ServiceProviderHandlerTest method createTestStore.

private StyxObjectStore<StyxObjectRecord<StyxService>> createTestStore() throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    StyxService mockService = mock(StyxService.class);
    StyxObjectStore<StyxObjectRecord<StyxService>> store = new StyxObjectStore<>();
    JsonNode config1 = mapper.readTree("{\"setting1\" : \"A\", \"setting2\" : \"A\"}");
    StyxObjectRecord<StyxService> rec1 = new StyxObjectRecord<>("Type1", new HashSet<>(Arrays.asList("this=that", "truth=false")), config1, mockService);
    store.insert("object1", rec1);
    JsonNode config2 = mapper.readTree("{\"setting1\" : \"B\", \"setting2\" : \"B\"}");
    StyxObjectRecord<StyxService> rec2 = new StyxObjectRecord<>("Type2", new HashSet<>(Arrays.asList("up=down", "weakness=strength")), config2, mockService);
    store.insert("object2", rec2);
    JsonNode config3 = mapper.readTree("{\"setting1\" : \"C\", \"setting2\" : \"C\"}");
    StyxObjectRecord<StyxService> rec3 = new StyxObjectRecord<>("Type3", new HashSet<>(Arrays.asList("black=white", "left=right")), config3, mockService);
    store.insert("object3", rec3);
    return store;
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) StyxObjectStore(com.hotels.styx.routing.db.StyxObjectStore) StyxService(com.hotels.styx.api.extension.service.spi.StyxService) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with StyxObjectStore

use of com.hotels.styx.routing.db.StyxObjectStore in project styx by ExpediaGroup.

the class ServiceProviderHandlerTest method returnsNoContentStatusWhenNoProvidersAvailable.

@Test
public void returnsNoContentStatusWhenNoProvidersAvailable() {
    StyxObjectStore<StyxObjectRecord<StyxService>> empty = new StyxObjectStore<>();
    ServiceProviderHandler handler = new ServiceProviderHandler(empty);
    HttpRequest request = HttpRequest.get("/admin/service/providers").build();
    HttpResponse response = Mono.from(handler.handle(request, requestContext())).block();
    assertThat(response.status(), equalTo(NO_CONTENT));
    assertFalse(response.contentLength().isPresent());
}
Also used : StyxObjectRecord(com.hotels.styx.StyxObjectRecord) HttpRequest(com.hotels.styx.api.HttpRequest) StyxObjectStore(com.hotels.styx.routing.db.StyxObjectStore) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Aggregations

StyxObjectRecord (com.hotels.styx.StyxObjectRecord)4 StyxObjectStore (com.hotels.styx.routing.db.StyxObjectStore)4 HttpResponse (com.hotels.styx.api.HttpResponse)3 Test (org.junit.jupiter.api.Test)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 HttpRequest (com.hotels.styx.api.HttpRequest)2 StyxService (com.hotels.styx.api.extension.service.spi.StyxService)1 HashSet (java.util.HashSet)1