Fix tests

(cherry picked from commit f9b321c429)
This commit is contained in:
Marcus Hert Da Coregio
2023-11-27 10:42:39 -03:00
parent dcd5e231c2
commit 20fbf859e7
3 changed files with 6 additions and 3 deletions

View File

@@ -12,7 +12,6 @@ dependencies {
implementation "org.webjars:bootstrap"
implementation "org.webjars:html5shiv"
implementation "org.webjars:webjars-locator-core"
implementation "org.apache.httpcomponents:httpclient"
testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation "org.assertj:assertj-core"

View File

@@ -16,9 +16,12 @@
package sample.web;
import java.util.Collections;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@@ -31,10 +34,11 @@ public class HomeController {
@RequestMapping("/setValue")
public String setValue(@RequestParam(name = "key", required = false) String key,
@RequestParam(name = "value", required = false) String value, HttpServletRequest request) {
@RequestParam(name = "value", required = false) String value, HttpServletRequest request, Model model) {
if (!ObjectUtils.isEmpty(key) && !ObjectUtils.isEmpty(value)) {
request.getSession().setAttribute(key, value);
}
model.addAttribute("sessionAttributeNames", Collections.list(request.getSession().getAttributeNames()));
return "home";
}

View File

@@ -23,7 +23,7 @@
</tr>
</thead>
<tbody>
<tr th:each="name : ${T(org.springframework.util.CollectionUtils).toIterator(httpSession?.getAttributeNames())}">
<tr th:each="name : ${sessionAttributeNames}">
<td th:text="${name}"></td>
<td th:text="${httpSession.getAttribute(name)}"></td>
</tr>