PageRenderTime 48ms CodeModel.GetById 2ms app.highlight 41ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/java/org/jhove2/module/format/warc/WarcHeaderVersionTest.java

https://bitbucket.org/moabrichard/jhove2
Java | 306 lines | 260 code | 5 blank | 41 comment | 0 complexity | 9fc5992d11dc9dd4b0b95c507cc61c63 MD5 | raw file
  1/**
  2 * JHOVE2 - Next-generation architecture for format-aware characterization
  3 * <p>
  4 * Copyright (c) 2009 by The Regents of the University of California, Ithaka
  5 * Harbors, Inc., and The Board of Trustees of the Leland Stanford Junior
  6 * University. All rights reserved.
  7 * </p>
  8 * <p>
  9 * Redistribution and use in source and binary forms, with or without
 10 * modification, are permitted provided that the following conditions are met:
 11 * </p>
 12 * <ul>
 13 * <li>Redistributions of source code must retain the above copyright notice,
 14 * this list of conditions and the following disclaimer.</li>
 15 * <li>Redistributions in binary form must reproduce the above copyright notice,
 16 * this list of conditions and the following disclaimer in the documentation
 17 * and/or other materials provided with the distribution.</li>
 18 * <li>Neither the name of the University of California/California Digital
 19 * Library, Ithaka Harbors/Portico, or Stanford University, nor the names of its
 20 * contributors may be used to endorse or promote products derived from this
 21 * software without specific prior written permission.</li>
 22 * </ul>
 23 * <p>
 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 34 * POSSIBILITY OF SUCH DAMAGE.
 35 * </p>
 36 */
 37package org.jhove2.module.format.warc;
 38
 39import org.jhove2.module.format.Validator.Validity;
 40import org.junit.Test;
 41
 42/**
 43 * Tests of WARC Module
 44 * @see org.jhove2.module.warc.WarcModule
 45 * @author nicl
 46 */
 47public class WarcHeaderVersionTest extends WarcModuleTestBase {
 48
 49	Object[][] cases = new Object[][] {
 50			{Validity.False, "invalid-warcheaderversion-1.warc", new String[][] {
 51					{
 52						"[ERROR/OBJECT] Unknown Magic version number: '0.16'",
 53						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
 54						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
 55						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
 56						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
 57						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
 58					}
 59			}, new String[] {
 60			}},
 61			{Validity.False, "invalid-warcheaderversion-2.warc", new String[][] {
 62					{
 63						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
 64						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
 65						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
 66						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
 67						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
 68					}
 69			}, new String[] {
 70			}},
 71			{Validity.False, "invalid-warcheaderversion-3.warc", new String[][] {
 72					{
 73						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
 74						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
 75						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
 76						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
 77						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
 78					}
 79			}, new String[] {
 80			}},
 81			{Validity.False, "invalid-warcheaderversion-4.warc", new String[][] {
 82					{
 83						"[ERROR/OBJECT] Unknown Magic version number: '0.19'",
 84						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
 85						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
 86						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
 87						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
 88						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
 89					}
 90			}, new String[] {
 91			}},
 92			{Validity.False, "invalid-warcheaderversion-5.warc", new String[][] {
 93					{
 94						"[ERROR/OBJECT] Unknown Magic version number: '0.99'",
 95						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
 96						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
 97						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
 98						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
 99						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
100					}
101			}, new String[] {
102			}},
103			{Validity.False, "invalid-warcheaderversion-6.warc", new String[][] {
104					{
105						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
106						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
107						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
108						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
109						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
110					}
111			}, new String[] {
112			}},
113			{Validity.False, "invalid-warcheaderversion-7.warc", new String[][] {
114					{
115						"[ERROR/OBJECT] Unknown Magic version number: '1.1'",
116						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
117						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
118						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
119						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
120						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
121					}
122			}, new String[] {
123			}},
124			{Validity.False, "invalid-warcheaderversion-8.warc", new String[][] {
125					{
126						"[ERROR/OBJECT] Unknown Magic version number: '2.0'",
127						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
128						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
129						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
130						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
131						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
132					}
133			}, new String[] {
134			}},
135			{Validity.False, "invalid-warcheaderversion-9.warc", new String[][] {
136					{
137						"[ERROR/OBJECT] Unknown Magic version number: 'x.x'",
138						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
139						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
140						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
141						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
142						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
143					}
144			}, new String[] {
145			}},
146			{Validity.False, "invalid-warcheaderversion-10.warc", new String[][] {
147					{
148						"[ERROR/OBJECT] Invalid Magic Version string, '1.0.0'",
149						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
150						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
151						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
152						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
153						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
154					}
155			}, new String[] {
156			}},
157			{Validity.False, "invalid-warcheaderversion-11.warc", new String[][] {
158					{
159						"[ERROR/OBJECT] Invalid Magic Version string, '1.0.1'",
160						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
161						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
162						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
163						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
164						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
165					}
166			}, new String[] {
167			}},
168			{Validity.False, "invalid-warcheaderversion-12.warc", new String[][] {
169					{
170						"[ERROR/OBJECT] Invalid Magic Version string, '1'",
171						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
172						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
173						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
174						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
175						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
176					}
177			}, new String[] {
178			}},
179			{Validity.False, "invalid-warcheaderversion-13.warc", new String[][] {
180					{
181						"[ERROR/OBJECT] Invalid Magic Version string, '1.2.3.4.5'",
182						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
183						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
184						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
185						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
186						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
187					}
188			}, new String[] {
189			}},
190			{Validity.False, "invalid-warcheaderversion-14.warc", new String[][] {
191					{
192						"[ERROR/OBJECT] Invalid Magic Version string, ''",
193						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
194						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
195						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
196						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
197						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
198					}
199			}, new String[] {
200			}},
201			{Validity.False, "invalid-warcheaderversion-15.warc", new String[][] {
202					{
203						"[ERROR/OBJECT] Invalid Magic Version string, 'WARC'",
204						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
205						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
206						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
207						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
208						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
209					}
210			}, new String[] {
211			}},
212			{Validity.False, "invalid-warcheaderversion-16.warc", new String[][] {
213			}, new String[] {
214					"[ERROR/OBJECT] Invalid Data before WARC version",
215					"[ERROR/OBJECT] Error in WARC file, expected 'One or more records'"
216			}},
217			{Validity.False, "invalid-warcheaderversion-17.warc", new String[][] {
218			}, new String[] {
219					"[ERROR/OBJECT] Invalid Data before WARC version",
220					"[ERROR/OBJECT] Error in WARC file, expected 'One or more records'"
221			}},
222			{Validity.False, "invalid-warcheaderversion-18.warc", new String[][] {
223			}, new String[] {
224					"[ERROR/OBJECT] Invalid Data before WARC version",
225					"[ERROR/OBJECT] Error in WARC file, expected 'One or more records'"
226			}},
227			{Validity.False, "invalid-warcheaderversion-19.warc", new String[][] {
228			}, new String[] {
229					"[ERROR/OBJECT] Invalid Data before WARC version",
230					"[ERROR/OBJECT] Error in WARC file, expected 'One or more records'"
231			}},
232			{Validity.False, "invalid-warcheaderversion-20.warc", new String[][] {
233			}, new String[] {
234					"[ERROR/OBJECT] Invalid Empty lines before WARC version",
235					"[ERROR/OBJECT] Error in WARC file, expected 'One or more records'"
236			}},
237			{Validity.False, "invalid-warcheaderversion-21.warc", new String[][] {
238					{
239						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
240						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
241						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
242						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
243						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
244					}
245			}, new String[] {
246			}},
247			{Validity.False, "invalid-warcheaderversion-22.warc", new String[][] {
248					{
249						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
250						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
251						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
252						"[ERROR/OBJECT] Required and invalid 'WARC-Target-URI' value: value: 'null'",
253						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
254					}
255			}, new String[] {
256			}},
257			{Validity.False, "invalid-warcheaderversion-23.warc", new String[][] {
258					{
259						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
260						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
261						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
262						"[ERROR/OBJECT] Required and invalid 'WARC-Target-URI' value: value: 'null'",
263						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'",
264					}
265			}, new String[] {
266			}},
267			{Validity.False, "invalid-warcheaderversion-24.warc", new String[][] {
268					{
269						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
270						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
271						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
272						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
273						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'",
274						"[WARNING/OBJECT] Unknown Header line: 'WARC-Type resource'"
275					}
276			}, new String[] {
277			}},
278			{Validity.False, "invalid-warcheaderversion-25.warc", new String[][] {
279					{
280						"[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
281						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
282						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
283						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
284						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'",
285						"[WARNING/OBJECT] Empty Header line"
286					}
287			}, new String[] {
288			}},
289			{Validity.False, "invalid-warcheaderversion-26.warc", new String[][] {
290					{
291						"[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
292						"[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
293						"[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
294						"[ERROR/OBJECT] Required and invalid 'WARC-Target-URI' value: value: 'null'",
295						"[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
296					}
297			}, new String[] {
298			}}
299	};
300
301	@Test
302	public void test_warcheaderversion() {
303    	test_cases(cases, false);
304	}
305
306}