現在、XML ファイルを Jaxb オブジェクトにアンマーシャリングしてから文字列にマーシャリングし、元の xml 文字列と比較する単体テストがあります。
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/info/info-element-reader-test-context.xml"})
public class InfoElementReaderTest {
private static final Logger logger = LoggerFactory.getLogger(InfoElementReaderTest.class);
@Autowired
private InfoElementReader infoElementReader;
@Test
public void testMarshalling() throws Exception {
Marshaller marshaller = infoElementReader.getJaxbContext().createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
// Unmarshall into java bean
InfoElement infoElement = infoElementReader.unmarshallInfoElement();
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
marshaller.marshal(infoElement, outStream);
logger.info("marshalled XML: {}", outStream.toString());
String fromFile = IOUtils.toString(infoElementReader.getInfoResource().getInputStream(), "UTF-8").replaceAll("\\s","");
String marshalled = outStream.toString().replaceAll(""", "\"").replaceAll("\\s","");
assertEquals("file contents should equal marshalled output", fromFile, marshalled);
}
}
IDE (Intellij IDEA) でこのテストを実行すると、問題はないように見えますが、mvn clean パッケージでコンパイルすると、XML のすべてのアクセント付き文字、つまり. Reddetelefoníamóvil、Reddetelefon[?am?vil になり、文字列は明らかに等しくありません。
これがmavenの問題なのか、それとも何か他の問題なのかはわかりませんが、助けていただければ幸いです。前もって感謝します。