Skip to main content
summaryrefslogtreecommitdiffstats
blob: c890404161b64141f2521ef5c04203416940cb45 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/*******************************************************************************
 * Copyright (c) 2004, 2007 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.client.integration.tests.integration.ui.skynet;

import static java.lang.Thread.sleep;
import static org.eclipse.osee.client.demo.DemoChoice.OSEE_CLIENT_DEMO;
import static org.eclipse.osee.framework.core.enums.DeletionFlag.INCLUDE_DELETED;
import static org.eclipse.osee.framework.core.enums.DemoBranches.SAW_Bld_2;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
import org.eclipse.core.resources.IFolder;
import org.eclipse.osee.client.test.framework.OseeClientIntegrationRule;
import org.eclipse.osee.client.test.framework.OseeLogMonitorRule;
import org.eclipse.osee.framework.access.AccessControlManager;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.enums.PermissionEnum;
import org.eclipse.osee.framework.core.enums.PresentationType;
import org.eclipse.osee.framework.core.model.TransactionDelta;
import org.eclipse.osee.framework.core.operation.IOperation;
import org.eclipse.osee.framework.core.operation.Operations;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
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.revision.ChangeManager;
import org.eclipse.osee.framework.ui.skynet.render.IRenderer;
import org.eclipse.osee.framework.ui.skynet.render.RendererManager;
import org.eclipse.osee.framework.ui.skynet.render.RenderingUtil;
import org.eclipse.osee.framework.ui.skynet.render.compare.CompareData;
import org.eclipse.osee.framework.ui.skynet.render.compare.CompareDataCollector;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

/**
 * @author Megumi Telles
 */
public final class ViewWordChangeAndDiffTest {

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

   @Rule
   public OseeLogMonitorRule monitorRule = new OseeLogMonitorRule();

   private IFolder renderFolder;
   private BranchId branch;

   @Before
   public void setUp() throws Exception {
      renderFolder = RenderingUtil.ensureRenderFolderExists(PresentationType.DIFF);
      branch = SAW_Bld_2;
   }

   @Test
   public void testCompareTwoArtifacts() throws Exception {
      Collection<Change> changes = getChanges(branch);
      ArrayList<Artifact> artifacts = asArtifacts(changes);

      checkPermissions(artifacts);
      TransactionDelta txDelta = changes.iterator().next().getTxDelta();
      Artifact newerArtifact = loadHistorical(artifacts.get(0));
      Artifact baseArtifact = loadHistorical(artifacts.get(1));

      final Collection<CompareData> testDatas = new ArrayList<>();

      CompareDataCollector collector = new CompareDataCollector() {

         @Override
         public void onCompare(CompareData data) {
            testDatas.add(data);
         }
      };

      RendererManager.diff(collector, new ArtifactDelta(txDelta, baseArtifact, newerArtifact), "", IRenderer.NO_DISPLAY,
         true);

      sleep(2000);

      Assert.assertEquals(1, testDatas.size());
      CompareData testData = testDatas.iterator().next();

      Assert.assertEquals(1, testData.size());
      Entry<String, String> fileSet = testData.entrySet().iterator().next();

      File vbScript = new File(testData.getGeneratorScriptPath());
      File outPut = new File(testData.getOutputPath());
      File file1 = new File(fileSet.getKey());
      File file2 = new File(fileSet.getValue());

      Assert.assertTrue(vbScript.exists());
      Assert.assertTrue(file1.exists());
      Assert.assertTrue(file2.exists());

      if (Lib.isWindows()) {
         Assert.assertTrue(outPut.exists());
      }
   }

   @Test
   public void testViewWordChangeReport() throws Exception {
      Collection<Change> changes = getChanges(branch);
      checkPermissions(asArtifacts(changes));

      Collection<ArtifactDelta> artifactDeltas = ChangeManager.getCompareArtifacts(changes);
      RendererManager.diff(artifactDeltas, "testDiff", IRenderer.NO_DISPLAY, true);
      verifyRenderFolderExists();
   }

   @Test
   public void testSingleNativeDiff() throws Exception {
      Collection<Change> changes = getChanges(branch);
      Artifact artifact = changes.iterator().next().getChangeArtifact();

      checkPermissions(Collections.singletonList(artifact));

      Collection<ArtifactDelta> artifactDeltas = ChangeManager.getCompareArtifacts(changes);
      RendererManager.diff(artifactDeltas, "", IRenderer.NO_DISPLAY, true);

      verifyRenderFolderExists();

      assertTrue("Single Native Diff test passed", true);
   }

   private static Collection<Change> getChanges(BranchId testBranch) throws OseeCoreException {
      Collection<Change> changes = new ArrayList<>();
      IOperation operation = ChangeManager.comparedToParent(testBranch, changes);
      Operations.executeWorkAndCheckStatus(operation);
      return changes;
   }

   private void verifyRenderFolderExists() {
      Assert.assertNotNull(renderFolder);
      Assert.assertTrue(renderFolder.exists());
   }

   private static Artifact loadHistorical(Artifact artifact) throws OseeCoreException {
      return ArtifactQuery.getHistoricalArtifactFromId(artifact.getArtId(), artifact.getTransaction(), INCLUDE_DELETED);
   }

   private static void checkPermissions(List<Artifact> artifacts) throws OseeCoreException {
      boolean isReadable = AccessControlManager.hasPermission(artifacts, PermissionEnum.READ);
      assertTrue("Valid object permissions", isReadable);
   }

   private static ArrayList<Artifact> asArtifacts(Collection<Change> changes) {
      ArrayList<Artifact> arts = new ArrayList<>();
      for (Change artifactChange : changes) {
         arts.add(artifactChange.getChangeArtifact());
      }
      return arts;
   }
}

Back to the top