저는 REST 인터페이스를 사용하는 오픈 소스 프로젝트에서 작업하고 있습니다. JSONAssert를 사용하려면 JUnit에서 나머지 인터페이스를 검증 (실제 응답과 예상과 일치)시키기 위해 (https://github.com/skyscreamer/JSONassert). 하지만 사용법에 문제가 있습니다. 친절하게 해결하는 데 도움이됩니다.정규식으로 JSONAssert를 사용하는 JSON 유효성 확인
Expected JSON:
{
"objectId": "[^\\s]",
"protocol": "[^\\s]",
"hostName": "[^\\s]",
"port": "[^\\s]",
"commParams": "[^\\s]"
}
비고 : OBJECTID/프로토콜/호스트 이름/포트/commParams 아무것도 할 수 있지만 빈 안
Actual JSON:
{
"objectId": "controller2",
"protocol": "ftp",
"hostName": "sdnorchestrator",
"port": "21",
"commParams": "username:tomcat, password:tomdog"
}
Problem1 : 나는 위의 문제를 해결하기 위해 사용해야하는 어떤 JSON 어설의 인터페이스 : 아래 하나?
JSONAssert.assertEquals("Expected JSON", "Actual JSON" new CustomComparator(
JSONCompareMode.LENIENT_ORDER, new Customization(PREFIX, new RegularExpressionValueMatcher<Object>())));
문제 2 : 여기 PREFIX해야 무슨 일이 (. 나는 . ",을", ""로 시도 "하지만 성공도 없었다) JSONAssert 이외의
다른 추천 () 위의 문제도 환영합니다.