Skip to main content
summaryrefslogtreecommitdiffstats
blob: 3281f83f4f2eff4f1c0708e41a1191aa3255b70f (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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/*******************************************************************************
 * 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.junit.Assert.assertEquals;
import java.io.StringWriter;
import java.util.Properties;
import org.databene.contiperf.PerfTest;
import org.eclipse.osee.framework.core.data.IOseeBranch;
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.Identity;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
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.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.MethodRule;

@PerfTest(threads = 2, invocations = 100)
public class OseeClientQueryTest {

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

   private static final IOseeBranch SAW_1 = new IOseeBranch() {

      @Override
      public Long getGuid() {
         return 3L;
      }

      @Override
      public boolean matches(Identity<?>... identities) {
         return false;
      }

      @Override
      public String getName() {
         return "SAW_Bld_1";
      }

      @Override
      public Long getUuid() {
         return 3L;
      }
   };

   @Rule
   public MethodRule performanceRule = IntegrationUtil.createPerformanceRule();

   private static OseeClient createClient;

   @BeforeClass
   public static void testSetup() throws OseeCoreException {
      createClient = IntegrationUtil.createClient();

      // 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.Guest).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(9).getSearchResult(RequestType.IDS);
      assertEquals(EXPECTED_RESULTS, results.getTotal());
   }

   @Test
   public void searchForArtifactByLocalIds() throws OseeCoreException {
      final int EXPECTED_RESULTS = 2;
      SearchResult results = createClient.createQueryBuilder(COMMON).andLocalId(19, 9).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 = 43;
      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 = 7;
      SearchResult results =
         createClient.createQueryBuilder(SAW_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_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_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());
   }

   @PerfTest(threads = 1, invocations = 1)
   @Test
   public void orcsScript() {
      String script =
         "start from branch 570 find artifacts where art-type = 'Folder' collect artifacts {id, attributes { value } };";
      String expected =
         "{\n" + //
         "  'parameters' : {\n" + //
         "    'output.debug' : 'false'\n" + //
         "  },\n" + //
         "  'script' : 'start from branch 570 find artifacts where art-type = 'Folder' collect artifacts {id, attributes { value } };',\n" + //
         "  'results' : [ {\n" + //
         "    'artifacts' : [ {\n" + //
         "      'id' : 8,\n" + //
         "      'attributes' : {\n" + //
         "        'Name' : {\n" + //
         "          'value' : 'User Groups'\n" + //
         "        }\n" + //
         "      }\n" + //
         "    }, {\n" + //
         "      'id' : 26,\n" + //
         "      'attributes' : {\n" + //
         "        'Name' : {\n" + //
         "          'value' : 'Document Templates'\n" + //
         "        }\n" + //
         "      }\n" + //
         "    }, {\n" + //
         "      'id' : 31,\n" + //
         "      'attributes' : {\n" + //
         "        'Name' : {\n" + //
         "          'value' : 'Action Tracking System'\n" + //
         "        }\n" + //
         "      }\n" + //
         "    }, {\n" + //
         "      'id' : 34,\n" + //
         "      'attributes' : {\n" + //
         "        'Name' : {\n" + //
         "          'value' : 'Config'\n" + //
         "        }\n" + //
         "      }\n" + //
         "    }, {\n" + //
         "      'id' : 35,\n" + //
         "      'attributes' : {\n" + //
         "        'Name' : {\n" + //
         "          'value' : 'Work Definitions'\n" + //
         "        }\n" + //
         "      }\n" + //
         "    } ]\n" + //
         "  } ]\n" + //
         "}";

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

      assertEquals(expected, normalize(writer.toString()));
   }

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

Back to the top