Search in sources :

Example 21 with ResteasyUriInfo

use of org.jboss.resteasy.spi.ResteasyUriInfo in project microservice_framework by CJSCommonPlatform.

the class EventPageResourceTest method shouldReturnBadRequestWhenFirstEventsRequestedWithBackwardDirection.

@Test(expected = BadRequestException.class)
public void shouldReturnBadRequestWhenFirstEventsRequestedWithBackwardDirection() throws Exception {
    final String streamId = randomUUID().toString();
    final UriInfo uriInfo = new ResteasyUriInfo("" + "/" + streamId, "", "");
    final URL fixedUrl = new URL("http://localhost:8080/rest/fixed");
    final Page<EventEntry> page = new Page<>(emptyList(), pagingLinksBuilder(fixedUrl, fixedUrl).build());
    when(eventsPageService.pageEvents(UUID.fromString(streamId), FIRST, BACKWARD, 10, uriInfo)).thenReturn(page);
    resource.events(streamId, FIRST, BACKWARD.toString(), 10, uriInfo);
}
Also used : EventEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) Page(uk.gov.justice.services.eventsourcing.source.api.service.Page) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) UriInfo(javax.ws.rs.core.UriInfo) URL(java.net.URL) Test(org.junit.Test)

Example 22 with ResteasyUriInfo

use of org.jboss.resteasy.spi.ResteasyUriInfo in project microservice_framework by CJSCommonPlatform.

the class EventPageResourceTest method shouldReturnFeedReturnedByService.

@Test
public void shouldReturnFeedReturnedByService() throws Exception {
    final UUID streamId = randomUUID();
    final String position = "2";
    final String positionValue = "2";
    final int pageSize = 10;
    final UriInfo uriInfo = new ResteasyUriInfo("" + "/" + streamId, "", "");
    final URL fixedUrl = new URL("http://localhost:8080/rest/fixed");
    final Page<EventEntry> page = new Page<>(emptyList(), pagingLinksBuilder(fixedUrl, fixedUrl).build());
    when(eventsPageService.pageEvents(streamId, position, FORWARD, pageSize, uriInfo)).thenReturn(page);
    final JsonObjectBuilder jsonObjectBuilder = Json.createObjectBuilder();
    jsonObjectBuilder.add("key", "value");
    when(converter.convert(page)).thenReturn(jsonObjectBuilder.build());
    resource.events(streamId.toString(), positionValue, FORWARD.toString(), pageSize, uriInfo);
    final ArgumentCaptor<UUID> uuidArgumentCaptor = ArgumentCaptor.forClass(UUID.class);
    final ArgumentCaptor<String> positionCaptor = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Integer> pageSizeCaptor = ArgumentCaptor.forClass(Integer.class);
    final ArgumentCaptor<UriInfo> uriInfoCaptor = ArgumentCaptor.forClass(UriInfo.class);
    final ArgumentCaptor<Direction> directionCaptor = ArgumentCaptor.forClass(Direction.class);
    verify(eventsPageService).pageEvents(uuidArgumentCaptor.capture(), positionCaptor.capture(), directionCaptor.capture(), pageSizeCaptor.capture(), uriInfoCaptor.capture());
    assertThat(positionCaptor.getValue(), is(position));
    assertThat(pageSizeCaptor.getValue(), is(pageSize));
    assertThat(uriInfoCaptor.getValue(), is(uriInfo));
    assertThat(directionCaptor.getValue(), is(FORWARD));
    assertThat(uuidArgumentCaptor.getValue(), is(streamId));
}
Also used : ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) Page(uk.gov.justice.services.eventsourcing.source.api.service.Page) Direction(uk.gov.justice.services.eventsourcing.source.api.service.core.Direction) URL(java.net.URL) EventEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry) UUID(java.util.UUID) UUID.randomUUID(java.util.UUID.randomUUID) JsonObjectBuilder(javax.json.JsonObjectBuilder) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 23 with ResteasyUriInfo

use of org.jboss.resteasy.spi.ResteasyUriInfo in project microservice_framework by CJSCommonPlatform.

the class EventPageResourceTest method shouldReturnBadRequestWhenHeadEventsRequestedWithForwardDirection.

@Test(expected = BadRequestException.class)
public void shouldReturnBadRequestWhenHeadEventsRequestedWithForwardDirection() throws Exception {
    final String streamId = randomUUID().toString();
    final UriInfo uriInfo = new ResteasyUriInfo("" + "/" + streamId, "", "");
    final URL fixedUrl = new URL("http://localhost:8080/rest/fixed");
    final Page<EventEntry> page = new Page<>(emptyList(), pagingLinksBuilder(fixedUrl, fixedUrl).build());
    when(eventsPageService.pageEvents(UUID.fromString(streamId), HEAD, FORWARD, 10, uriInfo)).thenReturn(page);
    resource.events(streamId, HEAD, FORWARD.toString(), 10, uriInfo);
}
Also used : EventEntry(uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) Page(uk.gov.justice.services.eventsourcing.source.api.service.Page) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) UriInfo(javax.ws.rs.core.UriInfo) URL(java.net.URL) Test(org.junit.Test)

Example 24 with ResteasyUriInfo

use of org.jboss.resteasy.spi.ResteasyUriInfo in project dubbo by alibaba.

the class DubboSwaggerApiListingResourceTest method test.

@Test
public void test() throws Exception {
    DubboSwaggerApiListingResource resource = new DubboSwaggerApiListingResource();
    app = mock(Application.class);
    sc = mock(ServletConfig.class);
    Set<Class<?>> sets = new HashSet<Class<?>>();
    sets.add(SwaggerService.class);
    when(sc.getServletContext()).thenReturn(mock(ServletContext.class));
    when(app.getClasses()).thenReturn(sets);
    Response response = resource.getListingJson(app, sc, null, new ResteasyUriInfo(new URI("http://rest.test")));
    Assertions.assertNotNull(response);
    Swagger swagger = (Swagger) response.getEntity();
    Assertions.assertEquals("SwaggerService", swagger.getTags().get(0).getName());
    Assertions.assertEquals("/demoService/hello", swagger.getPaths().keySet().toArray()[0].toString());
}
Also used : Response(javax.ws.rs.core.Response) ResteasyUriInfo(org.jboss.resteasy.spi.ResteasyUriInfo) Swagger(io.swagger.models.Swagger) ServletConfig(javax.servlet.ServletConfig) ServletContext(javax.servlet.ServletContext) Application(javax.ws.rs.core.Application) URI(java.net.URI) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Aggregations

ResteasyUriInfo (org.jboss.resteasy.spi.ResteasyUriInfo)24 Test (org.junit.Test)23 URL (java.net.URL)20 UUID (java.util.UUID)14 UUID.randomUUID (java.util.UUID.randomUUID)14 ArrayList (java.util.ArrayList)12 EventEntry (uk.gov.justice.services.eventsourcing.source.api.service.core.EventEntry)10 Position (uk.gov.justice.services.eventsourcing.source.api.service.core.Position)10 EventStreamEntry (uk.gov.justice.services.eventsourcing.source.api.service.core.EventStreamEntry)7 UriInfo (javax.ws.rs.core.UriInfo)6 UtcClock (uk.gov.justice.services.common.util.UtcClock)6 Page (uk.gov.justice.services.eventsourcing.source.api.service.Page)6 Direction (uk.gov.justice.services.eventsourcing.source.api.service.core.Direction)4 EventStreamPageEntry (uk.gov.justice.services.eventsourcing.source.api.service.EventStreamPageEntry)3 JsonObject (javax.json.JsonObject)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 ResteasyHttpHeaders (org.jboss.resteasy.specimpl.ResteasyHttpHeaders)2 WebQuery (com.peterphi.std.guice.restclient.jaxb.webquery.WebQuery)1 Swagger (io.swagger.models.Swagger)1 URI (java.net.URI)1