-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.spec.js
More file actions
326 lines (315 loc) · 16.5 KB
/
Copy pathindex.spec.js
File metadata and controls
326 lines (315 loc) · 16.5 KB
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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
import { StackPackage, StackLine, StackGroup, Stack } from './index';
import { expect } from 'chai';
describe('StackPackage', ()=> {
describe('throws error if', ()=> {
it('name is undefined', ()=> {
expect(()=> {
new StackPackage();
}).to.throw(Error);
});
it('name is null', ()=> {
expect(()=> {
new StackPackage(null);
}).to.throw(Error);
});
it('name is empty', ()=> {
expect(()=> {
new StackPackage(null);
}).to.throw(Error);
});
it('aliases is null', ()=> {
expect(()=> {
new StackPackage('test', null);
}).to.throw(Error);
});
it('aliases if not an array', ()=> {
expect(()=> {
new StackPackage('test', {});
}).to.throw(Error);
});
});
it('adds startsWith to String.prototype', ()=> {
// ES6 has the method, ES5 does not
if (String.prototype.startsWith) {
String.prototype.startsWith = undefined;
}
expect(String.prototype.startsWith).to.be.undefined;
new StackPackage('test');
expect(String.prototype.startsWith).to.exist;
});
describe('.equals()', ()=> {
describe('returns false if', ()=> {
it('package is undefined', ()=> {
let package1 = new StackPackage('test', ['foo', 'bar']);
expect(package1.equals()).to.be.false;
});
it('package is null', ()=> {
let package1 = new StackPackage('test', ['foo', 'bar']);
expect(package1.equals(null)).to.be.false;
});
it('name is not one of the alias', ()=> {
let package1 = new StackPackage('test', ['hello', 'world']);
let package2 = new StackPackage('foo', ['hello', 'world']);
expect(package1.equals(package2)).to.be.false;
});
it('name is not one of the alias', ()=> {
let package1 = new StackPackage('test', ['bar.foo', 'world']);
let package2 = new StackPackage('foo', ['hello', 'world']);
expect(package1.equals(package2)).to.be.false;
});
});
describe('returns true if', ()=> {
it('both names are the same', ()=> {
let package1 = new StackPackage('test', ['foo', 'bar']);
let package2 = new StackPackage('test', ['hello', 'world']);
expect(package1.equals(package2)).to.be.true;
expect(package2.equals(package1)).to.be.true;
});
it('name is one of the aliases', ()=> {
let package1 = new StackPackage('test', ['foo', 'bar']);
let package2 = new StackPackage('foo', ['hello', 'world']);
expect(package1.equals(package2)).to.be.true;
expect(package2.equals(package1)).to.be.false;
});
it('name is starts with of the aliases', ()=> {
let package1 = new StackPackage('test', ['foo', 'bar']);
let package2 = new StackPackage('foo.bar', ['hello', 'world']);
expect(package1.equals(package2)).to.be.true;
expect(package2.equals(package1)).to.be.false;
});
});
});
});
describe('StackLine', ()=> {
describe('throws error if', ()=> {
it('stack package is undefined', ()=> {
expect(()=> {
new StackLine();
}).to.throw(Error);
});
it('stack package is null', ()=> {
expect(()=> {
new StackLine(null)
}).to.throw(Error);
});
it('stack package is not of type StackPackage', ()=> {
expect(()=> {
new StackPackage({})
}).to.throw(Error);
});
});
it('sets default for class, method, source and line number', ()=> {
let stackPackage = new StackPackage('test');
let stackLine = new StackLine(stackPackage);
expect(stackLine.stackPackage).to.equal(stackPackage);
expect(stackLine.javaClass).to.equal('Unknown');
expect(stackLine.method).to.equal('Unknown');
expect(stackLine.source).to.equal('Unknown');
expect(stackLine.line).to.equal(-1);
});
});
describe('StackGroup', ()=> {
describe('throws error if', ()=> {
it('stack package is undefined', ()=> {
expect(()=> {
new StackGroup();
}).to.throw(Error);
});
it('stack package is null', ()=> {
expect(()=> {
new StackGroup(null)
}).to.throw(Error);
});
it('stack package is not of type StackPackage', ()=> {
expect(()=> {
new StackGroup({})
}).to.throw(Error);
});
});
describe('adds lines', ()=> {
let stackPackage;
let stackGroup;
beforeEach(()=> {
stackPackage = new StackPackage('test');
stackGroup = new StackGroup(stackPackage);
});
it('as expected', ()=> {
let numLines = 10;
for (let i = 0; i < numLines; i++) {
stackGroup.addLine(new StackLine(stackPackage));
}
expect(stackGroup.lines.length).to.equal(numLines);
});
it('only if typeof StackLine', ()=> {
stackGroup.addLine({});
expect(stackGroup.lines.length).to.equal(0);
});
});
describe('adds exception', ()=> {
let stackPackage;
let stackGroup;
beforeEach(()=> {
stackPackage = new StackPackage('test');
stackGroup = new StackGroup(stackPackage);
stackGroup.addException('my.exception', 'This is an error message');
});
it('as expected', ()=> {
expect(stackGroup.exception).to.exist;
expect(stackGroup.exception.exception).to.equal('my.exception');
expect(stackGroup.exception.message).to.equal('This is an error message');
});
it('and overrides the previously defined', ()=> {
stackGroup.addException('my.new.exception', 'This is a new error message');
expect(stackGroup.exception).to.exist;
expect(stackGroup.exception.exception).to.equal('my.new.exception');
expect(stackGroup.exception.message).to.equal('This is a new error message');
});
});
});
describe('Stack', ()=> {
it('has no vendor packages by default', ()=> {
let stack = new Stack();
expect(stack.vendorPackages.length).to.equal(0);
});
it('can add vendor packages', ()=> {
let opts = {
'aaa': ['foo', 'bar'],
'bbb': ['hello', 'world']
};
let stack = new Stack(opts);
expect(stack.vendorPackages.length).to.equal(Object.keys(opts).length);
stack.vendorPackages.forEach((vendorPackage, index)=> {
expect(Object.keys(opts).indexOf(vendorPackage.name)).to.equal(index);
expect(vendorPackage.aliases).to.equal(opts[vendorPackage.name]);
})
});
describe('can parse', ()=> {
let stackTrace = [
'java.net.SocketException: Connection reset',
'at java.net.SocketInputStream.read(SocketInputStream.java:185)',
'at sun.security.ssl.InputRecord.readFully(InputRecord.java:312)',
'at sun.security.ssl.InputRecord.read(InputRecord.java:350)',
'at org.apache.http.impl.io.AbstractSessionInputBuffer.fillBuffer(AbstractSessionInputBuffer.java:166)',
'at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:92)',
'at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:300)',
'at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:127)',
'at com.sparktale.bugtale.server.common.aws.S3Manager.doPutObject(S3Manager.java:247)',
'at com.sparktale.bugtale.server.common.aws.S3Manager.putBytes(S3Manager.java:134)',
'at com.sparktale.bugtale.server.common.util.S3IOInterface.putBytes(S3IOInterface.java:84)',
'at com.sparktale.bugtale.server.common.util.IOUtil.putBytes(IOUtil.java:126)',
'Caused by: org.hibernate.exception.ConstraintViolationException: could not insert: [com.example.myproject.MyEntity]',
'at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:96)',
'at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:64)',
'at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2329)',
'at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2822)',
'at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)',
'at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)',
'at $Proxy19.save(Unknown Source)',
'at com.example.myproject.MyEntityService.save(MyEntityService.java:59) <-- relevant call (see notes below)',
'at com.example.myproject.MyServlet.doPost(MyServlet.java:164)',
'... 32 more',
'Caused by: java.sql.SQLException: Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]',
'at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)',
'at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)',
'at java.lang.Thread.run(Thread.java:679)'
].join('\r\n');
it('without vendor packages', ()=> {
let stack = new Stack();
stack.parse(stackTrace);
expect(stack.groups.length).to.equal(15);
expect(stack.groups[0].exception).to.exist;
expect(stack.groups[0].exception.exception).to.equal('java.net.SocketException');
expect(stack.groups[0].exception.message).to.equal('Connection reset');
expect(stack.groups[0].stackPackage.name).to.equal('java.net');
expect(stack.groups[0].lines.length).to.equal(1);
expect(stack.groups[1].exception).to.not.exist;
expect(stack.groups[1].stackPackage.name).to.equal('sun.security.ssl');
expect(stack.groups[1].lines.length).to.equal(2);
expect(stack.groups[2].exception).to.not.exist;
expect(stack.groups[2].stackPackage.name).to.equal('org.apache.http.impl.io');
expect(stack.groups[2].lines.length).to.equal(1);
expect(stack.groups[3].exception).to.not.exist;
expect(stack.groups[3].stackPackage.name).to.equal('org.apache.http.impl.conn');
expect(stack.groups[3].lines.length).to.equal(1);
expect(stack.groups[4].exception).to.not.exist;
expect(stack.groups[4].stackPackage.name).to.equal('org.apache.http.protocol');
expect(stack.groups[4].lines.length).to.equal(2);
expect(stack.groups[5].exception).to.not.exist;
expect(stack.groups[5].stackPackage.name).to.equal('com.sparktale.bugtale.server.common.aws');
expect(stack.groups[5].lines.length).to.equal(2);
expect(stack.groups[6].exception).to.not.exist;
expect(stack.groups[6].stackPackage.name).to.equal('com.sparktale.bugtale.server.common.util');
expect(stack.groups[6].lines.length).to.equal(2);
expect(stack.groups[7].exception).to.exist;
expect(stack.groups[7].exception.exception).to.equal('org.hibernate.exception.ConstraintViolationException');
expect(stack.groups[7].exception.message).to.equal('could not insert: [com.example.myproject.MyEntity]');
expect(stack.groups[7].stackPackage.name).to.equal('org.hibernate.exception');
expect(stack.groups[7].lines.length).to.equal(1);
expect(stack.groups[8].exception).to.not.exist;
expect(stack.groups[8].stackPackage.name).to.equal('org.hibernate.id.insert');
expect(stack.groups[8].lines.length).to.equal(1);
expect(stack.groups[9].exception).to.not.exist;
expect(stack.groups[9].stackPackage.name).to.equal('org.hibernate.persister.entity');
expect(stack.groups[9].lines.length).to.equal(2);
expect(stack.groups[10].exception).to.not.exist;
expect(stack.groups[10].stackPackage.name).to.equal('sun.reflect');
expect(stack.groups[10].lines.length).to.equal(2);
expect(stack.groups[11].exception).to.not.exist;
expect(stack.groups[11].stackPackage.name).to.equal('Unknown');
expect(stack.groups[11].lines.length).to.equal(1);
expect(stack.groups[12].exception).to.not.exist;
expect(stack.groups[12].stackPackage.name).to.equal('com.example.myproject');
expect(stack.groups[12].lines.length).to.equal(2);
expect(stack.groups[13].exception).to.exist;
expect(stack.groups[13].exception.exception).to.equal('java.sql.SQLException');
expect(stack.groups[13].exception.message).to.equal('Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]');
expect(stack.groups[13].stackPackage.name).to.equal('java.util.concurrent');
expect(stack.groups[13].lines.length).to.equal(2);
expect(stack.groups[14].exception).to.not.exist;
expect(stack.groups[14].stackPackage.name).to.equal('java.lang');
expect(stack.groups[14].lines.length).to.equal(1);
});
it('with vendor packages', ()=> {
let stack = new Stack({
'Java/Sun/Oracle': ['java', 'javax', 'sun', 'sunw', 'com.sun', 'com.oracle'],
'Apache': ['org.apache'],
'Hibernate': ['org.hibernate']
});
stack.parse(stackTrace);
expect(stack.groups.length).to.equal(9);
expect(stack.groups[0].exception).to.exist;
expect(stack.groups[0].exception.exception).to.equal('java.net.SocketException');
expect(stack.groups[0].exception.message).to.equal('Connection reset');
expect(stack.groups[0].stackPackage.name).to.equal('Java/Sun/Oracle');
expect(stack.groups[0].lines.length).to.equal(3);
expect(stack.groups[1].exception).to.not.exist;
expect(stack.groups[1].stackPackage.name).to.equal('Apache');
expect(stack.groups[1].lines.length).to.equal(4);
expect(stack.groups[2].exception).to.not.exist;
expect(stack.groups[2].stackPackage.name).to.equal('com.sparktale.bugtale.server.common.aws');
expect(stack.groups[2].lines.length).to.equal(2);
expect(stack.groups[3].exception).to.not.exist;
expect(stack.groups[3].stackPackage.name).to.equal('com.sparktale.bugtale.server.common.util');
expect(stack.groups[3].lines.length).to.equal(2);
expect(stack.groups[4].exception).to.exist;
expect(stack.groups[4].exception.exception).to.equal('org.hibernate.exception.ConstraintViolationException');
expect(stack.groups[4].exception.message).to.equal('could not insert: [com.example.myproject.MyEntity]');
expect(stack.groups[4].stackPackage.name).to.equal('Hibernate');
expect(stack.groups[4].lines.length).to.equal(4);
expect(stack.groups[5].exception).to.not.exist;
expect(stack.groups[5].stackPackage.name).to.equal('Java/Sun/Oracle');
expect(stack.groups[5].lines.length).to.equal(2);
expect(stack.groups[6].exception).to.not.exist;
expect(stack.groups[6].stackPackage.name).to.equal('Unknown');
expect(stack.groups[6].lines.length).to.equal(1);
expect(stack.groups[7].exception).to.not.exist;
expect(stack.groups[7].stackPackage.name).to.equal('com.example.myproject');
expect(stack.groups[7].lines.length).to.equal(2);
expect(stack.groups[8].exception).to.exist;
expect(stack.groups[8].exception.exception).to.equal('java.sql.SQLException');
expect(stack.groups[8].exception.message).to.equal('Violation of unique constraint MY_ENTITY_UK_1: duplicate value(s) for column(s) MY_COLUMN in statement [...]');
expect(stack.groups[8].stackPackage.name).to.equal('Java/Sun/Oracle');
expect(stack.groups[8].lines.length).to.equal(3);
});
});
});