GzipModule extends ModuleBase { @Override public void parse(RandomAccessFile file, RepInfo info) { InputStream stream = new RandomAccessFileInputStream(file); parse(stream, info, 0); } GzipModule(); @Override void resetParams(); @Override void checkSignatures(File file,
            InputStream stream, 
            RepInfo info); @Override void checkSignatures(File file,
            RandomAccessFile raf, 
            RepInfo info); @Override void parse(RandomAccessFile file, RepInfo info); @Override int parse(InputStream stream, RepInfo info, int parseIndex);  }
@Test public void parseThreeFilesGzipFile() throws Exception { File gzipFile = new File(THREE_FILES_GZIP_SAMPLE_FILE); assertTrue( gzipFile.isFile() ); GzipModule gzm = new GzipModule(); RepInfo info = new RepInfo(gzipFile.getAbsolutePath()); gzm.parse(new FileInputStream(gzipFile), info, 0); assertEquals(RepInfo.TRUE, info.getWellFormed()); assertEquals(RepInfo.TRUE, info.getValid()); assertEquals(Arrays.asList(gzm.getName()), info.getSigMatch()); assertEquals(0, info.getMessage().size()); assertEquals(1, info.getProperty().size()); assertNotNull(info.getProperty().get(RECORDS)); assertEquals(3, ((List<Property>)info.getProperty().get(RECORDS).getValue()).size()); }
@Test public void parseInvalidCompressionGzipFile() throws Exception { File gzipFile = new File("src/test/resources/gzip/invalid-compression.gz"); assertTrue( gzipFile.isFile() ); GzipModule gzm = new GzipModule(); RepInfo info = new RepInfo(gzipFile.getAbsolutePath()); gzm.parse(new FileInputStream(gzipFile), info, 0); assertEquals(RepInfo.FALSE, info.getWellFormed()); assertEquals(RepInfo.FALSE, info.getValid()); assertTrue(info.getSigMatch().isEmpty()); assertEquals(1, info.getMessage().size()); Map<String, Integer> messages = extractMessages(info.getMessage()); assertEquals(1, messages.size()); assertEquals(1, messages.get(DiagnosisType.INVALID_EXPECTED.name()).intValue()); }
@Test public void parseInvalidEmptyGzipFile() throws Exception { File gzipFile = new File("src/test/resources/gzip/invalid-empty.gzip"); assertTrue( gzipFile.isFile() ); GzipModule gzm = new GzipModule(); RepInfo info = new RepInfo(gzipFile.getAbsolutePath()); gzm.parse(new FileInputStream(gzipFile), info, 0); assertEquals(RepInfo.FALSE, info.getWellFormed()); assertEquals(RepInfo.FALSE, info.getValid()); assertTrue(info.getSigMatch().isEmpty()); assertEquals(1, info.getMessage().size()); Map<String, Integer> messages = extractMessages(info.getMessage()); assertEquals(1, messages.size()); assertEquals(1, messages.get(DiagnosisType.ERROR_EXPECTED.name()).intValue()); }
@Test public void parseInvalidEntriesGzipFile() throws Exception { File gzipFile = new File("src/test/resources/gzip/invalid-entries.gz"); assertTrue( gzipFile.isFile() ); GzipModule gzm = new GzipModule(); RepInfo info = new RepInfo(gzipFile.getAbsolutePath()); gzm.parse(new FileInputStream(gzipFile), info, 0); assertEquals(RepInfo.FALSE, info.getWellFormed()); assertEquals(RepInfo.FALSE, info.getValid()); assertTrue(info.getSigMatch().isEmpty()); assertEquals(5, info.getMessage().size()); Map<String, Integer> messages = extractMessages(info.getMessage()); assertEquals(3, messages.size()); assertEquals(2, messages.get(DiagnosisType.INVALID_EXPECTED.name()).intValue()); assertEquals(2, messages.get(DiagnosisType.RESERVED.name()).intValue()); assertEquals(1, messages.get(DiagnosisType.UNKNOWN.name()).intValue()); }
@Test public void parseInvalidMagicGzipFile() throws Exception { File gzipFile = new File("src/test/resources/gzip/invalid-magic.gz"); assertTrue( gzipFile.isFile() ); GzipModule gzm = new GzipModule(); RepInfo info = new RepInfo(gzipFile.getAbsolutePath()); gzm.parse(new FileInputStream(gzipFile), info, 0); assertEquals(RepInfo.FALSE, info.getWellFormed()); assertEquals(RepInfo.FALSE, info.getValid()); assertTrue(info.getSigMatch().isEmpty()); assertEquals(1, info.getMessage().size()); Map<String, Integer> messages = extractMessages(info.getMessage()); assertEquals(1, messages.size()); assertEquals(1, messages.get(DiagnosisType.INVALID_EXPECTED.name()).intValue()); }
@Test public void parseInvalidTruncatedGzipFile() throws Exception { File gzipFile = new File("src/test/resources/gzip/invalid-truncated.gz"); assertTrue( gzipFile.isFile() ); GzipModule gzm = new GzipModule(); RepInfo info = new RepInfo(gzipFile.getAbsolutePath()); gzm.parse(new FileInputStream(gzipFile), info, 0); assertEquals(RepInfo.FALSE, info.getWellFormed()); assertEquals(RepInfo.FALSE, info.getValid()); assertTrue(info.getSigMatch().isEmpty()); assertEquals(1, info.getMessage().size()); Map<String, Integer> messages = extractMessages(info.getMessage()); for(Map.Entry<String, Integer> e : messages.entrySet()) { System.out.println(e.getKey() + " : " + e.getValue()); } assertEquals(1, messages.size()); Iterator<String> messageKeyIterator = messages.keySet().iterator(); String errorMessage = messageKeyIterator.next(); assertNotNull(errorMessage); assertTrue(errorMessage + " should contain " + DataFormatException.class.toString(), errorMessage.contains(DataFormatException.class.getCanonicalName())); assertFalse(messageKeyIterator.hasNext()); }
@Test public void parseSampleTextGzipFile() throws Exception { File gzipFile = new File(TXT_GZIP_SAMPLE_FILE); assertTrue( gzipFile.isFile() ); GzipModule gzm = new GzipModule(); RepInfo info = new RepInfo(gzipFile.getAbsolutePath()); gzm.parse(new FileInputStream(gzipFile), info, 0); assertEquals(RepInfo.TRUE, info.getWellFormed()); assertEquals(RepInfo.TRUE, info.getValid()); assertEquals(Arrays.asList(gzm.getName()), info.getSigMatch()); assertEquals(0, info.getMessage().size()); assertEquals(1, info.getProperty().size()); assertNotNull(info.getProperty().get(RECORDS)); assertEquals(PropertyArity.LIST, info.getProperty().get(RECORDS).getArity()); assertEquals(PropertyType.PROPERTY, info.getProperty().get(RECORDS).getType()); assertEquals(1, ((List<Property>)info.getProperty().get(RECORDS).getValue()).size()); }