當前位置: 首頁>>代碼示例>>Java>>正文


Java ResourceTestRule類代碼示例

本文整理匯總了Java中io.dropwizard.testing.junit.ResourceTestRule的典型用法代碼示例。如果您正苦於以下問題:Java ResourceTestRule類的具體用法?Java ResourceTestRule怎麽用?Java ResourceTestRule使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ResourceTestRule類屬於io.dropwizard.testing.junit包,在下文中一共展示了ResourceTestRule類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setupResourceTestRule

import io.dropwizard.testing.junit.ResourceTestRule; //導入依賴的package包/類
private ResourceTestRule setupResourceTestRule() {
    final InMemoryAuthIdentityManager<ApiKey> authIdentityManager = new InMemoryAuthIdentityManager<>();
    authIdentityManager.createIdentity(APIKEY_BLOB, new ApiKeyModification().addRoles("blob-role"));
    authIdentityManager.createIdentity(APIKEY_UNAUTHORIZED, new ApiKeyModification().addRoles("unauthorized-role"));
    authIdentityManager.createIdentity(APIKEY_BLOB_A, new ApiKeyModification().addRoles("blob-role-a"));
    authIdentityManager.createIdentity(APIKEY_BLOB_B, new ApiKeyModification().addRoles("blob-role-b"));

    final EmoPermissionResolver permissionResolver = new EmoPermissionResolver(mock(DataStore.class), _server);
    final InMemoryPermissionManager permissionManager = new InMemoryPermissionManager(permissionResolver);
    final RoleManager roleManager = new InMemoryRoleManager(permissionManager);

    createRole(roleManager, null, "blob-role", ImmutableSet.of("blob|*|*"));
    createRole(roleManager, null, "blob-role-a", ImmutableSet.of("blob|read|a*"));
    createRole(roleManager, null, "blob-role-b", ImmutableSet.of("blob|read|b*"));

    return setupResourceTestRule(
        Collections.<Object>singletonList(new BlobStoreResource1(_server, _approvedContentTypes)),
        authIdentityManager,
        permissionManager);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:21,代碼來源:BlobStoreJerseyTest.java

示例2: setupResourceTestRule

import io.dropwizard.testing.junit.ResourceTestRule; //導入依賴的package包/類
private ResourceTestRule setupResourceTestRule() {
    final InMemoryAuthIdentityManager<ApiKey> authIdentityManager = new InMemoryAuthIdentityManager<>();
    _stashKeyId = authIdentityManager.createIdentity(STASH_API_KEY, new ApiKeyModification().addRoles("stash"));
    _unauthKeyId = authIdentityManager.createIdentity(UNAUTH_API_KEY, new ApiKeyModification());

    final EmoPermissionResolver permissionResolver = new EmoPermissionResolver(mock(DataStore.class), mock(BlobStore.class));
    final InMemoryPermissionManager permissionManager = new InMemoryPermissionManager(permissionResolver);
    final RoleManager roleManager = new InMemoryRoleManager(permissionManager);

    roleManager.createRole(RoleIdentifier.fromString("stash"),
            new RoleModification()
                    .withName("stash")
                    .withPermissionUpdate(new PermissionUpdateRequest().permit("stash|*")));

    _scanUploader = mock(ScanUploader.class);
    _stashRequestManager = mock(StashRequestManager.class);

    return setupResourceTestRule(
            ImmutableList.of(new StashResource1(_scanUploader, _stashRequestManager)),
            authIdentityManager,
            permissionManager);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:23,代碼來源:StashJerseyTest.java

示例3: setupDataStoreResourceTestRule

import io.dropwizard.testing.junit.ResourceTestRule; //導入依賴的package包/類
private ResourceTestRule setupDataStoreResourceTestRule() {
    InMemoryAuthIdentityManager<ApiKey> authIdentityManager = new InMemoryAuthIdentityManager<>();
    authIdentityManager.createIdentity(APIKEY_TABLE, new ApiKeyModification().addRoles("table-role"));
    authIdentityManager.createIdentity(APIKEY_READ_TABLES_A, new ApiKeyModification().addRoles("tables-a-role"));
    authIdentityManager.createIdentity(APIKEY_READ_TABLES_B, new ApiKeyModification().addRoles("tables-b-role"));
    authIdentityManager.createIdentity(APIKEY_FACADE, new ApiKeyModification().addRoles("facade-role"));
    authIdentityManager.createIdentity(APIKEY_REVIEWS_ONLY, new ApiKeyModification().addRoles("reviews-only-role"));
    authIdentityManager.createIdentity(APIKEY_STANDARD, new ApiKeyModification().addRoles("standard"));
    authIdentityManager.createIdentity(APIKEY_STANDARD_UPDATE, new ApiKeyModification().addRoles("update-with-events"));

    EmoPermissionResolver permissionResolver = new EmoPermissionResolver(_server, mock(BlobStore.class));
    InMemoryPermissionManager permissionManager = new InMemoryPermissionManager(permissionResolver);
    RoleManager roleManager = new InMemoryRoleManager(permissionManager);

    createRole(roleManager, null, "table-role", ImmutableSet.of("sor|*|*"));
    createRole(roleManager, null, "tables-a-role", ImmutableSet.of("sor|read|a*"));
    createRole(roleManager, null, "tables-b-role", ImmutableSet.of("sor|read|b*"));
    createRole(roleManager, null, "facade-role", ImmutableSet.of("facade|*|*"));
    createRole(roleManager, null, "reviews-only-role", ImmutableSet.of("sor|*|if({..,\"type\":\"review\"})"));
    createRole(roleManager, null, "standard", DefaultRoles.standard.getPermissions());
    createRole(roleManager, null, "update-with-events", ImmutableSet.of("sor|update|*"));

    return setupResourceTestRule(Collections.<Object>singletonList(new DataStoreResource1(_server, mock(DataStoreAsync.class))), authIdentityManager, permissionManager);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:25,代碼來源:DataStoreJerseyTest.java

示例4: setupResourceTestRule

import io.dropwizard.testing.junit.ResourceTestRule; //導入依賴的package包/類
private ResourceTestRule setupResourceTestRule() {
    _authIdentityManager = new InMemoryAuthIdentityManager<>();
    _authIdentityManager.createIdentity(UAC_ALL_API_KEY, new ApiKeyModification().addRoles("uac-all"));

    final EmoPermissionResolver permissionResolver = new EmoPermissionResolver(mock(DataStore.class), mock(BlobStore.class));
    final InMemoryPermissionManager permissionManager = new InMemoryPermissionManager(permissionResolver);
    _roleManager = new InMemoryRoleManager(permissionManager);

    LocalSubjectUserAccessControl uac = new LocalSubjectUserAccessControl(_roleManager, permissionResolver,
            _authIdentityManager, HostAndPort.fromParts("localhost", 8080), new MetricRegistry());
    
    createRole(_roleManager, null, "uac-all", ImmutableSet.of("role|*", "apikey|*"));
    createRole(_roleManager, null, "uac-none", ImmutableSet.of());

    return setupResourceTestRule(
            ImmutableList.of(
                    new UserAccessControlResource1(
                            new RoleResource1(uac),
                            new ApiKeyResource1(uac)),
                    new UserAccessControlRequestMessageBodyReader()),
            _authIdentityManager,
            permissionManager);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:24,代碼來源:UserAccessControlJerseyTest.java

示例5: getResources

import io.dropwizard.testing.junit.ResourceTestRule; //導入依賴的package包/類
private ResourceTestRule getResources() {
    return ResourceTestRule.builder()
            .addResource(injector.getInstance(AccountResource.class))
            .addProvider(OptionalMessageBodyWriter.class)
            .addProvider(OptionalParamFeature.class)
            .addProvider(new ServiceExceptionMapper())
            .setRegisterDefaultExceptionMappers(false)
            .build();
}
 
開發者ID:researchgate,項目名稱:restler,代碼行數:10,代碼來源:AccountResourceTest.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: setupDataStoreResourceTestRule

import io.dropwizard.testing.junit.ResourceTestRule; //導入依賴的package包/類
private ResourceTestRule setupDataStoreResourceTestRule() {
    InMemoryAuthIdentityManager<ApiKey> authIdentityManager = new InMemoryAuthIdentityManager<>();
    authIdentityManager.createIdentity(API_KEY, new ApiKeyModification().addRoles("all-sor-role"));
    EmoPermissionResolver permissionResolver = new EmoPermissionResolver(_dataStore, mock(BlobStore.class));
    InMemoryPermissionManager permissionManager = new InMemoryPermissionManager(permissionResolver);
    InMemoryRoleManager roleManager = new InMemoryRoleManager(permissionManager);

    createRole(roleManager, null, "all-sor-role", ImmutableSet.of("sor|*|*"));

    return setupResourceTestRule(
            Collections.<Object>singletonList(new DataStoreResource1(_dataStore, new DefaultDataStoreAsync(_dataStore, mock(JobService.class), mock(JobHandlerRegistry.class)))),
            Collections.<Object>singletonList(new ConcurrentRequestsThrottlingFilter(_deferringRegulatorSupplier)),
            authIdentityManager, permissionManager);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:15,代碼來源:AdHocThrottleTest.java

示例11: 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

示例12: 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

示例13: 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

示例14: setupResourceTestRule

import io.dropwizard.testing.junit.ResourceTestRule; //導入依賴的package包/類
protected static ResourceTestRule setupResourceTestRule(List<Object> resourceList, Map<String, ApiKey> apiKeys,
                                                        Multimap<String, String> permissionsByRole) {
    return setupResourceTestRule(resourceList, ImmutableList.of(), apiKeys, permissionsByRole);
}
 
開發者ID:bazaarvoice,項目名稱:emodb,代碼行數:5,代碼來源:ResourceTest.java

示例15: 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


注:本文中的io.dropwizard.testing.junit.ResourceTestRule類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。