当前位置: 首页>>代码示例>>Java>>正文


Java ResourceTestRule.Builder方法代码示例

本文整理汇总了Java中io.dropwizard.testing.junit.ResourceTestRule.Builder方法的典型用法代码示例。如果您正苦于以下问题:Java ResourceTestRule.Builder方法的具体用法?Java ResourceTestRule.Builder怎么用?Java ResourceTestRule.Builder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.dropwizard.testing.junit.ResourceTestRule的用法示例。


在下文中一共展示了ResourceTestRule.Builder方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setUpResources

import io.dropwizard.testing.junit.ResourceTestRule; //导入方法依赖的package包/类
/**
 * Call this method to set up authentication in the test's Jersey client.
 */
public static void setUpResources(ResourceTestRule.Builder test, SecurityManager securityManager) {
    JerseyAuthConfiguration config = JerseyAuthConfigurationBuilder.build(securityManager);

    addResourceFilterFactories(test, config);
    for (Object provider : config.getProviderInstances()) {
        test.addProvider(provider);
    }
    for (Class<?> providerClass : config.getProviderClasses()) {
        test.addProvider(providerClass);
    }
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:15,代码来源:ResourceTestAuthUtil.java

示例2: addResourceFilterFactories

import io.dropwizard.testing.junit.ResourceTestRule; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static void addResourceFilterFactories(ResourceTestRule.Builder test, JerseyAuthConfiguration config) {
    // The ability to add properties is normally protected so we need to break in to update the resource filter
    // factories.
    Map<String, Object> properties;
    try {
        Field field = ResourceTestRule.Builder.class.getDeclaredField("properties");
        field.setAccessible(true);
        properties = (Map<String, Object>) field.get(test);
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }

    List resourceFilterFactories;

    // Add the new resource filter factories to any existing values
    Object existing = properties.get(PackagesResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES);
    if (existing == null) {
        resourceFilterFactories = config.getResourceFilterFactories();
    } else {
        resourceFilterFactories = Lists.newArrayList();
        if (existing.getClass().isArray()) {
            resourceFilterFactories.addAll(Arrays.asList((Object[]) existing));
        } else if (Iterable.class.isAssignableFrom(existing.getClass())) {
            Iterables.addAll(resourceFilterFactories, (Iterable) existing);
        } else {
            resourceFilterFactories.add(existing);
        }
        resourceFilterFactories.addAll(config.getResourceFilterFactories());
    }

    properties.put(PackagesResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES, resourceFilterFactories);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:34,代码来源:ResourceTestAuthUtil.java

示例3: setupResourceTestRule

import io.dropwizard.testing.junit.ResourceTestRule; //导入方法依赖的package包/类
protected ResourceTestRule setupResourceTestRule()  {
    ResourceTestRule.Builder resourceTestRuleBuilder = ResourceTestRule.builder();

    ResourceTestAuthUtil.setUpResources(resourceTestRuleBuilder, SecurityManagerBuilder.create()
            .withAuthIdentityReader(_authIdentityDAO)
            .withPermissionReader(_permissionDAO)
            .withAnonymousAccessAs("anon")
            .build());

    resourceTestRuleBuilder.addResource(new ExplicitPermissionResource());
    resourceTestRuleBuilder.addResource(new PathPermissionResource());
    resourceTestRuleBuilder.addResource(new QueryPermissionResource());

    return resourceTestRuleBuilder.build();
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:16,代码来源:ResourcePermissionsTest.java

示例4: setupResourceTestRule

import io.dropwizard.testing.junit.ResourceTestRule; //导入方法依赖的package包/类
protected ResourceTestRule setupResourceTestRule()  {
    ResourceTestRule.Builder resourceTestRuleBuilder = ResourceTestRule.builder();

    CacheRegistry cacheRegistry = new DefaultCacheRegistry(new SimpleLifeCycleRegistry(), new MetricRegistry());
    _cacheManager = new GuavaCacheManager(cacheRegistry);

    //noinspection unchecked
    Supplier<String> idSupplier = mock(Supplier.class);
    when(idSupplier.get()).thenReturn("id0", "id1").thenThrow(new IllegalStateException("Unexpected createIdentity call"));
    
    InMemoryAuthIdentityManager<ApiKey> authIdentityDAO = new InMemoryAuthIdentityManager<>(idSupplier);
    _authIdentityCaching = new CacheManagingAuthIdentityManager<>(authIdentityDAO, _cacheManager);
    _authIdentityManager = spy(_authIdentityCaching);

    InMemoryPermissionManager permissionDAO = new InMemoryPermissionManager(new MatchingPermissionResolver());
    _permissionCaching = new CacheManagingPermissionManager(permissionDAO, _cacheManager);
    _permissionManager = spy(_permissionCaching);

    authIdentityDAO.createIdentity("testkey", new ApiKeyModification().addRoles("testrole"));
    authIdentityDAO.createIdentity("othertestkey", new ApiKeyModification().addRoles("testrole"));

    permissionDAO.updatePermissions(PermissionIDs.forRole("testrole"), new PermissionUpdateRequest().permit("city|get|Madrid", "country|get|Spain"));

    ResourceTestAuthUtil.setUpResources(resourceTestRuleBuilder, SecurityManagerBuilder.create()
            .withAuthIdentityReader(_authIdentityManager)
            .withPermissionReader(_permissionManager)
            .withCacheManager(_cacheManager)
            .withAnonymousAccessAs("anon")
            .build());

    resourceTestRuleBuilder.addResource(new ExplicitPermissionResource());

    return resourceTestRuleBuilder.build();
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:35,代码来源:CachingTest.java

示例5: setUpResources

import io.dropwizard.testing.junit.ResourceTestRule; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected ResourceTestRule.Builder setUpResources(ResourceTestRule.Builder builder) {
    verificationStorage = mock(MetadataStorage.class);
    processor = mock(VerificationProcessor.class);

    return super.setUpResources(builder)
            .addResource(new VerificationResource(processor))
            .addProvider(new VerificationMetadataProvider(verificationStorage));
}
 
开发者ID:yammer,项目名称:backups,代码行数:11,代码来源:VerificationResourceTest.java

示例6: setUpResources

import io.dropwizard.testing.junit.ResourceTestRule; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected ResourceTestRule.Builder setUpResources(ResourceTestRule.Builder builder) {
    processor = mock(BackupProcessor.class);
    clientPermissionStorage = mock(MetadataStorage.class);
    backupStorage = mock(MetadataStorage.class);
    final MetadataStorage<Node> nodeStorage = mock(MetadataStorage.class);

    when(clientPermissionStorage.get(anyString(), anyString()))
        .thenReturn(Optional.<ClientPermission>absent());
    when(clientPermissionStorage.get(eq(SERVICE_NAME), eq(TOKEN)))
        .thenReturn(Optional.of(new ClientPermission(TOKEN,SERVICE_NAME)));
    try {
        when(nodeStorage.get(eq(OTHER_NODE), eq(OTHER_NODE)))
            .thenReturn(Optional.of(new Node(OTHER_NODE, new URL(OTHER_NODE_URL))));
        when(nodeStorage.get(eq(LOCAL_NODE), eq(LOCAL_NODE)))
            .thenReturn(Optional.of(new Node(LOCAL_NODE, new URL(LOCAL_NODE_URL))));
    }
    catch (MalformedURLException e) {
        throw Throwables.propagate(e);
    }

    final TemporaryTokenGenerator tokenGenerator = mock(TemporaryTokenGenerator.class);
    return super.setUpResources(builder)
            .addProvider(new TokenAuthProvider<>(new TokenAuthenticator(clientPermissionStorage, tokenGenerator)))
            .addResource(new BackupResource(processor, clientPermissionStorage, LOCAL_NODE))
            .addProvider(new BackupMetadataProvider(backupStorage))
            .addProvider(new IncorrectNodeExceptionMapper(nodeStorage));
}
 
开发者ID:yammer,项目名称:backups,代码行数:30,代码来源:BackupResourceTest.java

示例7: setUpResources

import io.dropwizard.testing.junit.ResourceTestRule; //导入方法依赖的package包/类
protected ResourceTestRule.Builder setUpResources(ResourceTestRule.Builder builder) {
    return builder.addProvider(new SingletonTypeInjectableProvider<Context, HttpServletRequest>(HttpServletRequest.class, REQUEST) {})
            .addProvider(new NoContentExceptionMapper())
            .addProvider(new MetadataNotFoundExceptionMapper())
            .addProvider(new InvalidMD5ExceptionMapper())
            .addProvider(new IllegalStateExceptionMapper());
}
 
开发者ID:yammer,项目名称:backups,代码行数:8,代码来源:AbstractBackupServiceResourceTest.java

示例8: setupResourceTestRule

import io.dropwizard.testing.junit.ResourceTestRule; //导入方法依赖的package包/类
protected static ResourceTestRule setupResourceTestRule(List<Object> resourceList, List<Object> filters,
                                                        AuthIdentityManager<ApiKey> authIdentityManager,
                                                        PermissionManager permissionManager) {
    ResourceTestRule.Builder resourceTestRuleBuilder = ResourceTestRule.builder();

    for (Object resource : resourceList) {
        resourceTestRuleBuilder.addResource(resource);
    }

    List<ResourceFilterFactory> resourceFilterFactories = Lists.newArrayList();
    List<ContainerRequestFilter> containerRequestFilters = Lists.newArrayList();
    List<ContainerResponseFilter> containerResponseFilters = Lists.newArrayList();

    for (Object filter : filters) {
        if (filter instanceof ResourceFilterFactory) {
            resourceFilterFactories.add((ResourceFilterFactory) filter);
        }
        if (filter instanceof ContainerRequestFilter) {
            containerRequestFilters.add((ContainerRequestFilter) filter);
        }
        if (filter instanceof ContainerResponseFilter) {
            containerResponseFilters.add((ContainerResponseFilter) filter);
        }
    }

    resourceTestRuleBuilder.addProperty(ResourceConfig.PROPERTY_RESOURCE_FILTER_FACTORIES, resourceFilterFactories);
    resourceTestRuleBuilder.addProperty(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, containerRequestFilters);
    resourceTestRuleBuilder.addProperty(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, containerResponseFilters);

    // Jersey tests don't inject Context parameters, so create an injector to provide a mock instance.
    resourceTestRuleBuilder.addProvider(new DatabusJerseyTest.ContextInjectableProvider<>(HttpServletRequest.class, mock(HttpServletRequest.class)));

    ResourceTestAuthUtil.setUpResources(resourceTestRuleBuilder, SecurityManagerBuilder.create()
            .withAuthIdentityReader(authIdentityManager)
            .withPermissionReader(permissionManager)
            .build());

    for (Object mapper : ExceptionMappers.getMappers()) {
        resourceTestRuleBuilder.addProvider(mapper);
    }
    for (Class mapperType : ExceptionMappers.getMapperTypes()) {
        resourceTestRuleBuilder.addProvider(mapperType);
    }

    ResourceTestRule resourceTestRule = resourceTestRuleBuilder.build();

    // Write Date objects using ISO8601 strings instead of numeric milliseconds-since-1970.
    SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
    resourceTestRule.getObjectMapper().setDateFormat(fmt);

    return resourceTestRule;
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:54,代码来源:ResourceTest.java

示例9: createRule

import io.dropwizard.testing.junit.ResourceTestRule; //导入方法依赖的package包/类
protected static ResourceTestRule.Builder createRule() {
    return ResourceTestRule.builder()
            .addProvider(new BasicAuthProvider<>(new DummyAuthenticator("username", "password", Data.Player1.PLAYER), "test"));
}
 
开发者ID:phxql,项目名称:restwars,代码行数:5,代码来源:AbstractResourceTest.java

示例10: builder

import io.dropwizard.testing.junit.ResourceTestRule; //导入方法依赖的package包/类
public static ResourceTestRule.Builder builder() {
    return new ResourceTestRule.Builder()
            .addProvider(OptionalMessageBodyWriter.class)
            .addProvider(OptionalParamFeature.class);
}
 
开发者ID:dropwizard,项目名称:dropwizard-java8,代码行数:6,代码来源:ResourceTestRuleBuilder.java


注:本文中的io.dropwizard.testing.junit.ResourceTestRule.Builder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。