Skip to content
This repository
Browse code

- Added .gitignore file

- Changed the Scanner main to use an argument instead of
  i/o redirection for simpler testing (first small step)
- Added first ScannerTest to use a real RPM example.
  • Loading branch information...
commit 181b3f1ff0224368030beb5bce67670e3bcfcc06 1 parent bd174ce
Karl Heinz Marbaise authored
7 .gitignore
... ... @@ -1 +1,6 @@
1   -target
  1 +.classpath
  2 +.project
  3 +nbactions.xml
  4 +/.settings
  5 +/target
  6 +/test-output
6 pom.xml
@@ -127,6 +127,12 @@
127 127 <version>4.3</version>
128 128 <scope>test</scope>
129 129 </dependency>
  130 + <dependency>
  131 + <groupId>org.testng</groupId>
  132 + <artifactId>testng</artifactId>
  133 + <version>6.3.1</version>
  134 + <scope>test</scope>
  135 + </dependency>
130 136 </dependencies>
131 137
132 138 <profiles>
7 src/main/java/org/freecompany/redline/Scanner.java
@@ -2,6 +2,8 @@
2 2
3 3 import org.freecompany.redline.header.Format;
4 4 import org.freecompany.redline.payload.CpioHeader;
  5 +
  6 +import java.io.FileInputStream;
5 7 import java.io.InputStream;
6 8 import java.nio.ByteBuffer;
7 9 import java.nio.channels.Channels;
@@ -33,10 +35,11 @@
33 35 * reading the RPM file or it's contents
34 36 */
35 37 public static void main( String[] args) throws Exception {
36   - ReadableChannelWrapper in = new ReadableChannelWrapper( Channels.newChannel( System.in));
  38 + InputStream fios = new FileInputStream ( args[0] );
  39 + ReadableChannelWrapper in = new ReadableChannelWrapper( Channels.newChannel( fios));
37 40 Format format = new Scanner().run( in);
38 41 System.out.println( format);
39   - InputStream uncompressed = new GZIPInputStream( System.in);
  42 + InputStream uncompressed = new GZIPInputStream( fios );
40 43 in = new ReadableChannelWrapper( Channels.newChannel( uncompressed));
41 44 CpioHeader header;
42 45 int total = 0;
14 src/test/java/org/freecompany/redline/ScannerTest.java
... ... @@ -0,0 +1,14 @@
  1 +package org.freecompany.redline;
  2 +
  3 +import java.io.File;
  4 +
  5 +import org.testng.annotations.Test;
  6 +
  7 +public class ScannerTest extends TestBase
  8 +{
  9 +
  10 + @Test
  11 + public void scanTest() throws Exception {
  12 + Scanner.main ( new String[]{ getTestResourcesDirectory ( ) + File.separator + "rpm-1-1.0-1.noarch.rpm" } );
  13 + }
  14 +}
95 src/test/java/org/freecompany/redline/TestBase.java
... ... @@ -0,0 +1,95 @@
  1 +package org.freecompany.redline;
  2 +
  3 +import java.io.File;
  4 +import java.net.URL;
  5 +
  6 +/**
  7 + * @author Karl Heinz Marbaise
  8 + */
  9 +public class TestBase {
  10 + /**
  11 + * This method will give you back the filename incl. the absolute path name
  12 + * to the resource. If the resource does not exist it will give you back the
  13 + * resource name incl. the path.
  14 + *
  15 + * It will give you back an absolute path incl. the name which is in the
  16 + * same directory as the the class you've called it from.
  17 + *
  18 + * @param name
  19 + * @return
  20 + */
  21 + public String getFileResource(String name) {
  22 + URL url = this.getClass().getResource(name);
  23 + if (url != null) {
  24 + return url.getFile();
  25 + } else {
  26 + // We have a file which does not exists
  27 + // We got the path
  28 + url = this.getClass().getResource(".");
  29 + return url.getFile() + name;
  30 + }
  31 + }
  32 +
  33 + /**
  34 + * Return the base directory of the project.
  35 + *
  36 + * @return
  37 + */
  38 + public String getMavenBaseDir() {
  39 + // basedir is defined by Maven
  40 + // but the above will not work under Eclipse.
  41 + // So there I'M using user.dir
  42 + return System.getProperty("basedir",
  43 + System.getProperty("user.dir", "."));
  44 + }
  45 +
  46 + /**
  47 + * Return the target directory of the current project.
  48 + *
  49 + * @return
  50 + */
  51 + public String getTargetDir() {
  52 + return getMavenBaseDir() + File.separatorChar + "target";
  53 + }
  54 +
  55 + /**
  56 + * This will give you back the position of a repository which is stored
  57 + * inside the <b>target</b> directory.
  58 + *
  59 + * @return The directory where the repository has been stored.
  60 + */
  61 + public String getRepositoryDirectory() {
  62 + return getTargetDir() + File.separatorChar + "repos";
  63 + }
  64 +
  65 + public String getRepositoryDirectory(String supplemental) {
  66 + return getTargetDir() + File.separatorChar + "repos-" + supplemental;
  67 + }
  68 +
  69 + /**
  70 + * This will give you back the position of an index directory which is
  71 + * stored inside the <b>target</b> directory.
  72 + *
  73 + * @return The directory where the index is stored.
  74 + */
  75 + public String getIndexDirectory() {
  76 + return getTargetDir() + File.separatorChar + "index.Test";
  77 + }
  78 +
  79 + public String getIndexDirectory(String supplemental) {
  80 + return getTargetDir() + File.separatorChar + "index-" + supplemental
  81 + + ".Test";
  82 + }
  83 +
  84 + public String getSrcDirectory() {
  85 + return getMavenBaseDir() + File.separator + "src";
  86 + }
  87 +
  88 + public String getTestDirectory() {
  89 + return getSrcDirectory() + File.separator + "test";
  90 + }
  91 +
  92 + public String getTestResourcesDirectory() {
  93 + return getTestDirectory() + File.separator + "resources";
  94 + }
  95 +}
BIN  src/test/resources/rpm-1-1.0-1.noarch.rpm
Binary file not shown

0 comments on commit 181b3f1

Please sign in to comment.
Something went wrong with that request. Please try again.