@Test
@org.junit.Test
public void parseTMXWithMetadata() throws Exception {
// Create a TM
TransMemory tm = createTMFromFile("/tmx/valid-tmx-with-metadata.tmx");
// Make sure everything is stored properly
tm = getEm().find(TransMemory.class, tm.getId());
// Metadata at the header level
Map<String, String> tmAtts = TMXMetadataHelper.getAttributes(tm);
assertThat(tmAtts.size(), is(9));
assertThat(tmAtts, hasEntry("segtype", "paragraph"));
assertThat(tmAtts, hasEntry("creationtoolversion", "unknown"));
assertThat(tmAtts,
hasEntry("creationtool", "Zanata TransMemoryExportTMXStrategy"));
assertThat(tmAtts, hasEntry("datatype", "unknown"));
assertThat(tmAtts, hasEntry("adminlang", "en"));
assertThat(tmAtts, hasEntry("o-tmf", "unknown"));
assertThat(tmAtts, hasEntry("srclang", "*all*"));
assertThat(tmAtts, hasKey("creationdate"));
assertThat(tmAtts, hasKey("changedate"));
List<Element> tmChildren = TMXMetadataHelper.getChildren(tm);
assertThat(tmChildren.size(), is(2));
assertThat(tmChildren.get(0).getLocalName(), is("prop"));
assertThat(tmChildren.get(0).getValue(), is("Header Prop value"));
assertThat(tmChildren.get(1).getLocalName(), is("note"));
assertThat(tmChildren.get(1).getValue(), is("Header Note value"));
// Metadata at the TU level
TransMemoryUnit tu0 =
findInCollection(tm.getTranslationUnits(), "doc0:resId0");
Map<String, String> tu0Atts = TMXMetadataHelper.getAttributes(tu0);
assertThat(tu0Atts.size(), is(4));
assertThat(tu0Atts, hasEntry("tuid", "doc0:resId0"));
assertThat(tu0Atts, hasEntry("srclang", "en"));
assertThat(tu0Atts, hasKey("creationdate"));
assertThat(tu0Atts, hasKey("changedate"));
List<Element> tu0Children = TMXMetadataHelper.getChildren(tu0);
assertThat(tu0Children.size(), is(2));
assertThat(tu0Children.get(0).getLocalName(), is("prop"));
assertThat(tu0Children.get(0).getValue(), is("Custom prop0 value"));
assertThat(tu0Children.get(1).getLocalName(), is("note"));
assertThat(tu0Children.get(1).getValue(), is("Custom note"));
TransMemoryUnit tu1 =
findInCollection(tm.getTranslationUnits(), "doc0:resId1");
Map<String, String> tu1Atts = TMXMetadataHelper.getAttributes(tu1);
assertThat(tu1Atts.size(), is(4));
assertThat(tu1Atts, hasEntry("tuid", "doc0:resId1"));
assertThat(tu1Atts, hasEntry("srclang", "en"));
assertThat(tu1Atts, hasKey("creationdate"));