Skip to main content
summaryrefslogtreecommitdiffstats
blob: a3976a74750ba3add71bf0c5da6c73ab2a032fbb (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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*******************************************************************************
 * Copyright (c) 2013 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.x.server.integration.tests.performance;

import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.Folder;
import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.GeneralData;
import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.GeneralDocument;
import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.Requirement;
import static org.eclipse.osee.framework.core.enums.CoreArtifactTypes.SoftwareRequirement;
import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.AccessContextId;
import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.Active;
import static org.eclipse.osee.framework.core.enums.CoreBranches.COMMON;
import static org.eclipse.osee.framework.core.enums.DemoBranches.SAW_Bld_1;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.StringWriter;
import java.util.Properties;
import javax.ws.rs.core.MediaType;
import org.eclipse.osee.framework.core.enums.CoreArtifactTokens;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.enums.QueryOption;
import org.eclipse.osee.framework.core.enums.SystemUser;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.jdk.core.type.OseeStateException;
import org.eclipse.osee.orcs.rest.client.OseeClient;
import org.eclipse.osee.orcs.rest.model.search.artifact.RequestType;
import org.eclipse.osee.orcs.rest.model.search.artifact.SearchResult;
import org.eclipse.osee.x.server.integration.tests.util.IntegrationUtil;
import org.junit.BeforeClass;
import org.junit.Test;

public class OseeClientQueryTest {

   private static final String GUID1 = SystemUser.Anonymous.getGuid();
   private static final String GUID2 = SystemUser.OseeSystem.getGuid();

   private static OseeClient createClient;

   @BeforeClass
   public static void testSetup() throws OseeCoreException {
      createClient = IntegrationUtil.createClient();
      if (!createClient.isLocalHost()) {
         throw new OseeStateException("This test should be run with local test server, not %s",
            createClient.getBaseUri());
      }

      // Establish initial connection to the db using this random query
      createClient.createQueryBuilder(COMMON).andIds(SystemUser.OseeSystem).getSearchResult(RequestType.IDS);
   }

   @Test
   public void searchForAttributeTypeByTokenId() throws OseeCoreException {
      final int EXPECTED_RESULTS = 1;
      SearchResult results =
         createClient.createQueryBuilder(COMMON).andIds(SystemUser.OseeSystem).getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForAttributeTypeByTokenIds() throws OseeCoreException {
      final int EXPECTED_RESULTS = 2;
      SearchResult results =
         createClient.createQueryBuilder(COMMON).andIds(SystemUser.OseeSystem, SystemUser.Anonymous).getSearchResult(
            RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForArtifactByGuid() throws OseeCoreException {
      final int EXPECTED_RESULTS = 1;
      SearchResult results = createClient.createQueryBuilder(COMMON).andGuids(GUID1).getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForArtifactByGuids() throws OseeCoreException {
      final int EXPECTED_RESULTS = 2;
      SearchResult results =
         createClient.createQueryBuilder(COMMON).andGuids(GUID1, GUID2).getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForArtifactByLocalId() throws OseeCoreException {
      final int EXPECTED_RESULTS = 1;
      SearchResult results =
         createClient.createQueryBuilder(COMMON).andLocalId(CoreArtifactTokens.UserGroups).getSearchResult(
            RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForArtifactByName() throws OseeCoreException {
      final int EXPECTED_RESULTS = 1;
      SearchResult results =
         createClient.createQueryBuilder(COMMON).andNameEquals("Joe Smith").getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForArtifactWithActionInName() throws OseeCoreException {
      final int EXPECTED_RESULTS = 45;
      SearchResult results = createClient.createQueryBuilder(COMMON).and(CoreAttributeTypes.Name, "SAW",
         QueryOption.CASE__IGNORE, QueryOption.TOKEN_MATCH_ORDER__MATCH, QueryOption.TOKEN_DELIMITER__ANY,
         QueryOption.TOKEN_COUNT__IGNORE).getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForArtifactType() throws OseeCoreException {
      final int EXPECTED_RESULTS = 8;
      SearchResult results =
         createClient.createQueryBuilder(SAW_Bld_1).andTypeEquals(Folder).getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForArtifactTypes() throws OseeCoreException {
      final int EXPECTED_RESULTS = 24;
      SearchResult results = createClient.createQueryBuilder(SAW_Bld_1).andTypeEquals(GeneralData, GeneralDocument,
         SoftwareRequirement).getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForArtifactTypesIncludeTypeInheritance() throws OseeCoreException {
      final int EXPECTED_RESULTS = 150;
      SearchResult results = createClient.createQueryBuilder(SAW_Bld_1).andIsOfType(GeneralData, GeneralDocument,
         Requirement).getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForExistenceOfAttributeType() throws OseeCoreException {
      final int EXPECTED_RESULTS = 28;
      SearchResult results = createClient.createQueryBuilder(COMMON).andExists(Active).getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForExistenceOfAttributeTypeIncludeDeleted() throws OseeCoreException {
      final int EXPECTED_RESULTS = 28;
      SearchResult results =
         createClient.createQueryBuilder(COMMON).andExists(Active).includeDeleted().getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForExistenceOfAttributeTypes() throws OseeCoreException {
      final int EXPECTED_RESULTS = 28;
      SearchResult results =
         createClient.createQueryBuilder(COMMON).andExists(Active, AccessContextId).getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   /**
    * This test simply ensures that the client endpoint to run Orcs Script works. OrcsScriptTest is the more exhaustive
    * test of Orcs Script.
    */
   @Test
   public void orcsScript() {
      String script =
         "start from branch 570 find artifacts where art-type = 'Folder' collect artifacts {id, attributes { value } };";

      StringWriter writer = new StringWriter();
      Properties properties = new Properties();
      createClient.executeScript(script, properties, false, MediaType.APPLICATION_JSON_TYPE, writer);

      assertTrue(normalize(writer.toString()).contains("'value' : 'User Groups'"));
   }

   private String normalize(String value) {
      value = value.replaceAll("\r\n", "\n");
      value = value.replaceAll("\"", "'");
      return value;
   }
}

Back to the top