PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms 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
Possible License(s): Apache-2.0, BSD-3-Clause
  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. */
  37. package org.jhove2.module.format.warc;
  38. import org.jhove2.module.format.Validator.Validity;
  39. import org.junit.Test;
  40. /**
  41. * Tests of WARC Module
  42. * @see org.jhove2.module.warc.WarcModule
  43. * @author nicl
  44. */
  45. public class WarcHeaderVersionTest extends WarcModuleTestBase {
  46. Object[][] cases = new Object[][] {
  47. {Validity.False, "invalid-warcheaderversion-1.warc", new String[][] {
  48. {
  49. "[ERROR/OBJECT] Unknown Magic version number: '0.16'",
  50. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  51. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  52. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  53. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  54. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  55. }
  56. }, new String[] {
  57. }},
  58. {Validity.False, "invalid-warcheaderversion-2.warc", new String[][] {
  59. {
  60. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  61. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  62. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  63. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  64. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  65. }
  66. }, new String[] {
  67. }},
  68. {Validity.False, "invalid-warcheaderversion-3.warc", new String[][] {
  69. {
  70. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  71. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  72. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  73. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  74. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  75. }
  76. }, new String[] {
  77. }},
  78. {Validity.False, "invalid-warcheaderversion-4.warc", new String[][] {
  79. {
  80. "[ERROR/OBJECT] Unknown Magic version number: '0.19'",
  81. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  82. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  83. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  84. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  85. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  86. }
  87. }, new String[] {
  88. }},
  89. {Validity.False, "invalid-warcheaderversion-5.warc", new String[][] {
  90. {
  91. "[ERROR/OBJECT] Unknown Magic version number: '0.99'",
  92. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  93. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  94. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  95. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  96. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  97. }
  98. }, new String[] {
  99. }},
  100. {Validity.False, "invalid-warcheaderversion-6.warc", new String[][] {
  101. {
  102. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  103. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  104. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  105. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  106. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  107. }
  108. }, new String[] {
  109. }},
  110. {Validity.False, "invalid-warcheaderversion-7.warc", new String[][] {
  111. {
  112. "[ERROR/OBJECT] Unknown Magic version number: '1.1'",
  113. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  114. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  115. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  116. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  117. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  118. }
  119. }, new String[] {
  120. }},
  121. {Validity.False, "invalid-warcheaderversion-8.warc", new String[][] {
  122. {
  123. "[ERROR/OBJECT] Unknown Magic version number: '2.0'",
  124. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  125. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  126. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  127. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  128. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  129. }
  130. }, new String[] {
  131. }},
  132. {Validity.False, "invalid-warcheaderversion-9.warc", new String[][] {
  133. {
  134. "[ERROR/OBJECT] Unknown Magic version number: 'x.x'",
  135. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  136. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  137. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  138. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  139. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  140. }
  141. }, new String[] {
  142. }},
  143. {Validity.False, "invalid-warcheaderversion-10.warc", new String[][] {
  144. {
  145. "[ERROR/OBJECT] Invalid Magic Version string, '1.0.0'",
  146. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  147. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  148. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  149. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  150. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  151. }
  152. }, new String[] {
  153. }},
  154. {Validity.False, "invalid-warcheaderversion-11.warc", new String[][] {
  155. {
  156. "[ERROR/OBJECT] Invalid Magic Version string, '1.0.1'",
  157. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  158. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  159. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  160. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  161. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  162. }
  163. }, new String[] {
  164. }},
  165. {Validity.False, "invalid-warcheaderversion-12.warc", new String[][] {
  166. {
  167. "[ERROR/OBJECT] Invalid Magic Version string, '1'",
  168. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  169. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  170. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  171. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  172. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  173. }
  174. }, new String[] {
  175. }},
  176. {Validity.False, "invalid-warcheaderversion-13.warc", new String[][] {
  177. {
  178. "[ERROR/OBJECT] Invalid Magic Version string, '1.2.3.4.5'",
  179. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  180. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  181. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  182. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  183. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  184. }
  185. }, new String[] {
  186. }},
  187. {Validity.False, "invalid-warcheaderversion-14.warc", new String[][] {
  188. {
  189. "[ERROR/OBJECT] Invalid Magic Version string, ''",
  190. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  191. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  192. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  193. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  194. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  195. }
  196. }, new String[] {
  197. }},
  198. {Validity.False, "invalid-warcheaderversion-15.warc", new String[][] {
  199. {
  200. "[ERROR/OBJECT] Invalid Magic Version string, 'WARC'",
  201. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  202. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  203. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  204. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  205. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  206. }
  207. }, new String[] {
  208. }},
  209. {Validity.False, "invalid-warcheaderversion-16.warc", new String[][] {
  210. }, new String[] {
  211. "[ERROR/OBJECT] Invalid Data before WARC version",
  212. "[ERROR/OBJECT] Error in WARC file, expected 'One or more records'"
  213. }},
  214. {Validity.False, "invalid-warcheaderversion-17.warc", new String[][] {
  215. }, new String[] {
  216. "[ERROR/OBJECT] Invalid Data before WARC version",
  217. "[ERROR/OBJECT] Error in WARC file, expected 'One or more records'"
  218. }},
  219. {Validity.False, "invalid-warcheaderversion-18.warc", new String[][] {
  220. }, new String[] {
  221. "[ERROR/OBJECT] Invalid Data before WARC version",
  222. "[ERROR/OBJECT] Error in WARC file, expected 'One or more records'"
  223. }},
  224. {Validity.False, "invalid-warcheaderversion-19.warc", new String[][] {
  225. }, new String[] {
  226. "[ERROR/OBJECT] Invalid Data before WARC version",
  227. "[ERROR/OBJECT] Error in WARC file, expected 'One or more records'"
  228. }},
  229. {Validity.False, "invalid-warcheaderversion-20.warc", new String[][] {
  230. }, new String[] {
  231. "[ERROR/OBJECT] Invalid Empty lines before WARC version",
  232. "[ERROR/OBJECT] Error in WARC file, expected 'One or more records'"
  233. }},
  234. {Validity.False, "invalid-warcheaderversion-21.warc", new String[][] {
  235. {
  236. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  237. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  238. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  239. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  240. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  241. }
  242. }, new String[] {
  243. }},
  244. {Validity.False, "invalid-warcheaderversion-22.warc", new String[][] {
  245. {
  246. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  247. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  248. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  249. "[ERROR/OBJECT] Required and invalid 'WARC-Target-URI' value: value: 'null'",
  250. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  251. }
  252. }, new String[] {
  253. }},
  254. {Validity.False, "invalid-warcheaderversion-23.warc", new String[][] {
  255. {
  256. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  257. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  258. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  259. "[ERROR/OBJECT] Required and invalid 'WARC-Target-URI' value: value: 'null'",
  260. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'",
  261. }
  262. }, new String[] {
  263. }},
  264. {Validity.False, "invalid-warcheaderversion-24.warc", new String[][] {
  265. {
  266. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  267. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  268. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  269. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  270. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'",
  271. "[WARNING/OBJECT] Unknown Header line: 'WARC-Type resource'"
  272. }
  273. }, new String[] {
  274. }},
  275. {Validity.False, "invalid-warcheaderversion-25.warc", new String[][] {
  276. {
  277. "[ERROR/OBJECT] Required and invalid 'WARC-Type' header: value: 'null'",
  278. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  279. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  280. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  281. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'",
  282. "[WARNING/OBJECT] Empty Header line"
  283. }
  284. }, new String[] {
  285. }},
  286. {Validity.False, "invalid-warcheaderversion-26.warc", new String[][] {
  287. {
  288. "[ERROR/OBJECT] Required and invalid 'WARC-Record-ID' header: value: 'null'",
  289. "[ERROR/OBJECT] Required and invalid 'WARC-Date' header: value: 'null'",
  290. "[ERROR/OBJECT] Required and invalid 'Content-Length' header: value: 'null'",
  291. "[ERROR/OBJECT] Required and invalid 'WARC-Target-URI' value: value: 'null'",
  292. "[ERROR/OBJECT] Invalid Trailing newlines, value: '0', expected: '2'"
  293. }
  294. }, new String[] {
  295. }}
  296. };
  297. @Test
  298. public void test_warcheaderversion() {
  299. test_cases(cases, false);
  300. }
  301. }