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


Java Configuration.getContracts方法代碼示例

本文整理匯總了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());
    }
}
 
開發者ID:eclipse,項目名稱:microprofile-rest-client,代碼行數:25,代碼來源:AdditionalRegistrationTest.java

示例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());
    }
}
 
開發者ID:eclipse,項目名稱:microprofile-rest-client,代碼行數:23,代碼來源:AdditionalRegistrationTest.java

示例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");
}
 
開發者ID:eclipse,項目名稱:microprofile-rest-client,代碼行數:13,代碼來源:AdditionalRegistrationTest.java

示例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");
}
 
開發者ID:eclipse,項目名稱:microprofile-rest-client,代碼行數:11,代碼來源:AdditionalRegistrationTest.java


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