本文整理汇总了Java中javax.ws.rs.core.Configuration.getContracts方法的典型用法代码示例。如果您正苦于以下问题:Java Configuration.getContracts方法的具体用法?Java Configuration.getContracts怎么用?Java Configuration.getContracts使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.core.Configuration
的用法示例。
在下文中一共展示了Configuration.getContracts方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldRegisterAMultiTypedProviderInstanceWithPriorities
import javax.ws.rs.core.Configuration; //导入方法依赖的package包/类
@Test
public void shouldRegisterAMultiTypedProviderInstanceWithPriorities() {
MultiTypedProvider provider = new MultiTypedProvider();
Map<Class<?>, Integer> priorities = new HashMap<>();
priorities.put(ClientRequestFilter.class, 500);
priorities.put(ClientResponseFilter.class, 501);
priorities.put(MessageBodyReader.class, 502);
priorities.put(MessageBodyWriter.class, 503);
priorities.put(ReaderInterceptor.class, 504);
priorities.put(WriterInterceptor.class, 505);
priorities.put(ResponseExceptionMapper.class, 506);
priorities.put(ParamConverterProvider.class, 507);
RestClientBuilder builder = RestClientBuilder.newBuilder().register(provider, priorities);
Configuration configuration = builder.getConfiguration();
assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
assertTrue(configuration.isRegistered(provider), MultiTypedProvider.class + " should be registered");
Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class);
assertEquals(contracts.size(), priorities.size(),
"There should be "+priorities.size()+" provider types registered");
for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) {
Integer contractPriority = contracts.get(priority.getKey());
assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue());
}
}
示例2: testRegister
import javax.ws.rs.core.Configuration; //导入方法依赖的package包/类
@Test
public void testRegister() throws Exception {
logger.info("start Register test");
Client client = newClient();
Map<Class<?>, Integer> myContracts = new HashMap<Class<?>, Integer>();
myContracts.put(Feature.class, 1200);
client.register(MyComponent.class, myContracts);
Configuration configuration = client.getConfiguration();
Set<Class<?>> classes = configuration.getClasses();
for (Class<?> clazz : classes) {
if (MyComponent.class.isAssignableFrom(clazz)) {
Map<Class<?>, Integer> contracts = configuration.getContracts(clazz);
int priority = contracts.get(Feature.class);
assertTrue("Only standard: Feature, DynamicFeature, WriterInterceptor, "
+ "ReaderInterceptor, ContainerResponseFilter, " + "ContainerRequestFilter, "
+ "ClientResponseFilter, ClientRequestFilter, " + "ExceptionMapper, MessageBodyWriter, "
+ "MessageBodyReader,ParamConverterProvider or implemented: InjectorFactory, "
+ "StringParameterUnmarshaller, StringConverter, " + "ContextResolver, PostProcessInterceptor, "
+ "PreProcessInterceptor, ClientExecutionInterceptor, ClientExceptionMapper"
+ "can be registered as contracts. Registered priority", priority == 1200);
}
}
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:24,代码来源:ComponentTestCase.java
示例3: shouldRegisterAMultiTypedProviderClassWithPriorities
import javax.ws.rs.core.Configuration; //导入方法依赖的package包/类
@Test
public void shouldRegisterAMultiTypedProviderClassWithPriorities() {
Map<Class<?>, Integer> priorities = new HashMap<>();
priorities.put(ClientRequestFilter.class, 500);
priorities.put(ClientResponseFilter.class, 501);
priorities.put(MessageBodyReader.class, 502);
priorities.put(MessageBodyWriter.class, 503);
priorities.put(ReaderInterceptor.class, 504);
priorities.put(WriterInterceptor.class, 505);
priorities.put(ResponseExceptionMapper.class, 506);
priorities.put(ParamConverterProvider.class, 507);
RestClientBuilder builder = RestClientBuilder.newBuilder().register(MultiTypedProvider.class, priorities);
Configuration configuration = builder.getConfiguration();
assertTrue(configuration.isRegistered(MultiTypedProvider.class), MultiTypedProvider.class + " should be registered");
Map<Class<?>, Integer> contracts = configuration.getContracts(MultiTypedProvider.class);
assertEquals(contracts.size(), priorities.size(),
"There should be "+priorities.size()+" provider types registered");
for(Map.Entry<Class<?>, Integer> priority : priorities.entrySet()) {
Integer contractPriority = contracts.get(priority.getKey());
assertEquals(contractPriority, priority.getValue(), "The priority for "+priority.getKey()+" should be "+priority.getValue());
}
}
示例4: testConfiguration
import javax.ws.rs.core.Configuration; //导入方法依赖的package包/类
@Test
public void testConfiguration() throws Exception {
logger.info("start REST Configuration test");
Client client = newClient();
Configuration configuration = client.getConfiguration();
Set<Class<?>> classes = configuration.getClasses();
for (Class<?> clazz : classes) {
assertTrue("verify if the class is a rest component or provider",
MessageBodyReader.class.isAssignableFrom(clazz) || MessageBodyWriter.class.isAssignableFrom(clazz)
|| clazz.isAnnotationPresent(Provider.class)
|| DynamicFeature.class.isAssignableFrom(clazz));
Map<Class<?>, Integer> contracts = configuration.getContracts(clazz);
assertFalse("each class has different contracts", contracts.isEmpty());
for (Class<?> contract : contracts.keySet()) {
int value = contracts.get(contract);
assertTrue("verify if the contract is a rest component or provider",
value == 5000 || value == 4000 || value == 3000 || value == 0);
}
}
Set<Object> instances = configuration.getInstances();
assertTrue("by default there are not instances", instances.isEmpty());
Map<String, Object> properties = configuration.getProperties();
assertTrue("by default there are not properties", properties.isEmpty());
MyComponent myComponent = new MyComponent();
client.register(myComponent);
instances = configuration.getInstances();
assertFalse("Added instance", instances.isEmpty());
for (Object instance : instances) {
if (instance instanceof MyComponent)
assertTrue("MyComponent is registered and active", configuration.isEnabled((Feature) instance));
}
assertEquals("Added property through MyComponent", 1, properties.size());
boolean property = (Boolean) properties.get("configured_myComponent");
assertEquals("configured_myComponent ok!", true, property);
assertEquals("type CLIENT by default", CLIENT, configuration.getRuntimeType());
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:37,代码来源:ComponentTestCase.java
示例5: shouldRegisterInstanceWithPriority
import javax.ws.rs.core.Configuration; //导入方法依赖的package包/类
@Test
public void shouldRegisterInstanceWithPriority() {
Integer priority = 1000;
TestClientRequestFilter instance = new TestClientRequestFilter();
RestClientBuilder builder = RestClientBuilder.newBuilder().register(instance, priority);
Configuration configuration = builder.getConfiguration();
assertTrue(configuration.isRegistered(TestClientRequestFilter.class), TestClientRequestFilter.class + " should be registered");
assertTrue(configuration.isRegistered(instance), TestClientRequestFilter.class + " should be registered");
Map<Class<?>, Integer> contracts = configuration.getContracts(TestClientRequestFilter.class);
assertEquals(contracts.size(), 1, "There should be a registered contract for "+TestClientRequestFilter.class);
assertEquals(contracts.get(ClientRequestFilter.class), priority, "The priority for "+TestClientRequestFilter.class+" should be 1000");
}
示例6: shouldRegisterProvidersWithPriority
import javax.ws.rs.core.Configuration; //导入方法依赖的package包/类
@Test
public void shouldRegisterProvidersWithPriority() {
Integer priority = 1000;
RestClientBuilder builder = RestClientBuilder.newBuilder().register(TestClientRequestFilter.class, priority);
Configuration configuration = builder.getConfiguration();
assertTrue(configuration.isRegistered(TestClientRequestFilter.class), TestClientRequestFilter.class + " should be registered");
Map<Class<?>, Integer> contracts = configuration.getContracts(TestClientRequestFilter.class);
assertEquals(contracts.size(), 1, "There should be a registered contract for "+TestClientRequestFilter.class);
assertEquals(contracts.get(ClientRequestFilter.class), priority, "The priority for "+TestClientRequestFilter.class+" should be 1000");
}