View Javadoc
1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package org.itracker.web.util;
6   
7   import org.dom4j.*;
8   import org.itracker.AbstractDependencyInjectionTest;
9   import org.itracker.ImportExportException;
10  import org.itracker.model.*;
11  import org.itracker.model.CustomField.Type;
12  import org.itracker.model.util.IssueUtilities;
13  import org.itracker.model.util.ProjectUtilities;
14  import org.junit.Ignore;
15  import org.junit.Test;
16  
17  import java.io.IOException;
18  import java.io.InputStreamReader;
19  import java.io.Reader;
20  import java.io.StringReader;
21  import java.text.SimpleDateFormat;
22  import java.util.*;
23  
24  import static org.itracker.Assert.*;
25  
26  
27  /**
28   * FIXME: reimplement this test as soon we got an XML Import/Export
29   *
30   * @author seas
31   */
32  public class ImportExportUtilitiesIT extends AbstractDependencyInjectionTest {
33  
34      public static final long TEST_TIMESTAMP_EXPORT1 = 50000l;
35      public static final long TEST_TIMESTAMP_EXPORT2 = 8000000l;
36  
37      private String flatXml(final String xml) {
38          return xml.replace("\n", "").replace("\r", "").replaceAll("> +<", "><").trim();
39      }
40  
41      public void doTestImportIssues(final Reader xml,
42                                     final AbstractEntity[] expected) {
43          try {
44              final AbstractEntity[] actual = ImportExportUtilities.importIssues(xml);
45              final List<AbstractEntity> actualList = new Vector<AbstractEntity>(Arrays.asList(actual));
46              final List<AbstractEntity> expectedList = new Vector<AbstractEntity>(Arrays.asList(expected));
47              assertEquals(expected.length, actual.length);
48              for (final AbstractEntity aeExpected : expectedList) {
49                  boolean found = false;
50                  for (final AbstractEntity aeActual : actualList) {
51                      if (aeExpected instanceof Issue && aeActual instanceof Issue) {
52                          final Issue issueExpected = (Issue) aeExpected;
53                          final Issue issueActual = (Issue) aeActual;
54                          if (issueExpected.getId().equals(issueActual.getId())) {
55                              found = true;
56                          }
57                      } else if (aeExpected instanceof Project && aeActual instanceof Project) {
58                          final Project projectExpected = (Project) aeExpected;
59                          final Project projectActual = (Project) aeActual;
60                          if (projectExpected.getId().equals(projectActual.getId())) {
61                              found = true;
62                          }
63                      } else if (aeExpected instanceof User && aeActual instanceof User) {
64                          final User userExpected = (User) aeExpected;
65                          final User userActual = (User) aeActual;
66                          if (userExpected.getId().equals(userActual.getId())) {
67                              found = true;
68                          }
69                      } else if (aeExpected instanceof SystemConfiguration && aeActual instanceof SystemConfiguration) {
70                          @SuppressWarnings("unused")
71                          final SystemConfiguration configExpected =
72                                  (SystemConfiguration) aeExpected;
73                          @SuppressWarnings("unused")
74                          final SystemConfiguration configActual =
75                                  (SystemConfiguration) aeActual;
76                          found = true;
77                      }
78                      if (found) {
79                          actualList.remove(aeActual);
80                          break;
81                      }
82                  }
83                  assertTrue(found);
84              }
85          } catch (final ImportExportException e) {
86              assertTrue(e.getMessage(), false);
87          }
88      }
89  
90      @Test
91      public void testImportIssue() {
92          final List<Issue> issues = new Vector<Issue>();
93          final Project project = new Project("project");
94          project.setId(1);
95          final User creator = new User();
96          creator.setId(1);
97          final User owner = new User();
98          owner.setId(2);
99          final Date dateCreate = new Date();
100         final Date dateModify = new Date();
101         final Issue issue1 = new Issue();
102         issue1.setId(1);
103         issue1.setProject(project);
104         issue1.setDescription("issue description");
105         issue1.setCreator(creator);
106         issue1.setOwner(owner);
107         issue1.setCreateDate(dateCreate);
108         issue1.setLastModifiedDate(dateModify);
109         issues.add(issue1);
110 
111         final Issue issue2 = new Issue();
112         issue2.setId(2);
113         issue2.setProject(project);
114         issue2.setDescription("issue description");
115         issue2.setCreator(creator);
116         issue2.setOwner(owner);
117         issue2.setCreateDate(dateCreate);
118         issue2.setLastModifiedDate(dateModify);
119         issues.add(issue2);
120 
121         final SystemConfiguration systemConfiguration =
122                 new SystemConfiguration();
123         final String xml = "<itracker>" +
124                 "<configuration>" +
125                 "<configuration-version><![CDATA[]]></configuration-version>" +
126                 "<custom-fields>" +
127                 "</custom-fields>" +
128                 "<resolutions>" +
129                 "</resolutions>" +
130                 "<severities>" +
131                 "</severities>" +
132                 "<statuses>" +
133                 "</statuses>" +
134                 "</configuration>" +
135                 "<users>" +
136                 "<user id=\"user1\" systemid=\"1\">" +
137                 "<login><![CDATA[]]></login>" +
138                 "<first-name><![CDATA[]]></first-name>" +
139                 "<last-name><![CDATA[]]></last-name>" +
140                 "<email><![CDATA[]]></email>" +
141                 "<user-status>0</user-status>" +
142                 "<super-user>false</super-user>" +
143                 "</user>" +
144                 "<user id=\"user2\" systemid=\"2\">" +
145                 "<login><![CDATA[]]></login>" +
146                 "<first-name><![CDATA[]]></first-name>" +
147                 "<last-name><![CDATA[]]></last-name>" +
148                 "<email><![CDATA[]]></email>" +
149                 "<user-status>0</user-status>" +
150                 "<super-user>false</super-user>" +
151                 "</user>" +
152                 "</users>" +
153                 "<projects>" +
154                 "<project id=\"project1\" systemid=\"1\">" +
155                 "<project-name><![CDATA[project]]></project-name>" +
156                 "<project-description><![CDATA[]]></project-description>" +
157                 "<project-status>" + ProjectUtilities.getStatusName(project.getStatus(), ImportExportUtilities.EXPORT_LOCALE) + "</project-status>" +
158                 "<project-options>0</project-options>" +
159                 "</project>" +
160                 "</projects>" +
161                 "<issues>" +
162                 "<issue id=\"issue1\" systemid=\"1\">" +
163                 "<issue-project><![CDATA[project1]]></issue-project>" +
164                 "<issue-description><![CDATA[issue description]]></issue-description>" +
165                 "<issue-severity>3</issue-severity>" +
166                 "<issue-status>100</issue-status>" +
167                 "<issue-resolution><![CDATA[]]></issue-resolution>" +
168                 "<create-date>" + ImportExportTags.DATE_FORMATTER.format(dateCreate) + "</create-date>" +
169                 "<last-modified>" + ImportExportTags.DATE_FORMATTER.format(dateModify) + "</last-modified>" +
170                 "<creator>user1</creator>" +
171                 "<owner>user2</owner>" +
172                 "</issue>" +
173                 "<issue id=\"issue2\" systemid=\"2\">" +
174                 " <issue-project><![CDATA[project1]]></issue-project>" +
175                 "<issue-description><![CDATA[issue description]]></issue-description>" +
176                 "<issue-severity>3</issue-severity>" +
177                 "<issue-status>100</issue-status>" +
178                 "<issue-resolution><![CDATA[]]></issue-resolution>" +
179                 "<create-date>" + ImportExportTags.DATE_FORMATTER.format(dateCreate) + "</create-date>" +
180                 "<last-modified>" + ImportExportTags.DATE_FORMATTER.format(dateModify) + "</last-modified>" +
181                 "<creator>user1</creator>" +
182                 "<owner>user2</owner>" +
183                 "</issue>" +
184                 "</issues>" +
185                 "</itracker>";
186         doTestImportIssues(new StringReader(xml),
187                 new AbstractEntity[]{
188                         systemConfiguration,
189                         creator,
190                         owner,
191                         project,
192                         issue1,
193                         issue2
194                 });
195 
196         //test throwing exception
197         try {
198             ImportExportUtilities.importIssues(null);
199             fail("should throw ImportExportException");
200         } catch (final ImportExportException e) {
201 
202         }
203 
204         try {
205             ImportExportUtilities.importIssues(new StringReader(""));
206             fail("should throw ImportExportException");
207         } catch (final ImportExportException e) {
208 
209         }
210 
211         try {
212             ImportExportUtilities.importIssues(new StringReader("Test"));
213             fail("should throw ImportExportException");
214         } catch (final ImportExportException e) {
215 
216         }
217     }
218 
219 
220     // TODO not stable
221     @Ignore
222     @Test
223     public void testExportIssues() {
224         final List<Issue> issues = new Vector<Issue>();
225         final Project project = new Project("project");
226         project.setId(1);
227         final User creator = new User();
228         creator.setId(1);
229         final User owner = new User();
230         owner.setId(2);
231         final User user = new User();
232         user.setId(3);
233         final User attachmentCreator = new User();
234         attachmentCreator.setId(4);
235         final Date dateCreate = new Date(TEST_TIMESTAMP_EXPORT1);
236         final Date dateModify = new Date(TEST_TIMESTAMP_EXPORT2);
237         Date created = null;
238         List<User> users = new ArrayList<User>();
239         users.add(creator);
240         project.setOwners(users);
241         try {
242             created = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2008-11-11 12:11:10");
243         } catch (Exception e) {
244 
245         }
246         {
247             final Issue issue = new Issue();
248             issue.setId(1);
249             issue.setProject(project);
250             issue.setDescription("issue description");
251             issue.setCreator(creator);
252             issue.setOwner(owner);
253             issue.setCreateDate(dateCreate);
254             issue.setLastModifiedDate(dateModify);
255 
256             IssueHistory issueHistory = new IssueHistory();
257             issueHistory.setUser(user);
258             issueHistory.setStatus(1);
259             issueHistory.setCreateDate(created);
260             issueHistory.setDescription("Test issue history entry.");
261             List<IssueHistory> histories = new ArrayList<IssueHistory>();
262             histories.add(issueHistory);
263             issue.setHistory(histories);
264 
265             IssueAttachment attachment = new IssueAttachment();
266             attachment.setUser(attachmentCreator);
267             attachment.setFileName("proj1_issue801_attachment1");
268             attachment.setOriginalFileName("ITracker.jmx");
269             attachment.setSize(192521);
270             attachment.setType("text/plain");
271 
272             List<IssueAttachment> attachments = new ArrayList<IssueAttachment>();
273             attachments.add(attachment);
274             issue.setAttachments(attachments);
275 
276             issues.add(issue);
277         }
278         {
279             final Issue issue = new Issue();
280             issue.setId(2);
281             issue.setProject(project);
282             issue.setDescription("issue description");
283             issue.setCreator(creator);
284             issue.setOwner(owner);
285             issue.setCreateDate(dateCreate);
286             issue.setLastModifiedDate(dateModify);
287             issues.add(issue);
288 
289         }
290         final SystemConfiguration systemConfiguration =
291                 new SystemConfiguration();
292         try {
293             final String expected = readXmlString("org/itracker/services/util/testExportIssuesExpected.xml");
294             String xml = ImportExportUtilities.exportIssues(issues,
295                     systemConfiguration);
296 
297             assertEquals("xml", flatXml(expected),
298                     flatXml(xml));
299         } catch (final ImportExportException ex) {
300             assertTrue(ex.getMessage(), false);
301         }
302 
303         try {
304             ImportExportUtilities.exportIssues(null, systemConfiguration);
305             fail("should throw ImportExportException");
306         } catch (ImportExportException e) {
307 
308         }
309 
310         try {
311             ImportExportUtilities.exportIssues(new ArrayList<Issue>(), systemConfiguration);
312             fail("should throw ImportExportException");
313         } catch (ImportExportException e) {
314 
315         }
316     }
317 
318     @Test
319     public void testExportModel() throws DocumentException {
320         try {
321             final User creator = new User();
322             creator.setId(1);
323             final User owner = new User();
324             owner.setId(2);
325             final Project project = new Project("project");
326             project.setId(1);
327             project.getOwners().add(creator);
328             project.getOwners().add(owner);
329             final Component component = new Component(project, "component");
330             project.getComponents().add(component);
331             final Issue issue = new Issue();
332             issue.setProject(project);
333             issue.setId(1);
334             issue.setDescription("issue description");
335             issue.setSeverity(1);
336             issue.setResolution("fixed");
337             issue.setTargetVersion(new Version(project, "1.1.1"));
338             final Date dateCreate = new Date();
339             issue.setCreateDate(dateCreate);
340             final Date dateModify = new Date();
341             issue.setLastModifiedDate(dateModify);
342             issue.setCreator(creator);
343             issue.setOwner(owner);
344             final IssueHistory issueHistory = new IssueHistory(issue, creator, "some description", IssueUtilities.STATUS_NEW);
345             issueHistory.setCreateDate(dateCreate);
346             issueHistory.setLastModifiedDate(dateModify);
347             issue.getHistory().add(issueHistory);
348             issue.getComponents().add(component);
349             final IssueAttachment attachment = new IssueAttachment(issue, "file.txt");
350             attachment.setUser(creator);
351             issue.getAttachments().add(attachment);
352             issue.getVersions().add(new Version(project, "1.1.1"));
353             issue.getVersions().add(new Version(project, "1.1.2"));
354             final String expected = "<issue id=\"issue1\" systemid=\"1\">" +
355                     "<issue-project><![CDATA[project1]]></issue-project>" +
356                     "<issue-description><![CDATA[issue description]]></issue-description>" +
357                     "<issue-severity>1</issue-severity>" +
358                     "<issue-status>null</issue-status>" +
359                     "<issue-resolution><![CDATA[fixed]]></issue-resolution>" +
360                     "<target-version-id>versionnull</target-version-id>" +
361                     "<create-date>" + ImportExportTags.DATE_FORMATTER.format(dateCreate) + "</create-date>" +
362                     "<last-modified>" + ImportExportTags.DATE_FORMATTER.format(dateModify) + "</last-modified>" +
363                     "<creator>user1</creator>" +
364                     "<owner>user2</owner>" +
365                     "<issue-components>" +
366                     "<component-id>componentnull</component-id>" +
367                     "</issue-components>" +
368                     "<issue-versions>" +
369                     "<version-id>versionnull</version-id>" +
370                     "<version-id>versionnull</version-id>" +
371                     "</issue-versions>" +
372                     "<issue-attachments>" +
373                     "<issue-attachment>      <issue-attachment-description><![CDATA[]]></issue-attachment-description>" +
374                     "<issue-attachment-filename><![CDATA[]]></issue-attachment-filename>" +
375                     "<issue-attachment-origfile><![CDATA[file.txt]]></issue-attachment-origfile>" +
376                     "<issue-attachment-size><![CDATA[0]]></issue-attachment-size>" +
377                     "<issue-attachment-type><![CDATA[application/octet-stream]]></issue-attachment-type>" +
378                     "<issue-attachment-creator><![CDATA[user1]]></issue-attachment-creator>" +
379                     "</issue-attachment>" +
380                     "</issue-attachments>" +
381                     "<issue-history>" +
382                     "<history-entry creator-id=\"user1\" date=\"" + ImportExportTags.DATE_FORMATTER.format(dateCreate) + "\" status=\"100\"><![CDATA[some description]]></history-entry>" +
383                     "</issue-history>" +
384                     "</issue>";
385 
386             final String xml = ImportExportUtilities.exportModel(issue);
387             assertNotNull("xml", xml);
388             assertContainsAll("xml", DocumentHelper.parseText(flatXml(expected)),
389                     DocumentHelper.parseText(flatXml(xml)));
390 
391         } catch (final ImportExportException ex) {
392             assertTrue(ex.getMessage(), false);
393         }
394 
395         try {
396             final Project project = new Project("project");
397             project.setId(1);
398             final Component component = new Component(project, "component");
399             component.setId(1);
400             project.getComponents().add(component);
401             final String expected = "<project id=\"project1\" systemid=\"1\">" +
402                     "<project-name><![CDATA[project]]></project-name>" +
403                     "<project-description><![CDATA[]]></project-description>" +
404                     "<project-status>" + ProjectUtilities.getStatusName(project.getStatus(), ImportExportUtilities.EXPORT_LOCALE) + "</project-status>" +
405                     "<project-options>0</project-options>" +
406                     "<components>" +
407                     "<component id=\"component1\" systemid=\"1\">" +
408                     "<component-name><![CDATA[component]]></component-name>" +
409                     "<component-description><![CDATA[]]></component-description>" +
410                     "</component>" +
411                     "</components>" +
412                     "</project>";
413 
414             final String xml = ImportExportUtilities.exportModel(project);
415             assertNotNull("xml", xml);
416             assertContainsAll("xml", DocumentHelper.parseText(expected),
417                     DocumentHelper.parseText(xml));
418 
419         } catch (final ImportExportException ex) {
420             assertTrue(ex.getMessage(), false);
421         }
422 
423         try {
424             final User user = new User();
425             user.setId(1);
426             user.setFirstName("firstName");
427             user.setLastName("lastName");
428             final String expected = "<user id=\"user1\" systemid=\"1\">" +
429                     "<login><![CDATA[]]></login>" +
430                     "<first-name><![CDATA[firstName]]></first-name>" +
431                     "<last-name><![CDATA[lastName]]></last-name>" +
432                     "<email><![CDATA[]]></email>" +
433                     "<user-status>0</user-status>" +
434                     "<super-user>false</super-user>" +
435                     "</user>";
436             final String xml = ImportExportUtilities.exportModel(user);
437             assertNotNull("xml", xml);
438             assertContainsAll("xml", DocumentHelper.parseText(expected),
439                     DocumentHelper.parseText(xml));
440 
441         } catch (final ImportExportException ex) {
442             assertTrue(ex.getMessage(), false);
443         }
444 
445         try {
446             ImportExportUtilities.exportModel(null);
447             fail("should throw ImportExportException");
448         } catch (ImportExportException e) {
449         }
450 
451         try {
452             ImportExportUtilities.exportModel(null);
453             fail("should throw ImportExportException");
454         } catch (ImportExportException e) {
455             assertEquals("The bean to export was null.", e.getMessage());
456         }
457 
458         try {
459             ImportExportUtilities.exportModel(new Component());
460             fail("should throw ImportExportException");
461         } catch (ImportExportException e) {
462             assertEquals("This bean type can not be exported.", e.getMessage());
463         }
464     }
465 
466     /**
467      * TODO: Not a valid XML..
468      */
469     @Test
470     public void testGetConfigurationXML() throws DocumentException {
471 
472         String got = ImportExportUtilities.getConfigurationXML(null);
473         assertNotNull(got);
474         assertEquals("", got);
475 
476         final SystemConfiguration config = new SystemConfiguration();
477         config.setId(1);
478         config.setVersion("1/1");
479         final CustomField customField1 = new CustomField();
480         customField1.setFieldType(Type.STRING);
481         customField1.setId(1);
482         config.getCustomFields().add(customField1);
483         final CustomField customField2 = new CustomField();
484         customField2.setFieldType(Type.LIST);
485         customField2.setId(2);
486         CustomFieldValue customFieldValue = new CustomFieldValue();
487         customFieldValue.setId(2);
488         customFieldValue.setValue("value2");
489         final CustomField customField3 = new CustomField();
490         customField3.setFieldType(Type.LIST);
491         customFieldValue.setCustomField(new CustomField());
492 
493         customField2.getOptions().add(customFieldValue);
494         config.getCustomFields().add(customField2);
495 
496 
497         config.getResolutions().add(new Configuration(Configuration.Type.resolution, "resolution"));
498 
499         config.getSeverities().add(new Configuration(Configuration.Type.severity, "severity"));
500 
501         config.getStatuses().add(new Configuration(Configuration.Type.status, "status"));
502 
503         final String expected = "<root>"
504                 + readXmlString("org/itracker/services/util/testGetConfigurationXMLExpected.xml")
505                 + "</root>";
506 
507         final String xml = "<root>" + ImportExportUtilities.getConfigurationXML(config) + "</root>";
508         assertNotNull("xml", xml);
509         assertContainsAll("xml", DocumentHelper.parseText(flatXml(expected)),
510                 DocumentHelper.parseText(flatXml(xml)));
511 
512     }
513 
514     private String readXmlString(String filename) {
515         InputStreamReader is = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(filename));
516         StringBuilder sb = new StringBuilder();
517         try {
518             while (is.ready()) {
519                 sb.append((char) is.read());
520             }
521         } catch (IOException e) {
522             fail(e.getMessage());
523         }
524         return sb.toString();
525     }
526 
527     @Test
528     public void testConstructor() {
529         ImportExportUtilities importExportUtilities = new ImportExportUtilities();
530 
531         assertNotNull(importExportUtilities);
532 
533     }
534 
535     @Test
536     // Cannot test this it's not a real test, String is not XML anyway! (XML is structured, String is pain)
537     public void testGetIssueXML() throws DocumentException {
538 
539         String got = ImportExportUtilities.getIssueXML(null);
540         assertNotNull(got);
541         assertEquals("", got);
542 
543 
544         final User creator = new User();
545         creator.setId(1);
546         final User owner = new User();
547         owner.setId(2);
548         final Project project = new Project("project");
549         project.setId(1);
550         project.getOwners().add(creator);
551         project.getOwners().add(owner);
552         final Component component = new Component(project, "component");
553         project.getComponents().add(component);
554         final Issue issue = new Issue();
555         issue.setProject(project);
556         issue.setId(1);
557         issue.setDescription("issue description");
558         issue.setSeverity(1);
559         issue.setResolution("fixed");
560         issue.setTargetVersion(new Version(project, "1.1.1"));
561         final Date dateCreate = new Date();
562         issue.setCreateDate(dateCreate);
563         final Date dateModify = new Date();
564         issue.setLastModifiedDate(dateModify);
565         issue.setCreator(creator);
566         issue.setOwner(owner);
567         final IssueHistory issueHistory = new IssueHistory(issue, creator, "some description", IssueUtilities.STATUS_NEW);
568         issueHistory.setCreateDate(dateCreate);
569         issueHistory.setLastModifiedDate(dateModify);
570         issue.getHistory().add(issueHistory);
571         issue.getComponents().add(component);
572         final IssueAttachment attachment = new IssueAttachment(issue, "file.txt");
573         attachment.setUser(creator);
574         issue.getAttachments().add(attachment);
575         issue.getVersions().add(new Version(project, "1.1.1"));
576         issue.getVersions().add(new Version(project, "1.1.2"));
577         IssueField issueField = new IssueField();
578         issueField.setId(1);
579         issueField.setStringValue("issue Field");
580         CustomField customField = new CustomField();
581         customField.setId(2);
582 //        customField.setName("customFieldName");
583         customField.setFieldType(Type.STRING);
584         issueField.setCustomField(customField);
585 
586 
587         issue.getFields().add(issueField);
588 
589         final String expected = "<issue id=\"issue1\" systemid=\"1\">" +
590                 "<issue-project><![CDATA[project1]]></issue-project>" +
591                 "<issue-description><![CDATA[issue description]]></issue-description>" +
592                 "<issue-severity>1</issue-severity>" +
593                 "<issue-status>null</issue-status>" +
594                 "<issue-resolution><![CDATA[fixed]]></issue-resolution>" +
595                 "<target-version-id>versionnull</target-version-id>" +
596                 "<create-date>" + ImportExportTags.DATE_FORMATTER.format(dateCreate) + "</create-date>" +
597                 "<last-modified>" + ImportExportTags.DATE_FORMATTER.format(dateModify) + "</last-modified>" +
598                 "<creator>user1</creator>" +
599                 "<owner>user2</owner>" +
600                 "<issue-components>" +
601                 "<component-id>componentnull</component-id>" +
602                 "</issue-components>" +
603                 "<issue-versions>" +
604                 "<version-id>versionnull</version-id>" +
605                 "<version-id>versionnull</version-id>" +
606                 "</issue-versions>" +
607                 "<issue-fields><issue-field id=\"custom-field2\">" +
608                 "<![CDATA[issue Field]]></issue-field></issue-fields>" +
609                 "<issue-attachments>" +
610                 "<issue-attachment>      <issue-attachment-description><![CDATA[]]></issue-attachment-description>" +
611                 "<issue-attachment-filename><![CDATA[]]></issue-attachment-filename>" +
612                 "<issue-attachment-origfile><![CDATA[file.txt]]></issue-attachment-origfile>" +
613                 "<issue-attachment-size><![CDATA[0]]></issue-attachment-size>" +
614                 "<issue-attachment-type><![CDATA[application/octet-stream]]></issue-attachment-type>" +
615                 "<issue-attachment-creator><![CDATA[user1]]></issue-attachment-creator>" +
616                 "</issue-attachment>" +
617                 "</issue-attachments>" +
618                 "<issue-history>" +
619                 "<history-entry creator-id=\"user1\" date=\"" + ImportExportTags.DATE_FORMATTER.format(dateCreate) + "\" status=\"100\"><![CDATA[some description]]></history-entry>" +
620                 "</issue-history>" +
621                 "</issue>";
622 
623 
624         final String xml = ImportExportUtilities.getIssueXML(issue);
625         assertNotNull("xml", xml);
626         assertContainsAll("xml", DocumentHelper.parseText(flatXml(expected)),
627                 DocumentHelper.parseText(flatXml(xml)));
628 
629 
630 
631     }
632 
633     @Test
634     public void testGetProjectXML() throws DocumentException {
635 
636         String got = ImportExportUtilities.getProjectXML(null);
637         assertNotNull(got);
638         assertEquals("", got);
639 
640         final Project project = new Project("project");
641         project.setId(1);
642         final Component component = new Component(project, "component");
643         component.setId(1);
644         project.getComponents().add(component);
645 
646         CustomField customField = new CustomField();
647         customField.setId(1);
648         project.getCustomFields().add(customField);
649         Version version = new Version(project, "1.1.1");
650         version.setId(1);
651         project.getVersions().add(version);
652 
653 
654         final String expected = "<project id=\"project1\" systemid=\"1\">" +
655                 "<project-name><![CDATA[project]]></project-name>" +
656                 "<project-description><![CDATA[]]></project-description>" +
657                 "<project-status>" + ProjectUtilities.getStatusName(project.getStatus(), ImportExportUtilities.EXPORT_LOCALE) + "</project-status>" +
658                 "<project-options>0</project-options>" +
659                 "<project-custom-fields><project-custom-field>custom-field1</project-custom-field></project-custom-fields>" +
660                 "<components>" +
661                 "<component id=\"component1\" systemid=\"1\">" +
662                 "<component-name><![CDATA[component]]></component-name>" +
663                 "<component-description><![CDATA[]]></component-description>" +
664                 "</component>" +
665                 "</components>" +
666                 "<versions><version id=\"version1\" systemid=\"1\"><version-number><![CDATA[1.1.1]]>" +
667                 "</version-number><version-description><![CDATA[]]></version-description></version></versions>" +
668                 "</project>";
669 
670         final String xml = ImportExportUtilities.getProjectXML(project);
671         assertNotNull("xml", xml);
672         assertContainsAll("xml", DocumentHelper.parseText(expected),
673                 DocumentHelper.parseText(xml));
674     }
675 
676     @Test
677     public void testGetUserXML() throws DocumentException {
678         String got = ImportExportUtilities.getUserXML(null);
679         assertNotNull(got);
680         assertEquals("", got);
681 
682         final User user = new User();
683         user.setId(1);
684         user.setFirstName("firstName");
685         user.setLastName("lastName");
686         final String expected = "<user id=\"user1\" systemid=\"1\">" +
687                 "<login><![CDATA[]]></login>" +
688                 "<first-name><![CDATA[firstName]]></first-name>" +
689                 "<last-name><![CDATA[lastName]]></last-name>" +
690                 "<email><![CDATA[]]></email>" +
691                 "<user-status>0</user-status>" +
692                 "<super-user>false</super-user>" +
693                 "</user>";
694         final String xml = ImportExportUtilities.getUserXML(user);
695         assertNotNull("xml", xml);
696         assertContainsAll("xml", DocumentHelper.parseText(expected),
697                 DocumentHelper.parseText(xml));
698 
699     }
700 
701     /**
702      * Defines a set of datafiles to be uploaded into database.
703      *
704      * @return an array with datafiles.
705      */
706     protected String[] getDataSetFiles() {
707         return new String[]{
708                 "dataset/languagebean_dataset.xml"
709         };
710     }
711 
712     /**
713      * Defines a simple configuration, required for running tests.
714      *
715      * @return an array of references to configuration files.
716      */
717     protected String[] getConfigLocations() {
718         return new String[]{"src/main/resources/application-context.xml"};
719     }
720 }