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


Java ReflectionTestUtils.getField方法代碼示例

本文整理匯總了Java中org.springframework.test.util.ReflectionTestUtils.getField方法的典型用法代碼示例。如果您正苦於以下問題:Java ReflectionTestUtils.getField方法的具體用法?Java ReflectionTestUtils.getField怎麽用?Java ReflectionTestUtils.getField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.test.util.ReflectionTestUtils的用法示例。


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

示例1: testCustomizeServletContainer

import org.springframework.test.util.ReflectionTestUtils; //導入方法依賴的package包/類
@Test
public void testCustomizeServletContainer() {
    env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION);
    UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
    webConfigurer.customize(container);
    assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg");
    assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8");
    assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8");
    if (container.getDocumentRoot() != null) {
        assertThat(container.getDocumentRoot().getPath()).isEqualTo(FilenameUtils.separatorsToSystem("target/www"));
    }

    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull();
}
 
開發者ID:oktadeveloper,項目名稱:jhipster-microservices-example,代碼行數:18,代碼來源:WebConfigurerTest.java

示例2: testRegister

import org.springframework.test.util.ReflectionTestUtils; //導入方法依賴的package包/類
@Test
public void testRegister() {
	RegisterMessage registerMessage = new RegisterMessage(1L, "service.add");
	registerMessage.setHeader(WampMessageHeader.WAMP_SESSION_ID, 123L);
	registerMessage.setHeader(WampMessageHeader.WEBSOCKET_SESSION_ID, "one");
	long regId = this.procedureRegistry.register(registerMessage);
	assertThat(regId).isNotEqualTo(-1);

	registerMessage = new RegisterMessage(2L, "service.add");
	registerMessage.setHeader(WampMessageHeader.WAMP_SESSION_ID, 124L);
	registerMessage.setHeader(WampMessageHeader.WEBSOCKET_SESSION_ID, "two");
	long result = this.procedureRegistry.register(registerMessage);
	assertThat(result).isEqualTo(-1);

	Map<String, Procedure> procedures = (Map<String, Procedure>) ReflectionTestUtils
			.getField(this.procedureRegistry, "procedures");
	Map<Long, String> registrations = (Map<Long, String>) ReflectionTestUtils
			.getField(this.procedureRegistry, "registrations");
	assertThat(registrations).hasSize(1);
	assertThat(registrations.get(regId)).isEqualTo("service.add");
	assertThat(procedures).hasSize(1);
	Procedure proc = procedures.get("service.add");
	assertThat(proc.getProcedure()).isEqualTo("service.add");
	assertThat(proc.getRegistrationId()).isEqualTo(regId);
	assertThat(proc.getWebSocketSessionId()).isEqualTo("one");
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:27,代碼來源:ProcedureRegistryTest.java

示例3: testCreateInvocationMessage

import org.springframework.test.util.ReflectionTestUtils; //導入方法依賴的package包/類
@Test
public void testCreateInvocationMessage() {
	RegisterMessage registerMessage = new RegisterMessage(1L, "service.add");
	registerMessage.setHeader(WampMessageHeader.WAMP_SESSION_ID, 123L);
	registerMessage.setHeader(WampMessageHeader.WEBSOCKET_SESSION_ID, "one");
	long regId = this.procedureRegistry.register(registerMessage);
	assertThat(regId).isNotEqualTo(-1);

	CallMessage callMessage = new CallMessage(3L, "service.add");
	callMessage.setHeader(WampMessageHeader.WAMP_SESSION_ID, 124L);
	callMessage.setHeader(WampMessageHeader.WEBSOCKET_SESSION_ID, "two");
	WampMessage msg = this.procedureRegistry.createInvocationMessage(callMessage);
	assertThat(msg).isInstanceOf(InvocationMessage.class);
	InvocationMessage im = (InvocationMessage) msg;
	assertThat(im.getRegistrationId()).isEqualTo(regId);
	assertThat(im.getWebSocketSessionId()).isEqualTo("one");

	Map<Long, CallProc> pendingInvocations = (Map<Long, CallProc>) ReflectionTestUtils
			.getField(this.procedureRegistry, "pendingInvocations");
	assertThat(pendingInvocations).containsOnlyKeys(im.getRequestId());
	CallProc cp = pendingInvocations.get(im.getRequestId());
	assertThat(cp.callMessage).isEqualTo(callMessage);
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:24,代碼來源:ProcedureRegistryTest.java

示例4: testCustomizeServletContainer

import org.springframework.test.util.ReflectionTestUtils; //導入方法依賴的package包/類
@Test
public void testCustomizeServletContainer() {
    env.setActiveProfiles(JHipsterConstants.SPRING_PROFILE_PRODUCTION);
    UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
    webConfigurer.customize(container);
    assertThat(container.getMimeMappings().get("abs")).isEqualTo("audio/x-mpeg");
    assertThat(container.getMimeMappings().get("html")).isEqualTo("text/html;charset=utf-8");
    assertThat(container.getMimeMappings().get("json")).isEqualTo("text/html;charset=utf-8");

    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isNull();
}
 
開發者ID:xm-online,項目名稱:xm-gate,代碼行數:15,代碼來源:WebConfigurerTest.java

示例5: testUndertowHttp2Enabled

import org.springframework.test.util.ReflectionTestUtils; //導入方法依賴的package包/類
@Test
public void testUndertowHttp2Enabled() {
    props.getHttp().setVersion(JHipsterProperties.Http.Version.V_2_0);
    UndertowEmbeddedServletContainerFactory container = new UndertowEmbeddedServletContainerFactory();
    webConfigurer.customize(container);
    Builder builder = Undertow.builder();
    container.getBuilderCustomizers().forEach(c -> c.customize(builder));
    OptionMap.Builder serverOptions = (OptionMap.Builder) ReflectionTestUtils.getField(builder, "serverOptions");
    assertThat(serverOptions.getMap().get(UndertowOptions.ENABLE_HTTP2)).isTrue();
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:11,代碼來源:WebConfigurerTest.java

示例6: setUp

import org.springframework.test.util.ReflectionTestUtils; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
  controller = new NotificationControllerV2();
  gson = new Gson();

  when(bizConfig.releaseMessageNotificationBatch()).thenReturn(100);
  when(bizConfig.releaseMessageNotificationBatchIntervalInMilli()).thenReturn(5);

  ReflectionTestUtils.setField(controller, "releaseMessageService", releaseMessageService);
  ReflectionTestUtils.setField(controller, "entityManagerUtil", entityManagerUtil);
  ReflectionTestUtils.setField(controller, "namespaceUtil", namespaceUtil);
  ReflectionTestUtils.setField(controller, "watchKeysUtil", watchKeysUtil);
  ReflectionTestUtils.setField(controller, "gson", gson);
  ReflectionTestUtils.setField(controller, "bizConfig", bizConfig);

  someAppId = "someAppId";
  someCluster = "someCluster";
  defaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  defaultNamespace = ConfigConsts.NAMESPACE_APPLICATION;
  somePublicNamespace = "somePublicNamespace";
  someDataCenter = "someDC";
  someNotificationId = 1;
  someClientIp = "someClientIp";

  when(namespaceUtil.filterNamespaceName(defaultNamespace)).thenReturn(defaultNamespace);
  when(namespaceUtil.filterNamespaceName(somePublicNamespace)).thenReturn(somePublicNamespace);
  when(namespaceUtil.normalizeNamespace(someAppId, defaultNamespace)).thenReturn(defaultNamespace);
  when(namespaceUtil.normalizeNamespace(someAppId, somePublicNamespace)).thenReturn(somePublicNamespace);

  deferredResults =
      (Multimap<String, DeferredResultWrapper>) ReflectionTestUtils.getField(controller, "deferredResults");
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:33,代碼來源:NotificationControllerV2Test.java

示例7: setup

import org.springframework.test.util.ReflectionTestUtils; //導入方法依賴的package包/類
@Before
public void setup(){
  mapper = (ObjectMapper) ReflectionTestUtils.getField(SpeechletRequestEnvelope.class, "OBJECT_MAPPER");

  toTestQuery.calendarService = mock(CalendarService.class);

  try{
    toTestBasic.speechService = spy(toTestBasic.speechService);
    toTestQuery.speechService = spy(toTestQuery.speechService);
    toTestNewEvent.speechService = spy(toTestNewEvent.speechService);
  }catch(MockitoException e){
    //don't spy a spy...
  }
}
 
開發者ID:rainu,項目名稱:alexa-skill,代碼行數:15,代碼來源:CalendarSpeechletIT.java

示例8: testHandleMessage

import org.springframework.test.util.ReflectionTestUtils; //導入方法依賴的package包/類
@Test
public void testHandleMessage() throws Exception {
  String someWatchKey = "someWatchKey";
  String anotherWatchKey = "anotherWatchKey";
  String someCacheKey = "someCacheKey";
  String anotherCacheKey = "anotherCacheKey";
  String someValue = "someValue";

  ReleaseMessage someReleaseMessage = mock(ReleaseMessage.class);
  when(someReleaseMessage.getMessage()).thenReturn(someWatchKey);

  Cache<String, String> cache =
      (Cache<String, String>) ReflectionTestUtils.getField(configFileController, "localCache");
  cache.put(someCacheKey, someValue);
  cache.put(anotherCacheKey, someValue);

  watchedKeys2CacheKey.putAll(someWatchKey, Lists.newArrayList(someCacheKey, anotherCacheKey));
  watchedKeys2CacheKey.putAll(anotherWatchKey, Lists.newArrayList(someCacheKey, anotherCacheKey));

  cacheKey2WatchedKeys.putAll(someCacheKey, Lists.newArrayList(someWatchKey, anotherWatchKey));
  cacheKey2WatchedKeys.putAll(anotherCacheKey, Lists.newArrayList(someWatchKey, anotherWatchKey));

  configFileController.handleMessage(someReleaseMessage, Topics.APOLLO_RELEASE_TOPIC);

  assertTrue(watchedKeys2CacheKey.isEmpty());
  assertTrue(cacheKey2WatchedKeys.isEmpty());
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:28,代碼來源:ConfigFileControllerTest.java

示例9: getApplicationContext

import org.springframework.test.util.ReflectionTestUtils; //導入方法依賴的package包/類
private ApplicationContext getApplicationContext(Object testInstance) {
    try {
        return (ApplicationContext) ReflectionTestUtils.getField(testInstance, "applicationContext");
    } catch (Exception e) {
        throw new IllegalStateException("@TuPactManager requires application context to be present, are you extending AbstractJUnit4SpringContextTests?");
    }
}
 
開發者ID:tyro,項目名稱:pact-spring-mvc,代碼行數:8,代碼來源:TuPactManager.java

示例10: testCreateInvocationMessageError

import org.springframework.test.util.ReflectionTestUtils; //導入方法依賴的package包/類
@Test
public void testCreateInvocationMessageError() {
	CallMessage callMessage = new CallMessage(3L, "service.add");
	callMessage.setHeader(WampMessageHeader.WAMP_SESSION_ID, 124L);
	callMessage.setHeader(WampMessageHeader.WEBSOCKET_SESSION_ID, "two");
	WampMessage msg = this.procedureRegistry.createInvocationMessage(callMessage);
	assertThat(msg).isInstanceOf(ErrorMessage.class);
	ErrorMessage er = (ErrorMessage) msg;
	assertThat(er.getRequestId()).isEqualTo(callMessage.getRequestId());
	assertThat(er.getWebSocketSessionId()).isEqualTo("two");

	Map<Long, CallMessage> pendingInvocations = (Map<Long, CallMessage>) ReflectionTestUtils
			.getField(this.procedureRegistry, "pendingInvocations");
	assertThat(pendingInvocations).isEmpty();
}
 
開發者ID:ralscha,項目名稱:wamp2spring,代碼行數:16,代碼來源:ProcedureRegistryTest.java


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