use of cn.taketoday.web.view.View in project today-infrastructure by TAKETODAY.
the class FreeMarkerViewTests method freeMarkerViewResolver.
@Test
public void freeMarkerViewResolver() throws Exception {
MockServletContext sc = new MockServletContext();
FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
configurer.setConfiguration(new TestConfiguration());
StaticWebServletApplicationContext wac = new StaticWebServletApplicationContext();
wac.setServletContext(sc);
wac.getBeanFactory().registerSingleton("configurer", configurer);
wac.refresh();
FreeMarkerViewResolver vr = new FreeMarkerViewResolver("prefix_", "_suffix");
vr.setApplicationContext(wac);
View view = vr.resolveViewName("test", Locale.CANADA);
assertThat(view.getClass()).as("Correct view class").isEqualTo(FreeMarkerView.class);
assertThat(((FreeMarkerView) view).getUrl()).as("Correct URL").isEqualTo("prefix_test_suffix");
view = vr.resolveViewName("non-existing", Locale.CANADA);
assertThat(view).isNull();
view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
assertThat(view.getClass()).as("Correct view class").isEqualTo(RedirectView.class);
assertThat(((RedirectView) view).getUrl()).as("Correct URL").isEqualTo("myUrl");
view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
assertThat(view.getClass()).as("Correct view class").isEqualTo(InternalResourceView.class);
assertThat(((InternalResourceView) view).getUrl()).as("Correct URL").isEqualTo("myUrl");
}
use of cn.taketoday.web.view.View in project today-infrastructure by TAKETODAY.
the class XlsViewTests method testXlsxView.
@Test
@SuppressWarnings("resource")
public void testXlsxView() throws Exception {
View excelView = new AbstractXlsxView() {
@Override
protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, RequestContext request) throws Exception {
Sheet sheet = workbook.createSheet("Test Sheet");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("Test Value");
}
};
excelView.render(new HashMap<>(), requestContext);
Workbook wb = new XSSFWorkbook(new ByteArrayInputStream(response.getContentAsByteArray()));
assertThat(wb.getSheetName(0)).isEqualTo("Test Sheet");
Sheet sheet = wb.getSheet("Test Sheet");
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
assertThat(cell.getStringCellValue()).isEqualTo("Test Value");
}
Aggregations