本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
}
示例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);
}
示例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();
}
示例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();
}
示例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);
}
示例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));
}
示例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));
}
示例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());
}
示例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);
}
示例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"));
}