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


Java ReflectionTestUtils類代碼示例

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


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

示例1: sendRegistrationSuccessEmailSMTP

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@Test
public void sendRegistrationSuccessEmailSMTP() {
    ReflectionTestUtils.setField(sut, "mailEnabled", true);

    String email = "[email protected]";
    String subject = "Your registration was successful";
    String expected = "Hello!\nYour registration was accepted by an administrator";

    sut.sendSuccessEmail(email, "registration");

    ArgumentCaptor<SimpleMailMessage> captor = ArgumentCaptor.forClass(SimpleMailMessage.class);
    verify(sender, times(1)).send(captor.capture());
    SimpleMailMessage message = captor.getValue();


    assertEquals(1, message.getTo().length);
    assertEquals(email, message.getTo()[0]);
    assertEquals(subject, message.getSubject());
    assertEquals(expected, message.getText());
}
 
開發者ID:2DV603NordVisaProject,項目名稱:nordvisa_calendar,代碼行數:21,代碼來源:EmailTest.java

示例2: parseSessionDataFailsIfStampIsExpired

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@Test
public void parseSessionDataFailsIfStampIsExpired() throws Exception {
    ReflectionTestUtils.setField(parser, "clock", expired);

    MultivaluedMap<String,String> initParams = getValidInitParams();
    initParams.putSingle("sessionId", "1234567890");
    when(authenticationHandlerUtils.popFromCache(any())).thenReturn(initParams);

    Map<String,String> attributeNameMap = mock(Map.class);
    when(attributeNameMap.get("B02K_CUSTID")).thenReturn("ATTRNAME_CUSTID");
    when(attributeNameMap.get("B02K_CUSTNAME")).thenReturn("ATTRNAME_CUSTNAME");

    MultivaluedMap<String,String> sessionParams = getValidSessionParamsWithHetu();
    sessionParams.putSingle("sessionId", "1234567890");

    assertNull(parser.parseSessionData(sessionParams));
}
 
開發者ID:vrk-kpa,項目名稱:e-identification-tupas-idp-public,代碼行數:18,代碼來源:SessionParserServiceSessionTest.java

示例3: shouldHaveAwsCredentialsIntanceWhenEndpointUrlIsNotProvidedAndProfileIsProvided

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@Test
public void shouldHaveAwsCredentialsIntanceWhenEndpointUrlIsNotProvidedAndProfileIsProvided() {
    ReflectionTestUtils.setField(config, "ENDPOINT_URL", "");
    ReflectionTestUtils.setField(config, "PROFILE", "default");
    Assert.isInstanceOf(AWSCredentials.class,
            config.awsCredentials(new StubProfileCredentialsProvider()));
}
 
開發者ID:simplymequeeny,項目名稱:dynamodb-client-web-gui,代碼行數:8,代碼來源:AwsConfigTest.java

示例4: setup

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);
    doNothing().when(mockMailService).sendActivationEmail((User) anyObject(), anyString());

    AccountResource accountResource = new AccountResource();
    ReflectionTestUtils.setField(accountResource, "userRepository", userRepository);
    ReflectionTestUtils.setField(accountResource, "userService", userService);
    ReflectionTestUtils.setField(accountResource, "mailService", mockMailService);

    AccountResource accountUserMockResource = new AccountResource();
    ReflectionTestUtils.setField(accountUserMockResource, "userRepository", userRepository);
    ReflectionTestUtils.setField(accountUserMockResource, "userService", mockUserService);
    ReflectionTestUtils.setField(accountUserMockResource, "mailService", mockMailService);

    this.restMvc = MockMvcBuilders.standaloneSetup(accountResource).build();
    this.restUserMockMvc = MockMvcBuilders.standaloneSetup(accountUserMockResource).build();
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:19,代碼來源:AccountResourceTest.java

示例5: portEightyShortenURL

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@Test
public void portEightyShortenURL() {
    when(env.getProperty("local.server.port")).thenReturn("80");
    ReflectionTestUtils.setField(sut, "mailEnabled", false);
    String id = "1234567890";
    String email = "[email protected]";

    String expected = "Sent to [email protected]\nVerify Email\nHello!\n" +
            "Someone has created an account for this email address. If this was not you then just ignore " +
            "this message. If it was you then click the link bellow.\n\n" +
            "http://localhost/api/visitor/verify_email?id=" + id + "\n";

    sut.sendVerificationEmail(id, email);

    assertEquals(expected, outContent.toString());
}
 
開發者ID:2DV603NordVisaProject,項目名稱:nordvisa_calendar,代碼行數:17,代碼來源:EmailTest.java

示例6: testFlushAll

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testFlushAll() {
    InMemoryAttributeCache inMemoryAttributeCache = new InMemoryAttributeCache(5, TEST_ZONE,
            AbstractAttributeCache::subjectKey);
    Set<Attribute> attributes = Collections.singleton(new Attribute("https://test.com", "attribute1", "value1"));
    CachedAttributes cachedAttributes = new CachedAttributes(attributes);

    Map<String, CachedAttributes> cachedAttributesMap = new HashMap<>();
    String cacheKey = AbstractAttributeCache.subjectKey(TEST_ZONE, TEST_KEY);
    cachedAttributesMap.put(cacheKey, cachedAttributes);
    ReflectionTestUtils.setField(inMemoryAttributeCache, "attributeCache", cachedAttributesMap);
    Assert.assertEquals(inMemoryAttributeCache.get(TEST_KEY), cachedAttributes);
    inMemoryAttributeCache.flushAll();
    Assert.assertTrue(
            ((Map<String, CachedAttributes>) ReflectionTestUtils.getField(inMemoryAttributeCache, "attributeCache"))
                    .isEmpty());

}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:20,代碼來源:InMemoryAttributeCacheTest.java

示例7: setUp

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
  instanceConfigAuditUtil = new InstanceConfigAuditUtil();

  ReflectionTestUtils.setField(instanceConfigAuditUtil, "instanceService", instanceService);

  audits = (BlockingQueue<InstanceConfigAuditUtil.InstanceConfigAuditModel>)
      ReflectionTestUtils.getField(instanceConfigAuditUtil, "audits");

  someAppId = "someAppId";
  someClusterName = "someClusterName";
  someDataCenter = "someDataCenter";
  someIp = "someIp";
  someConfigAppId = "someConfigAppId";
  someConfigClusterName = "someConfigClusterName";
  someConfigNamespace = "someConfigNamespace";
  someReleaseKey = "someReleaseKey";

  someAuditModel = new InstanceConfigAuditUtil.InstanceConfigAuditModel(someAppId,
      someClusterName, someDataCenter, someIp, someConfigAppId, someConfigClusterName,
      someConfigNamespace, someReleaseKey);
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:23,代碼來源:InstanceConfigAuditUtilTest.java

示例8: 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("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:deepu105,項目名稱:spring-io,代碼行數:18,代碼來源:WebConfigurerTest.java

示例9: setUp

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
  controller = new NotificationController();
  ReflectionTestUtils.setField(controller, "releaseMessageService", releaseMessageService);
  ReflectionTestUtils.setField(controller, "entityManagerUtil", entityManagerUtil);
  ReflectionTestUtils.setField(controller, "namespaceUtil", namespaceUtil);
  ReflectionTestUtils.setField(controller, "watchKeysUtil", watchKeysUtil);

  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);

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

示例10: testHealth

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@Test(dataProvider = "statuses")
public void testHealth(final GraphResourceRepository graphResourceRepository, final Status status,
        final AcsMonitoringUtilities.HealthCode healthCode, final boolean cassandraEnabled) throws Exception {
    GraphDbHealthIndicator graphDbHealthIndicator = new GraphDbHealthIndicator(graphResourceRepository);
    ReflectionTestUtils.setField(graphDbHealthIndicator, "cassandraEnabled", cassandraEnabled);
    Assert.assertEquals(status, graphDbHealthIndicator.health().getStatus());
    Assert.assertEquals(GraphDbHealthIndicator.DESCRIPTION,
            graphDbHealthIndicator.health().getDetails().get(AcsMonitoringUtilities.DESCRIPTION_KEY));
    if (healthCode == AcsMonitoringUtilities.HealthCode.AVAILABLE) {
        Assert.assertFalse(
                graphDbHealthIndicator.health().getDetails().containsKey(AcsMonitoringUtilities.CODE_KEY));
    } else {
        Assert.assertEquals(healthCode,
                graphDbHealthIndicator.health().getDetails().get(AcsMonitoringUtilities.CODE_KEY));
    }
}
 
開發者ID:eclipse,項目名稱:keti,代碼行數:17,代碼來源:GraphDbHealthIndicatorTest.java

示例11: 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("build/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:michaelhoffmantech,項目名稱:patient-portal,代碼行數:18,代碼來源:WebConfigurerTest.java

示例12: 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:pascalgrimaud,項目名稱:qualitoast,代碼行數:18,代碼來源:WebConfigurerTest.java

示例13: shouldAddANewCustomer

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@Test
public void shouldAddANewCustomer() throws Exception {

	final Customer newCustomer = Customer.ofType(PERSON).build();

	final ObjectId id = ObjectId.get();
	ReflectionTestUtils.setField(newCustomer, "id", id);

	given(repo.existsById(any(ObjectId.class))).willReturn(Mono.just(false));
	given(repo.save(any(Customer.class))).willReturn(Mono.just(newCustomer));

	webClient.post().uri("/customers")
		.contentType(APPLICATION_JSON_UTF8)
		.body(fromObject("{\"customer_type\":\"PERSON\"}"))
		.exchange()
		.expectStatus().isCreated()	// HTTP 201
		.expectHeader().valueEquals("Location", String.format("/customers/%s", id));
}
 
開發者ID:dserradji,項目名稱:reactive-customer-service,代碼行數:19,代碼來源:CustomerControllerWebTest.java

示例14: setUp

import org.springframework.test.util.ReflectionTestUtils; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
  MockInjector.reset();

  MockInjector.setInstance(HttpUtil.class, httpUtil);

  someServerUrl = "http://someServer";
  ServiceDTO serviceDTO = mock(ServiceDTO.class);
  when(serviceDTO.getHomepageUrl()).thenReturn(someServerUrl);
  when(configServiceLocator.getConfigServices()).thenReturn(Lists.newArrayList(serviceDTO));
  MockInjector.setInstance(ConfigServiceLocator.class, configServiceLocator);

  MockInjector.setInstance(ConfigUtil.class, new MockConfigUtil());

  remoteConfigLongPollService = new RemoteConfigLongPollService();

  responseType =
      (Type) ReflectionTestUtils.getField(remoteConfigLongPollService, "m_responseType");

  someAppId = "someAppId";
  someCluster = "someCluster";
}
 
開發者ID:dewey-its,項目名稱:apollo-custom,代碼行數:23,代碼來源:RemoteConfigLongPollServiceTest.java

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


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