Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 2c4e239b0521b9e2149a685a8641cbf2331bd14a (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
/*********************************************************************
 * Copyright (c) 2015 Boeing
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Boeing - initial API and implementation
 **********************************************************************/

package org.eclipse.osee.client.integration.tests.integration.ui.skynet;

import static org.eclipse.osee.client.demo.DemoChoice.OSEE_CLIENT_DEMO;
import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import java.util.Arrays;
import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule;
import org.eclipse.osee.client.test.framework.OseeLogMonitorRule;
import org.eclipse.osee.client.test.framework.TestInfo;
import org.eclipse.osee.framework.core.data.TransactionToken;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.ModificationType;
import org.eclipse.osee.framework.core.model.TransactionDelta;
import org.eclipse.osee.framework.core.model.TransactionRecord;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.change.ArtifactChange;
import org.eclipse.osee.framework.skynet.core.change.ArtifactDelta;
import org.eclipse.osee.framework.skynet.core.change.Change;
import org.eclipse.osee.framework.skynet.core.transaction.TransactionManager;
import org.eclipse.osee.framework.ui.skynet.render.RenderingUtil;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

/**
 * @author Megumi Telles
 */
public class ArtifactRendererTest {

   @Rule
   public OseeClientIntegrationRule integration = new OseeClientIntegrationRule(OSEE_CLIENT_DEMO);

   @Rule
   public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule();

   @Rule
   public TestInfo method = new TestInfo();

   private static final String NAME1 = "Name with \"quote\"";
   private static final String NAME2 = "Name with 'quote'";
   private static final String EXPECTED_NAME = "Name+with+_quot";
   private static Artifact artifact1;
   private static Artifact artifact2;
   private static TransactionToken startTx;
   private static TransactionRecord endTx1;
   private static TransactionRecord endTx2;

   @Before
   public void setUp() {

      startTx = TransactionManager.getHeadTransaction(COMMON);
      artifact1 = new Artifact(CoreBranches.COMMON, NAME1);
      String comment1 = getClass().getSimpleName() + "_1";
      artifact1.persist(comment1);
      endTx1 = TransactionManager.getTransaction(comment1).iterator().next();
      endTx1.setCommit((long) artifact1.getArtId());

      artifact2 = new Artifact(CoreBranches.COMMON, NAME2);
      String comment2 = getClass().getSimpleName() + "_2";
      artifact2.persist(comment2);
      endTx2 = TransactionManager.getTransaction(comment2).iterator().next();
      endTx2.setCommit((long) artifact2.getArtId());
   }

   @Test
   public void testAssociatedArtifact_notAllowedDoubleQuotes() throws Exception {

      TransactionDelta deltaTx = new TransactionDelta(startTx, endTx1);
      ArtifactDelta delta = new ArtifactDelta(null, artifact2, artifact1);
      Change change = new ArtifactChange(COMMON, artifact1.getGammaId(), artifact1, deltaTx, ModificationType.MODIFIED,
         "", "", false, artifact1, delta);

      String name = RenderingUtil.getAssociatedArtifactName(Arrays.asList(change));
      Assert.assertEquals(EXPECTED_NAME, name);
   }

   @Test
   public void testAssociatedArtifact_notAllowedSingleQuotes() throws Exception {
      TransactionDelta deltaTx = new TransactionDelta(startTx, endTx2);
      ArtifactDelta delta = new ArtifactDelta(null, artifact1, artifact2);
      Change change = new ArtifactChange(COMMON, artifact2.getGammaId(), artifact2, deltaTx, ModificationType.MODIFIED,
         "", "", false, artifact2, delta);

      String name = RenderingUtil.getAssociatedArtifactName(Arrays.asList(change));
      Assert.assertEquals(EXPECTED_NAME, name);
   }
}

Back to the top