com.sun.jersey.test.framework.LowLevelAppDescriptor Java Examples

The following examples show how to use com.sun.jersey.test.framework.LowLevelAppDescriptor. 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: AbstractResourceTest.java    From monasca-common with Apache License 2.0 6 votes vote down vote up
@BeforeMethod
protected void beforeTestCase() throws Exception {
  singletons.clear();
  providers.clear();
  features.clear();
  properties.clear();
  setupResources();

  test = new JerseyTest() {
    @Override
    protected AppDescriptor configure() {
      final DropwizardResourceConfig config = DropwizardResourceConfig.forTesting(metricRegistry);
      for (Class<?> provider : providers)
        config.getClasses().add(provider);
      for (Map.Entry<String, Boolean> feature : features.entrySet())
        config.getFeatures().put(feature.getKey(), feature.getValue());
      for (Map.Entry<String, Object> property : properties.entrySet())
        config.getProperties().put(property.getKey(), property.getValue());
      config.getSingletons().add(new JacksonMessageBodyProvider(objectMapper, validator));
      config.getSingletons().addAll(singletons);
      return new LowLevelAppDescriptor.Builder(config).build();
    }
  };

  test.setUp();
}
 
Example #2
Source File: HmacAuthProviderTest.java    From jersey-hmac-auth with Apache License 2.0 5 votes vote down vote up
@Override
protected AppDescriptor configure() {
    this.requestConfiguration = RequestConfiguration.builder().withApiKeyQueryParamName("passkey")
            .withSignatureHttpHeader("duck-duck-signature-header")
            .withTimestampHttpHeader("duck-duck-timestamp-header")
            .withVersionHttpHeader("duck-duck-version-header")
            .build();
    final Authenticator<String> authenticator = new Authenticator<String>() {
        @Override
        public String getApiKeyName() {
            return DEFAULT_API_KEY_PARAM;
        }

        @Override
        public String authenticate(Credentials credentials) {
            if (GOOD_API_KEY.equals(credentials.getApiKey())) {
                return GOOD_API_KEY;
            }
            if (INTERNAL_ERROR.equals(credentials.getApiKey())) {
                throw new IllegalStateException("An internal error occurred");
            }
            return null;
        }
    };

    ResourceConfig config = new ScanningResourceConfig();
    config.getSingletons().add(new HmacAuthProvider<String>(new DefaultRequestHandler<String>(authenticator, requestConfiguration)));
    config.getSingletons().add(new AuthResource());
    return new LowLevelAppDescriptor.Builder(config).build();
}
 
Example #3
Source File: TrimouViewRendererTest.java    From trimou with Apache License 2.0 5 votes vote down vote up
@Override
protected AppDescriptor configure() {
    final DefaultResourceConfig config = new DefaultResourceConfig();
    final ViewRenderer renderer = new TrimouViewRenderer.Builder().build();
    config.getSingletons().add(new ViewMessageBodyWriter(new MetricRegistry(), ImmutableList.of(renderer)));
    config.getSingletons().add(new TestResource());
    return new LowLevelAppDescriptor.Builder(config).build();
}