com.alibaba.spring.util.FieldUtils Java Examples

The following examples show how to use com.alibaba.spring.util.FieldUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConfigurableContentNegotiationManagerWebMvcConfigurerTest.java    From spring-webmvc-support with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testConfigureContentNegotiationOnDefaultValues() {

    WebMvcConfigurer webMvcConfigurer =
            new ConfigurableContentNegotiationManagerWebMvcConfigurer(new HashMap<String, String>());

    ContentNegotiationConfigurer configurer = new ContentNegotiationConfigurer(new MockServletContext());

    webMvcConfigurer.configureContentNegotiation(configurer);

    ContentNegotiationManagerFactoryBean factoryBean =
            FieldUtils.getFieldValue(configurer, "factory", ContentNegotiationManagerFactoryBean.class);

    Assert.assertTrue(FieldUtils.getFieldValue(factoryBean, "favorPathExtension", boolean.class));
    Assert.assertFalse(FieldUtils.getFieldValue(factoryBean, "favorParameter", boolean.class));
    Assert.assertFalse(FieldUtils.getFieldValue(factoryBean, "ignoreAcceptHeader", boolean.class));
    Assert.assertNull(FieldUtils.getFieldValue(factoryBean, "useJaf", Boolean.class));
    Assert.assertEquals("format", FieldUtils.getFieldValue(factoryBean, "parameterName", String.class));
    Assert.assertTrue(FieldUtils.getFieldValue(factoryBean, "mediaTypes", Map.class).isEmpty());
    Assert.assertNull(FieldUtils.getFieldValue(factoryBean, "defaultContentType", MediaType.class));

}
 
Example #2
Source File: VelocityLayoutAutoConfigurationTest.java    From velocity-spring-boot-project with Apache License 2.0 5 votes vote down vote up
@Test
public void testVelocityLayoutViewResolver() {

    String layoutUrl = FieldUtils.getFieldValue(embeddedVelocityLayoutViewResolver, "layoutUrl");
    Assert.assertEquals("/layout/default.vm", layoutUrl);

    String layoutKey = FieldUtils.getFieldValue(embeddedVelocityLayoutViewResolver, "layoutKey");
    Assert.assertEquals("layout_key", layoutKey);

    String screenContentKey = FieldUtils.getFieldValue(embeddedVelocityLayoutViewResolver, "screenContentKey");
    Assert.assertEquals("body_content", screenContentKey);
}
 
Example #3
Source File: ContentNegotiationManagerConfigurationTest.java    From spring-boot-web-support with GNU General Public License v3.0 5 votes vote down vote up
/**
 * spring.web-support.content-negotiation-manager.favorPathExtension = true
 * spring.web-support.content-negotiation-manager.favorParameter = true
 * spring.web-support.content-negotiation-manager.ignoreAcceptHeader = false
 * spring.web-support.content-negotiation-manager.useJaf = false
 * spring.web-support.content-negotiation-manager.parameterName = test-format
 * spring.web-support.content-negotiation-manager.mediaTypes.html = text/html
 * spring.web-support.content-negotiation-manager.mediaTypes.xml = text/xml
 * spring.web-support.content-negotiation-manager.mediaTypes.json = application/json
 * spring.web-support.content-negotiation-manager.mediaTypes.gif = image/gif
 * spring.web-support.content-negotiation-manager.mediaTypes.jpeg = image/jpeg
 * spring.web-support.content-negotiation-manager.defaultContentType = text/html
 */
@Test
public void testContentNegotiationManagerConfiguration() {

    ContentNegotiationManager contentNegotiationManager =
            contentNegotiatingViewResolver.getContentNegotiationManager();

    List<ContentNegotiationStrategy> strategies = contentNegotiationManager.getStrategies();

    Assert.assertEquals(4, strategies.size());
    Assert.assertTrue(contains(ParameterContentNegotiationStrategy.class, strategies));
    Assert.assertTrue(contains(HeaderContentNegotiationStrategy.class, strategies));
    Assert.assertTrue(contains(FixedContentNegotiationStrategy.class, strategies));

    ContentNegotiationStrategy strategy = strategies.get(0);

    strategy = FieldUtils.getFieldValue(strategy, "delegate");

    Map<String, MediaType> mediaTypesMap = FieldUtils.getFieldValue(strategy, "mediaTypes");

    Assert.assertEquals("html", mediaTypesMap.get("html").getSubtype());
    Assert.assertEquals("xml", mediaTypesMap.get("xml").getSubtype());
    Assert.assertEquals("json", mediaTypesMap.get("json").getSubtype());
    Assert.assertEquals("gif", mediaTypesMap.get("gif").getSubtype());
    Assert.assertEquals("jpeg", mediaTypesMap.get("jpeg").getSubtype());

}
 
Example #4
Source File: ConfigurableContentNegotiationManagerWebMvcConfigurerTest.java    From spring-webmvc-support with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testConfigureContentNegotiation() {

    Map<String, String> properties = new HashMap<String, String>();

    properties.put("favorPathExtension", "false");
    properties.put("favorParameter", "true");
    properties.put("ignoreAcceptHeader", "true");
    properties.put("useJaf", "true");
    properties.put("parameterName", "test-format");
    properties.put("mediaTypes.html", TEXT_HTML_VALUE);
    properties.put("mediaTypes.xml", APPLICATION_XML_VALUE);
    properties.put("mediaTypes.json", APPLICATION_JSON_VALUE);
    properties.put("mediaTypes.gif", IMAGE_GIF_VALUE);
    properties.put("mediaTypes.jpeg", IMAGE_JPEG_VALUE);
    properties.put("defaultContentType", TEXT_HTML_VALUE);


    WebMvcConfigurer webMvcConfigurer = new ConfigurableContentNegotiationManagerWebMvcConfigurer(properties);

    ContentNegotiationConfigurer configurer = new ContentNegotiationConfigurer(new MockServletContext());

    ContentNegotiationManagerFactoryBean factoryBean =
            FieldUtils.getFieldValue(configurer, "factory", ContentNegotiationManagerFactoryBean.class);

    webMvcConfigurer.configureContentNegotiation(configurer);


    Assert.assertFalse(FieldUtils.getFieldValue(factoryBean, "favorPathExtension", boolean.class));
    Assert.assertTrue(FieldUtils.getFieldValue(factoryBean, "favorParameter", boolean.class));
    Assert.assertTrue(FieldUtils.getFieldValue(factoryBean, "ignoreAcceptHeader", boolean.class));
    Assert.assertTrue(FieldUtils.getFieldValue(factoryBean, "useJaf", Boolean.class));
    Assert.assertEquals("test-format", FieldUtils.getFieldValue(factoryBean, "parameterName", String.class));

    Map<String, MediaType> mediaTypesMap = FieldUtils.getFieldValue(factoryBean, "mediaTypes", Map.class);

    Assert.assertEquals("html", mediaTypesMap.get("html").getSubtype());
    Assert.assertEquals("xml", mediaTypesMap.get("xml").getSubtype());
    Assert.assertEquals("json", mediaTypesMap.get("json").getSubtype());
    Assert.assertEquals("gif", mediaTypesMap.get("gif").getSubtype());
    Assert.assertEquals("jpeg", mediaTypesMap.get("jpeg").getSubtype());

}
 
Example #5
Source File: ExclusiveViewResolverApplicationListenerTest.java    From spring-webmvc-support with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void testOnApplicationContext() {

    // Register ViewResolver Beans
    applicationContext.register(TestViewResolver.class);

    ApplicationListener<ContextRefreshedEvent> applicationListener =
            new ExclusiveViewResolverApplicationListener("test-view-resolver");

    applicationContext.addApplicationListener(applicationListener);

    applicationContext.refresh();

    List<ViewResolver> viewResolvers = FieldUtils.getFieldValue(resolver, "viewResolvers");

    Assert.assertEquals(1, viewResolvers.size());

    Assert.assertEquals(TestViewResolver.class, viewResolvers.get(0).getClass());

}