Answer the question
In order to leave comments, you need to log in
How to make thymeleaf friends with an integration test?
<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"/>
<title th:text="${title}"> </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<header th:insert="blocks/header :: header"></header>
<div th:each="el : ${product}" class="allert allert-info mt-2">
<div class="card" style="width: 18rem;" id="showCase-list">
<div class="card-body">
<h2 class="card-title"><p th:text="${el.name}" ></h2>
<p class="card-text"><p th:text="${el.description}" ></p>
<p class="card-text"><p th:text="${el.price}" ></p>
<p><a th:href="'/product/'+${el.id}" class="btn btn-primary btn-sm">View Details </a></p><br>
</div>
</div>
</div>
<div th:insert="blocks/footer :: footer"></div>
</body>
</html>
@Test
public void createShowcaseTest() throws Exception {
this.mockMvc.perform(get("/showcase"))
.andDo(print())
.andExpect(xpath("//div[@id='showCase-list']").nodeCount(4));
}
org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 14; Attribute name "xmlns:" associated with an element type "html" must be followed by the ' = ' character.
at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:262)
at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:339)
at org.springframework.test.util.XpathExpectationsHelper.parseXmlByteArray(XpathExpectationsHelper.java:237)
at org.springframework.test.util.XpathExpectationsHelper.evaluateXpath(XpathExpectationsHelper.java:219)
Answer the question
In order to leave comments, you need to log in
In the Thymeleaf documentation, the code is:
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
decision
@Autowired
private WebApplicationContext wac;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question