Skip to main content
summaryrefslogtreecommitdiffstats
blob: f2bac45656c0f6a9ff762f93f3cb71731028875b (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
/*******************************************************************************
 * 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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.util.Collections;
import java.util.List;
import javax.ws.rs.core.Response;
import org.eclipse.osee.ats.client.integration.tests.AtsClientService;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.CoreBranches;
import org.eclipse.osee.framework.core.enums.DemoUsers;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactCache;
import org.eclipse.osee.framework.skynet.core.artifact.ArtifactTypeManager;
import org.eclipse.osee.framework.skynet.core.artifact.search.ArtifactQuery;
import org.eclipse.osee.orcs.rest.model.OrcsWriterEndpoint;
import org.eclipse.osee.orcs.rest.model.writer.reader.OwArtifact;
import org.eclipse.osee.orcs.rest.model.writer.reader.OwArtifactToken;
import org.eclipse.osee.orcs.rest.model.writer.reader.OwCollector;
import org.junit.Before;
import org.junit.Test;

/**
 * Test unit for {@link OrcsWriterEndpoint}
 *
 * @author Donald G. Dunne
 */
public class OrcsWriterEndpointTest extends AbstractRestTest {
   private OrcsWriterEndpoint writer;

   @Before
   public void setup() {
      writer = AtsClientService.getOrcsWriter();
   }

   @Test
   public void testGetOrcsWriterInputDefaultJson() throws Exception {
      OwCollector collector = getDefaultOwCollector();
      assertEquals(3, collector.getCreate().size());
   }

   private OwCollector getDefaultOwCollector() throws Exception {
      Response response = writer.getOrcsWriterInputDefaultJson();
      assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.getStatus());
      OwCollector collector = response.readEntity(OwCollector.class);
      return collector;
   }

   @Test
   public void testGetOrcsWriterInputDefault() throws Exception {
      Response response = writer.getOrcsWriterInputDefault();
      assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.getStatus());
      String excelXml = response.readEntity(String.class);
      assertTrue(excelXml.contains("Orcs Writer Import Folder"));
   }

   @Test
   public void testValidate() throws Exception {
      OwCollector collector = getDefaultOwCollector();
      collector.setAsUserId(DemoUsers.Joe_Smith.getUserId());
      collector.setPersistComment(getClass().getSimpleName() + " - testValidate");
      Response response = writer.getOrcsWriterValidate(collector);
      assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.getStatus());
   }

   @Test
   public void testPersist() throws Exception {
      OwCollector collector = getDefaultOwCollector();
      collector.setAsUserId(DemoUsers.Joe_Smith.getUserId());
      collector.setPersistComment(getClass().getSimpleName() + " - testPersist");
      Response response = writer.getOrcsWriterPersist(collector);
      assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.getStatus());

      for (OwArtifact art : collector.getCreate()) {
         long artTypeId = art.getType().getId();
         ArtifactType typeById = ArtifactTypeManager.getTypeByGuid(artTypeId);
         assertNotNull(typeById);
         if (typeById.equals(CoreArtifactTypes.Folder)) {
            long artId = art.getId();
            Artifact folderArt = AtsClientService.get().getArtifact(artId);
            assertNotNull(folderArt);
            assertEquals(2, folderArt.getChildren().size());
            for (Artifact child : folderArt.getChildren()) {
               assertTrue(
                  child.getName().equals("Software Requirement 1") || child.getName().equals("Software Requirement 2"));
            }
         }
      }

      OwArtifact userGroupOwArt = collector.getUpdate().iterator().next();
      Artifact userGroupArt = AtsClientService.get().getArtifact(userGroupOwArt.getId());
      assertNotNull(userGroupArt);
      assertEquals("test static id", userGroupArt.getSoleAttributeValue(CoreAttributeTypes.StaticId, null));
      assertEquals("test annotation", userGroupArt.getSoleAttributeValue(CoreAttributeTypes.Annotation, null));

   }

   @Test
   public void testDelete() throws Exception {
      Artifact artifact = ArtifactTypeManager.addArtifact(CoreArtifactTypes.GeneralData, CoreBranches.COMMON,
         getClass().getSimpleName());
      artifact.persist(getClass().getSimpleName());

      Artifact artifactFromId1 = ArtifactQuery.getArtifactFromId(artifact.getId(), CoreBranches.COMMON);
      assertNotNull(artifactFromId1);

      OwCollector collector = getDefaultOwCollector();
      collector.getCreate().clear();
      collector.getUpdate().clear();
      OwArtifactToken owToken = new OwArtifactToken();
      owToken.setId(artifact.getId());
      owToken.setName(artifact.getName());
      String tokenStr = String.format("[%s]-[%d]", artifact.getName(), artifact.getId());
      owToken.setData(tokenStr);
      collector.getDelete().add(owToken);

      collector.setAsUserId(DemoUsers.Joe_Smith.getUserId());
      collector.setPersistComment(getClass().getSimpleName() + " - testValidate");

      Response response = writer.getOrcsWriterPersist(collector);
      assertEquals(javax.ws.rs.core.Response.Status.OK.getStatusCode(), response.getStatus());

      ArtifactCache.deCache(artifactFromId1);

      List<Artifact> artifacts =
         ArtifactQuery.getArtifactListFromIds(Collections.singleton(artifact.getId().intValue()), CoreBranches.COMMON);
      assertTrue(artifacts.iterator().next().isDeleted());
   }
}

Back to the top