Skip to main content
summaryrefslogtreecommitdiffstats
blob: 09365963b406ea4e63f292b70c37af36337ba948 (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
/*******************************************************************************
 * 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.orcs.api;

import static org.eclipse.osee.orcs.OrcsIntegrationRule.integrationRule;
import static org.junit.Assert.assertEquals;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptException;
import javax.script.SimpleScriptContext;
import org.eclipse.osee.orcs.OrcsApi;
import org.eclipse.osee.orcs.db.mock.OsgiService;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

/**
 * @author Roberto E. Escobar
 */
@RunWith(Parameterized.class)
public class OrcsScriptTest {

   @Rule
   public TestRule osgi = integrationRule(this);

   @OsgiService
   private OrcsApi orcsApi;

   private ScriptEngine engine;

   private final String script;
   private final String expected;

   public OrcsScriptTest(String script, String expected) {
      this.script = script;
      this.expected = expected;
   }

   @Before
   public void setup() {
      engine = orcsApi.getScriptEngine();
   }

   @Test
   public void testOrcsQuery() throws ScriptException {
      StringWriter writer = new StringWriter();
      engine.eval(script, newContext(writer));
      String actual = writer.toString();
      assertEquals(expected, normalize(actual));
   }

   @Parameters
   public static Iterable<Object[]> data() {
      List<Object[]> data = new ArrayList<>();

      add(data, "start from branch 570 collect branches {*}", //
         "{\n" + //
            "  'script' : 'start from branch 570 collect branches {*};',\n" + //
            "  'results' : [ {\n" + //
            "    'branches' : [ {\n" + //
            "      'archived' : 'UNARCHIVED',\n" + //
            "      'assoc-id' : -1,\n" + //
            "      'baseline-tx-id' : 4,\n" + //
            "      'id' : 570,\n" + //
            "      'inherits-access-control' : 0,\n" + //
            "      'name' : 'Common',\n" + //
            "      'parent-id' : 1,\n" + //
            "      'parent-tx-id' : 3,\n" + //
            "      'state' : 'MODIFIED',\n" + //
            "      'type' : 'BASELINE'\n" + //
            "    } ]\n" + //
            "  } ]\n" + //
            "}");

      add(data, "start from branch where state = modified collect branches {name};", //
         "{\n" + //
            "  'script' : 'start from branch where state = modified collect branches {name};',\n" + //
            "  'results' : [ {\n" + //
            "    'branches' : [ {\n" + //
            "      'name' : 'System Root Branch'\n" + //
            "    }, {\n" + //
            "      'name' : 'SAW_Bld_1'\n" + //
            "    }, {\n" + //
            "      'name' : 'CIS_Bld_1'\n" + //
            "    }, {\n" + //
            "      'name' : 'SAW_Bld_2'\n" + //
            "    }, {\n" + //
            "      'name' : 'Common'\n" + //
            "    }, {\n" + //
            "      'name' : 'ATS9 - SAW (uncommitted) More Reqt Changes for...'\n" + //
            "    }, {\n" + //
            "      'name' : 'ATS20 - SAW (uncommitted-conflicted) More Requi...'\n" + //
            "    } ]\n" + //
            "  } ]\n" + //
            "}");

      add(data,
         "start from branch 570 find artifacts where art-type = 'Folder' collect artifacts {id, attributes { value } };", //
         "{\n" + //
            "  'script' : 'start from branch 570 find artifacts where art-type = 'Folder' collect artifacts {id, attributes { value } };',\n" + //
            "  'results' : [ {\n" + //
            "    'artifacts' : [ {\n" + //
            "      'id' : 80920,\n" + //
            "      'attributes' : {\n" + //
            "        'Name' : {\n" + //
            "          'value' : 'User Groups'\n" + //
            "        }\n" + //
            "      }\n" + //
            "    }, {\n" + //
            "      'id' : 113036,\n" + //
            "      'attributes' : {\n" + //
            "        'Name' : {\n" + //
            "          'value' : 'Config'\n" + //
            "        }\n" + //
            "      }\n" + //
            "    }, {\n" + //
            "      'id' : 114713,\n" + //
            "      'attributes' : {\n" + //
            "        'Name' : {\n" + //
            "          'value' : 'Action Tracking System'\n" + //
            "        }\n" + //
            "      }\n" + //
            "    }, {\n" + //
            "      'id' : 200005,\n" + //
            "      'attributes' : {\n" + //
            "        'Name' : {\n" + //
            "          'value' : 'Document Templates'\n" + //
            "        }\n" + //
            "      }\n" + //
            "    }, {\n" + //
            "      'id' : 284655,\n" + //
            "      'attributes' : {\n" + //
            "        'Name' : {\n" + //
            "          'value' : 'Work Definitions'\n" + //
            "        }\n" + //
            "      }\n" + //
            "    }, {\n" + //
            "      'id' : 6915493,\n" + //
            "      'attributes' : {\n" + //
            "        'Name' : {\n" + //
            "          'value' : 'Agile'\n" + //
            "        }\n" + //
            "      }\n" + //
            "    }, {\n" + //
            "      'id' : 7968155,\n" + //
            "      'attributes' : {\n" + //
            "        'Name' : {\n" + //
            "          'value' : 'Countries'\n" + //
            "        }\n" + //
            "      }\n" + //
            "    }, {\n" + //
            "      'id' : 545949432,\n" + //
            "      'attributes' : {\n" + //
            "        'Name' : {\n" + //
            "          'value' : 'Sprints'\n" + //
            "        }\n" + //
            "      }\n" + //
            "    }, {\n" + //
            "      'id' : 849027577,\n" + //
            "      'attributes' : {\n" + //
            "        'Name' : {\n" + //
            "          'value' : 'Feature Groups'\n" + //
            "        }\n" + //
            "      }\n" + //
            "    } ]\n" + //
            "  } ]\n" + //
            "}");

      add(data,
         "start from branch 'SAW_Bld_1' find artifacts where attribute type = 'Name' match-order 'Read-only Robots' collect artifacts as 'Requirement' { id, attributes { value } };", //
         "{\n" + //
            "  'script' : 'start from branch 'SAW_Bld_1' find artifacts where attribute type = 'Name' match-order 'Read-only Robots' collect artifacts as 'Requirement' { id, attributes { value } };',\n" + //
            "  'results' : [ {\n" + //
            "    'Requirement' : [ {\n" + //
            "      'id' : 200077,\n" + //
            "      'attributes' : {\n" + //
            "        'Name' : {\n" + //
            "          'value' : 'Read-only Robots'\n" + //
            "        },\n" + //
            "        'Word Template Content' : {\n" + //
            "          'value' : '<w:p wsp:rsidR=\\'006A3C0C\\' wsp:rsidRDefault=\\'006A3C0C\\' wsp:rsidP=\\'00E54E52\\'><w:r wsp:rsidRPr=\\'00EB2959\\'><w:t>Individual and collaborative robots can be “read-only” (i.e., provide only state information) or “read-write” (i.e., provide state inform</w:t></w:r><w:r><w:t>ation and allow state changes).</w:t></w:r></w:p>'\n" + //
            "        },\n" + //
            "        'Paragraph Number' : {\n" + //
            "          'value' : '1.1.4'\n" + //
            "        },\n" + //
            "        'Partition' : {\n" + //
            "          'value' : 'Unspecified'\n" + //
            "        },\n" + //
            "        'Subsystem' : {\n" + //
            "          'value' : 'Unspecified'\n" + //
            "        },\n" + //
            "        'Qualification Method' : {\n" + //
            "          'value' : 'Unspecified'\n" + //
            "        },\n" + //
            "        'Technical Performance Parameter' : {\n" + //
            "          'value' : 'false'\n" + //
            "        },\n" + //
            "        'CSCI' : {\n" + //
            "          'value' : 'Unspecified'\n" + //
            "        },\n" + //
            "        'Software Control Category' : {\n" + //
            "          'value' : 'Unspecified'\n" + //
            "        },\n" + //
            "        'IDAL' : {\n" + //
            "          'value' : 'Unspecified'\n" + //
            "        }\n" + //
            "      }\n" + //
            "    } ]\n" + //
            "  } ]\n" + //
            "}");
      return data;
   }

   private static void add(List<Object[]> data, Object... args) {
      data.add(args);
   }

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

   private ScriptContext newContext(StringWriter writer) {
      ScriptContext context = new SimpleScriptContext();
      context.setWriter(writer);
      context.setErrorWriter(writer);
      return context;
   }

}

Back to the top