Permalink
Browse files

- 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...
1 parent bd174ce commit 181b3f1ff0224368030beb5bce67670e3bcfcc06 @khmarbaise khmarbaise committed Apr 19, 2012
View
@@ -1 +1,6 @@
-target
+.classpath
+.project
+nbactions.xml
+/.settings
+/target
+/test-output
View
@@ -127,6 +127,12 @@
<version>4.3</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>6.3.1</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<profiles>
@@ -2,6 +2,8 @@
import org.freecompany.redline.header.Format;
import org.freecompany.redline.payload.CpioHeader;
+
+import java.io.FileInputStream;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
@@ -33,10 +35,11 @@
* reading the RPM file or it's contents
*/
public static void main( String[] args) throws Exception {
- ReadableChannelWrapper in = new ReadableChannelWrapper( Channels.newChannel( System.in));
+ InputStream fios = new FileInputStream ( args[0] );
+ ReadableChannelWrapper in = new ReadableChannelWrapper( Channels.newChannel( fios));
Format format = new Scanner().run( in);
System.out.println( format);
- InputStream uncompressed = new GZIPInputStream( System.in);
+ InputStream uncompressed = new GZIPInputStream( fios );
in = new ReadableChannelWrapper( Channels.newChannel( uncompressed));
CpioHeader header;
int total = 0;
@@ -0,0 +1,14 @@
+package org.freecompany.redline;
+
+import java.io.File;
+
+import org.testng.annotations.Test;
+
+public class ScannerTest extends TestBase
+{
+
+ @Test
+ public void scanTest() throws Exception {
+ Scanner.main ( new String[]{ getTestResourcesDirectory ( ) + File.separator + "rpm-1-1.0-1.noarch.rpm" } );
+ }
+}
@@ -0,0 +1,95 @@
+package org.freecompany.redline;
+
+import java.io.File;
+import java.net.URL;
+
+/**
+ * @author Karl Heinz Marbaise
+ */
+public class TestBase {
+ /**
+ * This method will give you back the filename incl. the absolute path name
+ * to the resource. If the resource does not exist it will give you back the
+ * resource name incl. the path.
+ *
+ * It will give you back an absolute path incl. the name which is in the
+ * same directory as the the class you've called it from.
+ *
+ * @param name
+ * @return
+ */
+ public String getFileResource(String name) {
+ URL url = this.getClass().getResource(name);
+ if (url != null) {
+ return url.getFile();
+ } else {
+ // We have a file which does not exists
+ // We got the path
+ url = this.getClass().getResource(".");
+ return url.getFile() + name;
+ }
+ }
+
+ /**
+ * Return the base directory of the project.
+ *
+ * @return
+ */
+ public String getMavenBaseDir() {
+ // basedir is defined by Maven
+ // but the above will not work under Eclipse.
+ // So there I'M using user.dir
+ return System.getProperty("basedir",
+ System.getProperty("user.dir", "."));
+ }
+
+ /**
+ * Return the target directory of the current project.
+ *
+ * @return
+ */
+ public String getTargetDir() {
+ return getMavenBaseDir() + File.separatorChar + "target";
+ }
+
+ /**
+ * This will give you back the position of a repository which is stored
+ * inside the <b>target</b> directory.
+ *
+ * @return The directory where the repository has been stored.
+ */
+ public String getRepositoryDirectory() {
+ return getTargetDir() + File.separatorChar + "repos";
+ }
+
+ public String getRepositoryDirectory(String supplemental) {
+ return getTargetDir() + File.separatorChar + "repos-" + supplemental;
+ }
+
+ /**
+ * This will give you back the position of an index directory which is
+ * stored inside the <b>target</b> directory.
+ *
+ * @return The directory where the index is stored.
+ */
+ public String getIndexDirectory() {
+ return getTargetDir() + File.separatorChar + "index.Test";
+ }
+
+ public String getIndexDirectory(String supplemental) {
+ return getTargetDir() + File.separatorChar + "index-" + supplemental
+ + ".Test";
+ }
+
+ public String getSrcDirectory() {
+ return getMavenBaseDir() + File.separator + "src";
+ }
+
+ public String getTestDirectory() {
+ return getSrcDirectory() + File.separator + "test";
+ }
+
+ public String getTestResourcesDirectory() {
+ return getTestDirectory() + File.separator + "resources";
+ }
+}
Binary file not shown.

0 comments on commit 181b3f1

Please sign in to comment.