@SankaSanka

Как подружить thymeleaf c интеграционным тестом?

<!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));
	}


все проходит хорошо, но не принимает мой html
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)

at org.springframework.test.util.XpathExpectationsHelper.assertNodeCount(XpathExpectationsHelper.java:154)
.......

Как это исправить подскажите пожалуйста.
Просто вставить как оно просит "=" туда не получается.
  • Вопрос задан
  • 65 просмотров
Пригласить эксперта
Ответы на вопрос 2
BorLaze
@BorLaze
Java developer
В документации по Thymeleaf код такой:
<!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">


Попробуй - вдруг поможет.
Ответ написан
Комментировать
@SankaSanka Автор вопроса
решение

@Autowired
	private WebApplicationContext wac;

	@Before
	public void setup() {
		MockitoAnnotations.initMocks(this);
		this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
	}
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
Bell Integrator Ульяновск
До 400 000 ₽
Bell Integrator Хабаровск
До 400 000 ₽
Bell Integrator Ижевск
До 400 000 ₽
25 апр. 2024, в 16:12
2000 руб./за проект
25 апр. 2024, в 16:08
100000 руб./за проект