use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class ThymeleafViewContext method render.
@Override
public void render(ServletContext servletContext, HttpServletRequest request, HttpServletResponse response, View view) throws IOException {
for (ViewDecorator viewDecorator : viewDecorators) {
viewDecorator.decorate(request, view);
}
WebContext ctx = new WebContext(request, response, servletContext, view.getLocale());
ctx.setVariables(view.getVariables());
templateEngine.process(view.getTemplate(), ctx, response.getWriter());
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class ThymeleafViewContextTest method test.
@Test
public void test() throws Exception {
// given
TemplateResolver resolver = TemplateResolver.builder().build();
ViewContext viewContext = new ThymeleafViewContextBuilder().templateResolver(resolver).build();
ServletContext servletContext = mock(ServletContext.class);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
PrintWriter writer = mock(PrintWriter.class);
when(response.getWriter()).thenReturn(writer);
View view = View.builder().template("index.html").build();
// when
viewContext.render(servletContext, request, response, view);
// then
Asserts.assertNotNull(viewContext);
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyhttp by youngmonkeys.
the class ThymeleafViewContextTest method renderWithViewDecorator.
@Test
public void renderWithViewDecorator() throws Exception {
// given
TemplateResolver resolver = TemplateResolver.builder().build();
ViewDecorator viewDecorator = mock(ViewDecorator.class);
ViewContext viewContext = new ThymeleafViewContextBuilder().templateResolver(resolver).viewDecorators(Collections.singletonList(viewDecorator)).build();
ServletContext servletContext = mock(ServletContext.class);
HttpServletRequest request = mock(HttpServletRequest.class);
HttpServletResponse response = mock(HttpServletResponse.class);
PrintWriter writer = mock(PrintWriter.class);
when(response.getWriter()).thenReturn(writer);
View view = View.builder().template("index.html").build();
// when
viewContext.render(servletContext, request, response, view);
// then
Asserts.assertNotNull(viewContext);
verify(viewDecorator, times(1)).decorate(request, view);
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-examples by tvd12.
the class BookController method addBook.
@DoPost("/book/add")
public BookResponse addBook(@RequestBody AddBookRequest request) {
Book existedBook = bookRepository.findByNameAndAuthorId(request.getBookName(), request.getAuthorId());
if (existedBook != null) {
throw new HttpBadRequestException("author: " + request.getAuthorId() + " has already registered book: " + request.getBookName());
}
Author author = authorRepository.findById(request.getAuthorId());
if (author == null) {
throw new HttpBadRequestException("author: " + request.getAuthorId() + " not found");
}
Category category = categoryRepository.findById(request.getCategoryId());
if (category == null) {
throw new HttpBadRequestException("category: " + request.getCategoryId() + " not found");
}
val bookId = maxIdRepository.incrementAndGet("book");
val book = requestToEntityConverter.toBookEntity(request, bookId);
bookRepository.save(book);
return entityToResponseConverter.toBookResponse(book, author, category);
}
use of com.tvd12.ezyhttp.client.request.Request in project ezyfox-examples by tvd12.
the class CategoryController method addCategory.
@DoPost("/add")
public Category addCategory(@RequestBody AddCategoryRequest request) {
Category existedCategory = categoryRepository.findByName(request.getCategoryName());
if (existedCategory != null) {
throw new HttpBadRequestException("category named: " + request.getCategoryName() + " existed");
}
Category category = new Category(maxIdRepository.incrementAndGet("category"), request.getCategoryName());
categoryRepository.save(category);
return category;
}
Aggregations