Skip to main content
summaryrefslogtreecommitdiffstats
blob: 947eb028cb0ad7863126575828b64fb51b65de92 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*******************************************************************************
 * Copyright (c) 2010 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ats.client.integration.tests.ats.core.client.workflow.note;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.eclipse.osee.ats.core.client.util.AtsUsersClient;
import org.eclipse.osee.ats.core.client.workflow.note.NoteItem;
import org.eclipse.osee.ats.core.client.workflow.note.NoteType;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.DateUtil;
import org.junit.Assert;
import org.junit.Test;

/**
 * @author Donald G. Dunne
 */
public class NoteItemTest {

   @Test
   public void testNoteItemNoteTypeStringStringUserString() throws OseeCoreException {
      Date date = new Date();
      NoteItem item =
         new NoteItem(NoteType.Comment, "Implement", String.valueOf(date.getTime()), AtsUsersClient.getUser(), "my msg");
      validate(item, date);
   }

   public static void validate(NoteItem item, Date date) throws OseeCoreException {
      Assert.assertEquals(NoteType.Comment, item.getType());
      Assert.assertEquals("Implement", item.getState());
      Assert.assertEquals(AtsUsersClient.getUser(), item.getUser());
      Assert.assertEquals("my msg", item.getMsg());
   }

   public static NoteItem getTestNoteItem(Date date) throws OseeCoreException {
      return new NoteItem(NoteType.Comment, "Implement", String.valueOf(date.getTime()), AtsUsersClient.getUser(), "my msg");
   }

   @Test
   public void testNoteItemStringStringStringUserString() throws OseeCoreException {
      Date date = new Date();
      NoteItem item =
         new NoteItem(NoteType.Comment.name(), "Implement", String.valueOf(date.getTime()), AtsUsersClient.getUser(),
            "my msg");
      validate(item, date);
   }

   @Test
   public void testToString() throws OseeCoreException {
      Date date = new Date();
      NoteItem item = getTestNoteItem(date);

      Assert.assertEquals(
         "Note: Comment from " + AtsUsersClient.getUser().getName() + " for \"Implement\" on " + DateUtil.getMMDDYYHHMM(date) + " - my msg",
         item.toString());
   }

   @Test
   public void testToXmlFromXml() throws OseeCoreException {
      Date date = new Date();
      NoteItem item = getTestNoteItem(date);
      NoteItem item2 =
         new NoteItem(NoteType.Question.name(), "Analyze", String.valueOf(date.getTime()), AtsUsersClient.getUser(),
            "another message");

      String xml = NoteItem.toXml(Arrays.asList(item, item2));
      Assert.assertEquals(
         "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><AtsNote>" + //
         "<Item date=\"" + date.getTime() + "\" msg=\"my msg\" state=\"Implement\" type=\"Comment\" userId=\"" + AtsUsersClient.getUser().getUserId() + "\"/>" + //
         "<Item date=\"" + date.getTime() + "\" msg=\"another message\" state=\"Analyze\" type=\"Question\" userId=\"" + AtsUsersClient.getUser().getUserId() + "\"/></AtsNote>",
         xml);

      List<NoteItem> items = NoteItem.fromXml(xml, "ASDF4");
      validate(items.iterator().next(), date);

      NoteItem fromXmlItem2 = items.get(1);
      Assert.assertEquals(NoteType.Question, fromXmlItem2.getType());
      Assert.assertEquals("Analyze", fromXmlItem2.getState());
      Assert.assertEquals(AtsUsersClient.getUser(), fromXmlItem2.getUser());
      Assert.assertEquals("another message", fromXmlItem2.getMsg());

   }

   @Test
   public void testToHTML() throws OseeCoreException {
      Date date = new Date();
      NoteItem item = getTestNoteItem(date);

      Assert.assertEquals(
         "<b>Note:</b>Comment from " + AtsUsersClient.getUser().getName() + " for \"Implement\" on " + DateUtil.getMMDDYYHHMM(date) + " - my msg",
         item.toHTML());
   }

}

Back to the top