当前位置: 首页>>代码示例>>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;未经允许,请勿转载。