org.jboss.resteasy.spi.ResteasyUriInfo Java Examples

The following examples show how to use org.jboss.resteasy.spi.ResteasyUriInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidVariantEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 6 votes vote down vote up
@Test
public void registerAndroidVariantShouldReturn404WhenPushAppDoesNotExist() {
    final AndroidVariant variant = new AndroidVariant();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/abc", "", "push");
    final PushApplication pushApp = new PushApplication();

    when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(null);

    final Response response = this.endpoint.registerAndroidVariant(variant, "push-app-id", uriInfo);

    assertEquals(response.getStatus(), 404);

    verify(variantService, never()).addVariant(any());
    verify(validator, never()).validate(any());
    verify(pushAppService, never()).addVariant(any(), any());
}
 
Example #2
Source File: iOSVariantEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRegisteriOSVariantSuccessfully() {
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/abc", "", "push");
    final PushApplication pushApp = new PushApplication();

    final iOSApplicationUploadForm form = new iOSApplicationUploadForm();
    form.setName("variant name");
    form.setCertificate("certificate".getBytes());
    form.setProduction(false);

    when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp);
    when(validator.validate(form)).thenReturn(Collections.EMPTY_SET);

    final Response response = this.endpoint.registeriOSVariant(form, "push-app-id", uriInfo);

    assertEquals(response.getStatus(), 201);
    final iOSVariant createdVariant = (iOSVariant) response.getEntity();
    assertEquals(createdVariant.getName(), "variant name");
    assertEquals(response.getMetadata().get("location").get(0).toString(), "http://example.org/abc/" + createdVariant.getVariantID());

    verify(variantService).addVariant(createdVariant);
    verify(pushAppService).addVariant(pushApp, createdVariant);
}
 
Example #3
Source File: DisabledByEnvironmentTest.java    From aerogear-unifiedpush-server with Apache License 2.0 6 votes vote down vote up
@Test
public void doNotAbortIfNotInVariable() throws IOException, ServletException {
    System.setProperty("UPS_DISABLED", "");
    DisabledVariantEndpointFilter localFilter = new DisabledVariantEndpointFilter();
    ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/rest/applications/fake-push-id/android", "",
            "");
    uriInfo.pushCurrentResource(new AndroidVariantEndpoint());
    ContainerRequestContext context = mock(ContainerRequestContext.class);
    when(context.getUriInfo()).thenReturn(uriInfo);
    doThrow(new RuntimeException("This should not be aborted.")).when(context).abortWith(Matchers.any());
    
    try {
        localFilter.filter(context);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}
 
Example #4
Source File: InstallationManagementEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGenerateHeaderLinksLastPage() throws URISyntaxException {
    //given
    final ResteasyUriInfo uriInfo = getUriInfo();

    //when
    final LinkHeader linkHeader = endpoint.getLinkHeader(3, 3, uriInfo);

    final Link prev = findLinkByRel(linkHeader, "prev");
    assertThat(prev).isNotNull();
    assertThat(prev.getHref()).isEqualTo("/?page=2");
    final Link first = findLinkByRel(linkHeader, "first");
    assertThat(first).isNotNull();
    assertThat(first.getHref()).isEqualTo("/?page=0");
    assertThat(findLinkByRel(linkHeader, "last")).isNull();
}
 
Example #5
Source File: InstallationManagementEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGenerateHeaderLinksNormalPage() throws URISyntaxException {
    //given
    final ResteasyUriInfo uriInfo = getUriInfo();

    //when
    final LinkHeader linkHeader = endpoint.getLinkHeader(2, 3, uriInfo);

    final Link prev = findLinkByRel(linkHeader, "prev");
    assertThat(prev).isNotNull();
    assertThat(prev.getHref()).isEqualTo("/?page=1");
    final Link next = findLinkByRel(linkHeader, "next");
    assertThat(next).isNotNull();
    assertThat(next.getHref()).isEqualTo("/?page=3");

}
 
Example #6
Source File: WebPushVariantEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 6 votes vote down vote up
@Test
public void registerWebPushVariantShouldReturn400WhenVariantModelIsNotValid() {
    final WebPushVariant variant = new WebPushVariant();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/abc", "", "push");
    final PushApplication pushApp = new PushApplication();

    when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp);
    when(validator.validate(variant)).thenReturn(Sets.newHashSet(sampleViolation));

    final Response response = this.endpoint.registerWebPushVariant(variant, "push-app-id", uriInfo);

    assertEquals(response.getStatus(), 400);

    verify(variantService, never()).addVariant(variant);
    verify(pushAppService, never()).addVariant(pushApp, variant);
}
 
Example #7
Source File: WebPushVariantEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 6 votes vote down vote up
@Test
public void registerWebPushVariantShouldReturn404WhenPushAppDoesNotExist() {
    final WebPushVariant variant = new WebPushVariant();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/abc", "", "push");
    final PushApplication pushApp = new PushApplication();

    when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(null);

    final Response response = this.endpoint.registerWebPushVariant(variant, "push-app-id", uriInfo);

    assertEquals(response.getStatus(), 404);

    verify(variantService, never()).addVariant(any());
    verify(validator, never()).validate(any());
    verify(pushAppService, never()).addVariant(any(), any());
}
 
Example #8
Source File: WebPushVariantEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRegisterWebPushVariantSuccessfully() {
    final WebPushVariant variant = new WebPushVariant();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/abc", "", "push");
    final PushApplication pushApp = new PushApplication();

    when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp);
    when(validator.validate(variant)).thenReturn(Collections.EMPTY_SET);

    final Response response = this.endpoint.registerWebPushVariant(variant, "push-app-id", uriInfo);

    assertEquals(response.getStatus(), 201);
    assertTrue(response.getEntity() == variant);        // identity check
    assertEquals(response.getMetadata().get("location").get(0).toString(), "http://example.org/abc/" + variant.getVariantID());

    verify(variantService).addVariant(variant);
    verify(pushAppService).addVariant(pushApp, variant);
}
 
Example #9
Source File: AndroidVariantEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 6 votes vote down vote up
@Test
public void registerAndroidVariantShouldReturn400WhenVariantModelIsNotValid() {
    final AndroidVariant variant = new AndroidVariant();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/abc", "", "push");
    final PushApplication pushApp = new PushApplication();

    when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp);
    when(validator.validate(variant)).thenReturn(Sets.newHashSet(sampleViolation));

    final Response response = this.endpoint.registerAndroidVariant(variant, "push-app-id", uriInfo);

    assertEquals(response.getStatus(), 400);

    verify(variantService, never()).addVariant(variant);
    verify(pushAppService, never()).addVariant(pushApp, variant);
}
 
Example #10
Source File: AndroidVariantEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldRegisterAndroidVariantSuccessfully() {
    final AndroidVariant variant = new AndroidVariant();
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/abc", "", "push");
    final PushApplication pushApp = new PushApplication();

    when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp);
    when(validator.validate(variant)).thenReturn(Collections.EMPTY_SET);

    final Response response = this.endpoint.registerAndroidVariant(variant, "push-app-id", uriInfo);

    assertEquals(response.getStatus(), 201);
    assertTrue(response.getEntity() == variant);        // identity check
    assertEquals(response.getMetadata().get("location").get(0).toString(), "http://example.org/abc/" + variant.getVariantID());

    verify(variantService).addVariant(variant);
    verify(pushAppService).addVariant(pushApp, variant);
}
 
Example #11
Source File: iOSTokenVariantEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRegisteriOSTokenVariantSuccessfully() {
    final ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/abc", "", "push");
    final PushApplication pushApp = new PushApplication();

    final iOSTokenVariant form = new iOSTokenVariant();
    form.setName("variant name");
    form.setPrivateKey("privateKey");
    form.setTeamId("team id");
    form.setKeyId("key id");
    form.setBundleId("test.my.toe");
    form.setProduction(false);

    when(searchService.findByPushApplicationIDForDeveloper("push-app-id")).thenReturn(pushApp);
    when(validator.validate(form)).thenReturn(Collections.EMPTY_SET);

    final Response response = this.endpoint.registeriOSVariant(form, "push-app-id", uriInfo);

    assertEquals(response.getStatus(), 201);
    final iOSTokenVariant createdVariant = (iOSTokenVariant) response.getEntity();
    assertEquals(createdVariant.getName(), "variant name");
    assertEquals(createdVariant.getPrivateKey(), "privateKey");
    assertEquals(createdVariant.getTeamId(), "team id");
    assertEquals(createdVariant.getKeyId(), "key id");
    assertEquals(createdVariant.getBundleId(), "test.my.toe");


    assertEquals(response.getMetadata().get("location").get(0).toString(), "http://example.org/abc/" + createdVariant.getVariantID());

    verify(variantService).addVariant(createdVariant);
    verify(pushAppService).addVariant(pushApp, createdVariant);
}
 
Example #12
Source File: DisabledByEnvironmentTest.java    From aerogear-unifiedpush-server with Apache License 2.0 5 votes vote down vote up
@Test
public void androidEnvDisablesAndroid() throws IOException {
    ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/rest/applications/fake-push-id/android", "",
            "");
    uriInfo.pushCurrentResource(new AndroidVariantEndpoint());
    runTest(uriInfo);
}
 
Example #13
Source File: DisabledByEnvironmentTest.java    From aerogear-unifiedpush-server with Apache License 2.0 5 votes vote down vote up
private void runTest(ResteasyUriInfo uriInfo) {
    ContainerRequestContext context = mock(ContainerRequestContext.class);
    when(context.getUriInfo()).thenReturn(uriInfo);
    ArgumentCaptor<Response> argument = ArgumentCaptor.forClass(Response.class);

    try {
        filter.filter(context);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    verify(context).abortWith(argument.capture());

    assertEquals(404, argument.getValue().getStatus());
}
 
Example #14
Source File: InstallationManagementEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGenerateHeaderLinksFirstPage() throws URISyntaxException {
    //given
    final ResteasyUriInfo uriInfo = getUriInfo();

    //when
    final LinkHeader linkHeader = endpoint.getLinkHeader(0, 3, uriInfo);

    //then
    assertThat(findLinkByRel(linkHeader, "prev")).isNull();
    final Link next = findLinkByRel(linkHeader, "next");
    assertThat(next).isNotNull();
    assertThat(next.getHref()).isEqualTo("/?page=1");
    assertThat(findLinkByRel(linkHeader, "first")).isNull();
}
 
Example #15
Source File: SynchronousDispatcherInterceptorTest.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws URISyntaxException {
    synchronousDispatcherInterceptor = new SynchronousDispatcherInterceptor();
    exceptionInterceptor = new SynchronousDispatcherExceptionInterceptor();
    when(request.getUri()).thenReturn(new ResteasyUriInfo(new URI("http://localhost:8080/test/testRequestURL")));
    when(request.getHttpHeaders()).thenReturn(new ResteasyHttpHeaders(new MultivaluedMapImpl<String, String>()));
    when(response.getStatus()).thenReturn(200);
    when(request.getAsyncContext()).thenReturn(resteasyAsynchronousContext);
    when(request.getAsyncContext().isSuspended()).thenReturn(false);
    arguments = new Object[] {
        request,
        response,
        resourceInvoker
    };
    argumentType = new Class[] {
        request.getClass(),
        response.getClass(),
        resourceInvoker.getClass()
    };

    exceptionArguments = new Object[] {
        request,
        response,
        new RuntimeException()
    };
    exceptionArgumentType = new Class[] {
        request.getClass(),
        response.getClass(),
        new RuntimeException().getClass()
    };
}
 
Example #16
Source File: SearchUtilsTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void buildQueryRemoveSelectedParametersIncludingDefault() {
  ResteasyUriInfo uriInfo = new ResteasyUriInfo(URI, QUERY_STRING, CONTEXT_PATH);
  String query = underTest.buildQuery(uriInfo, singletonList("wait")).toString();

  assertQueryParameters(query, not(containsString("wait")));
}
 
Example #17
Source File: SearchUtilsTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void buildQueryRemoveContinuationTokenByDefault() {
  ResteasyUriInfo uriInfo = new ResteasyUriInfo(URI, QUERY_STRING, CONTEXT_PATH);
  String query = underTest.buildQuery(uriInfo).toString();

  assertQueryParameters(query, containsString("wait"));
}
 
Example #18
Source File: DisabledByEnvironmentTest.java    From aerogear-unifiedpush-server with Apache License 2.0 4 votes vote down vote up
@Test
public void iosEnvDisablesIOS() {
    ResteasyUriInfo uriInfo = new ResteasyUriInfo("http://example.org/rest/applications/fake-push-id/ios", "", "");
    uriInfo.pushCurrentResource(new iOSVariantEndpoint());
    runTest(uriInfo);
}
 
Example #19
Source File: VertxPluginRequestHandler.java    From redpipe with Apache License 2.0 4 votes vote down vote up
@Override
public void handle(HttpServerRequest request)
{
   request.bodyHandler(buff -> {
      Context ctx = vertx.getOrCreateContext();
      ResteasyUriInfo uriInfo = VertxUtil.extractUriInfo(request.getDelegate(), servletMappingPrefix);
      ResteasyHttpHeaders headers = VertxUtil.extractHttpHeaders(request.getDelegate());
      HttpServerResponse response = request.response();
      VertxHttpResponse vertxResponse = new VertxHttpResponseWithWorkaround(response.getDelegate(), dispatcher.getProviderFactory(), request.method());
      VertxHttpRequest vertxRequest = new VertxHttpRequest(ctx.getDelegate(), headers, uriInfo, request.rawMethod(), dispatcher.getDispatcher(), vertxResponse, false);
      if (buff.length() > 0)
      {
         ByteBufInputStream in = new ByteBufInputStream(buff.getDelegate().getByteBuf());
         vertxRequest.setInputStream(in);
      }

      try
      {
     	AppGlobals.set(appGlobals);
     	appGlobals.injectGlobals();
         dispatcher.service(ctx.getDelegate(), request.getDelegate(), response.getDelegate(), vertxRequest, vertxResponse, true);
      } catch (Failure e1)
      {
         vertxResponse.setStatus(e1.getErrorCode());
      } catch (Exception ex)
      {
         vertxResponse.setStatus(500);
         LogMessages.LOGGER.error(Messages.MESSAGES.unexpected(), ex);
      }
      finally 
      {
     	 AppGlobals.set(null);
      }
      if (!vertxRequest.getAsyncContext().isSuspended())
      {
         try
         {
            vertxResponse.finish();
         } catch (IOException e)
         {
            e.printStackTrace();
         }
      }
   });
}
 
Example #20
Source File: InstallationManagementEndpointTest.java    From aerogear-unifiedpush-server with Apache License 2.0 4 votes vote down vote up
private ResteasyUriInfo getUriInfo() throws URISyntaxException {
    return new ResteasyUriInfo(new URI("/"), new URI("http://localhost"));
}
 
Example #21
Source File: RenderDataServiceTest.java    From render with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testGetAndSaveResolvedTiles() throws Exception {

    final ResolvedTileSpecCollection resolvedTiles = service.getResolvedTiles(alignStackId.getOwner(),
                                                                              alignStackId.getProject(),
                                                                              alignStackId.getStack(),
                                                                              Z);

    validateResolvedTiles("before save", resolvedTiles, 1, 1);

    final LeafTransformSpec leafTransformSpecA = new LeafTransformSpec("test_transform_a",
                                                                      null,
                                                                      "mpicbg.trakem2.transform.AffineModel2D",
                                                                      "1  0  0  1  0  0");
    resolvedTiles.addTransformSpecToCollection(leafTransformSpecA);
    resolvedTiles.addReferenceTransformToAllTiles(leafTransformSpecA.getId(), false);

    final StackId testStackId = new StackId(alignStackId.getOwner(), alignStackId.getProject(), "test");

    final UriInfo uriInfo = new ResteasyUriInfo(new URI("http://test/resolvedTiles"),
                                                new URI("http://test"));

    service.saveResolvedTilesForZ(testStackId.getOwner(),
                                  testStackId.getProject(),
                                  testStackId.getStack(),
                                  Z,
                                  null,
                                  uriInfo,
                                  resolvedTiles);

    final ResolvedTileSpecCollection resolvedTestTiles = service.getResolvedTiles(testStackId.getOwner(),
                                                                                  testStackId.getProject(),
                                                                                  testStackId.getStack(),
                                                                                  Z);

    validateResolvedTiles("after save", resolvedTestTiles, 1, 2);

    final TransformSpec leafTransformSpecB = new LeafTransformSpec("test_transform_b",
                                                                   null,
                                                                   "mpicbg.trakem2.transform.AffineModel2D",
                                                                   "1  0  0  1  0  0");
    final TileSpec tileSpecB = new TileSpec();
    tileSpecB.setTileId("test_tile_b");
    tileSpecB.setZ(Z);
    tileSpecB.addTransformSpecs(Collections.singletonList(leafTransformSpecB));
    tileSpecB.setWidth(10.0);
    tileSpecB.setHeight(10.0);
    tileSpecB.deriveBoundingBox(tileSpecB.getMeshCellSize(), false);

    resolvedTestTiles.addTileSpecToCollection(tileSpecB);

    service.saveResolvedTilesForZ(testStackId.getOwner(),
                                  testStackId.getProject(),
                                  testStackId.getStack(),
                                  Z,
                                  null,
                                  uriInfo,
                                  resolvedTestTiles);

    final ResolvedTileSpecCollection resolvedTest2Tiles = service.getResolvedTiles(testStackId.getOwner(),
                                                                                   testStackId.getProject(),
                                                                                   testStackId.getStack(),
                                                                                   Z);

    validateResolvedTiles("after second save", resolvedTest2Tiles, 2, 2);
}
 
Example #22
Source File: StackMetaDataServiceTest.java    From render with GNU General Public License v2.0 4 votes vote down vote up
private static UriInfo getUriInfo()
        throws URISyntaxException {
    return new ResteasyUriInfo(new URI("http://test/stack"),
                               new URI("http://test"));
}
 
Example #23
Source File: SearchResourceTest.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private UriInfo uriInfo(final String uri) {
  return new ResteasyUriInfo(URI.create(uri));
}