Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3cbb09502264b15aa87cab18e390190a52a15ddd (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
/*******************************************************************************
 * Copyright (c) 2015 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.resource;

import com.google.common.collect.Lists;
import java.io.InputStream;
import java.util.List;
import org.eclipse.osee.ats.api.data.AtsArtifactTypes;
import org.eclipse.osee.ats.api.util.IAtsChangeSet;
import org.eclipse.osee.ats.client.integration.tests.AtsClientService;
import org.eclipse.osee.ats.client.integration.tests.DirtyArtifactCacheTest;
import org.eclipse.osee.ats.core.util.AtsUtilCore;
import org.eclipse.osee.define.report.api.WordArtifactChange;
import org.eclipse.osee.define.report.api.WordUpdateChange;
import org.eclipse.osee.define.report.api.WordUpdateData;
import org.eclipse.osee.define.report.api.WordUpdateEndpoint;
import org.eclipse.osee.framework.core.data.BranchId;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.enums.BranchType;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.QueryOption;
import org.eclipse.osee.framework.core.model.cache.BranchFilter;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.skynet.core.UserManager;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.BranchManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.framework.skynet.core.httpRequests.HttpWordUpdateRequest;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

/**
 * Test unit for {@link WordUpdateEndpoint}
 *
 * @author David W. Miller
 */
public class WordUpdateEndpointImplTest extends AbstractRestTest {
   private Artifact artReqt = null;
   private BranchId branch = null;

   @AfterClass
   public static void cleanup() {
      List<Artifact> teamWorkflows = ArtifactQuery.getArtifactListFromTypeAndName(AtsArtifactTypes.TeamWorkflow,
         "Safety", AtsUtilCore.getAtsBranch(), QueryOption.CONTAINS_MATCH_OPTIONS);
      IAtsChangeSet changes =
         AtsClientService.get().getStoreService().createAtsChangeSet(WordUpdateEndpointImplTest.class.getSimpleName());
      for (Artifact teamArt : teamWorkflows) {
         changes.deleteArtifact(teamArt);
      }
      changes.executeIfNeeded();

      new DirtyArtifactCacheTest().testArtifactCacheNotDirty();
   }

   @Before
   public void setup() {
      branch = getWorkingBranch();
      artReqt = ArtifactQuery.getArtifactFromTypeAndAttribute(CoreArtifactTypes.SoftwareRequirement,
         CoreAttributeTypes.Name, "Claw Interface Init 15", branch);
   }

   @Test
   public void testCreate() throws Exception {
      // get word xml
      String wordData = getResource();

      List<Long> transferArts = Lists.newLinkedList();
      transferArts.add(artReqt.getUuid());
      wordData = wordData.replaceAll("ABCgi5iUkGgj2zhlrOgA", artReqt.getGuid());

      WordUpdateChange change =
         makeRequest(branch.getUuid(), transferArts, wordData, "Testing word update one artifact");
      validateWordUpdateChange(change);
      validateSafetyTeamWFExists();
   }

   @Test
   public void testMissingArtifact() throws Exception {
      // get word xml
      InputStream inputStream = getClass().getResourceAsStream("data/testMissingArtifact.xml");
      String wordData = Lib.inputStreamToString(inputStream);
      wordData = wordData.replaceAll("A0UNsNvCigV4SyvaCCAA", artReqt.getGuid());

      List<Long> transferArts = Lists.newLinkedList();
      transferArts.add(artReqt.getUuid());

      WordUpdateChange change =
         makeRequest(branch.getUuid(), transferArts, wordData, "Testing word update one artifact");
      validateWordUpdateChange(change);
   }

   private void validateWordUpdateChange(WordUpdateChange change) {
      List<WordArtifactChange> changes = change.getChangedArts();
      Assert.assertTrue(changes.size() == 1);
      WordArtifactChange wac = changes.get(0);
      Assert.assertEquals(wac.getArtId(), artReqt.getUuid().longValue());
   }

   private void validateSafetyTeamWFExists() {
      List<Artifact> teamWorkflows = ArtifactQuery.getArtifactListFromTypeAndName(AtsArtifactTypes.TeamWorkflow,
         "Safety Workflow", AtsUtilCore.getAtsBranch(), QueryOption.CONTAINS_MATCH_OPTIONS);
      Assert.assertFalse(teamWorkflows.isEmpty());
   }

   private WordUpdateChange makeRequest(long branchId, List<Long> artifacts, String wordData, String comment) {
      byte[] data = wordData.getBytes();
      WordUpdateData wud = new WordUpdateData();
      wud.setWordData(data);
      wud.setArtifacts(artifacts);
      wud.setBranch(branchId);
      wud.setThreeWayMerge(false);
      wud.setComment(comment);
      wud.setMultiEdit(false);
      wud.setUserArtId((long) UserManager.getUser().getArtId());

      WordUpdateChange change = HttpWordUpdateRequest.updateWordArtifacts(wud);
      return change;
   }

   private BranchId getWorkingBranch() {
      BranchId branchReturn = null;
      BranchFilter branchFilter = new BranchFilter(BranchType.WORKING);
      List<IOseeBranch> branches = BranchManager.getBranches(branchFilter);
      for (IOseeBranch branch : branches) {
         if (branch.getName().contains("More Reqt")) {
            branchReturn = branch;
            break;
         }
      }
      return branchReturn;
   }

   private String getResource() throws Exception {
      InputStream inputStream = getClass().getResourceAsStream("data/testSoftwareRequirement.xml");
      return Lib.inputStreamToString(inputStream);
   }

}

Back to the top