Skip to content

Commit f5b2757

Browse files
committed
removed junit dependency and refactored for proper testing
1 parent b33bcea commit f5b2757

File tree

17 files changed

+453
-399
lines changed

17 files changed

+453
-399
lines changed

pom.xml

+60-21
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,26 @@
88
<name>Oomph Task - Unzip - Parent</name>
99
<packaging>pom</packaging>
1010

11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
14+
<!-- Eclipse version to build against -->
15+
<eclipse-repo.url>http://download.eclipse.org/releases/mars</eclipse-repo.url>
16+
17+
<!-- Tycho Build parameters -->
18+
<tycho.version>2.2.0</tycho.version>
19+
<tycho-extras.version>2.2.0</tycho-extras.version>
20+
<tycho-repo.url>https://oss.sonatype.org/content/groups/public/</tycho-repo.url>
21+
</properties>
22+
23+
<modules>
24+
<module>task-unzip</module>
25+
<module>task-unzip-test</module>
26+
<module>task-unzip.edit</module>
27+
<module>task-unzip-feature</module>
28+
<module>task-unzip-updatesite</module>
29+
</modules>
30+
1131
<developers>
1232
<developer>
1333
<name>Malte Brunnlieb</name>
@@ -35,31 +55,12 @@
3555

3656
<licenses>
3757
<license>
38-
<name>Eclipse Public Licence - v 1.0</name>
39-
<url>https://www.eclipse.org/legal/epl-v10.html</url>
58+
<name>Eclipse Public Licence - v 2.0</name>
59+
<url>https://www.eclipse.org/legal/epl-v20.html</url>
4060
<distribution>repo</distribution>
4161
</license>
4262
</licenses>
4363

44-
<properties>
45-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
46-
47-
<!-- Eclipse version to build against -->
48-
<eclipse-repo.url>http://download.eclipse.org/releases/mars</eclipse-repo.url>
49-
50-
<!-- Tycho Build parameters -->
51-
<tycho.version>0.22.0</tycho.version>
52-
<tycho-extras.version>0.22.0</tycho-extras.version>
53-
<tycho-repo.url>https://oss.sonatype.org/content/groups/public/</tycho-repo.url>
54-
</properties>
55-
56-
<modules>
57-
<module>task-unzip</module>
58-
<module>task-unzip.edit</module>
59-
<module>task-unzip-feature</module>
60-
<module>task-unzip-updatesite</module>
61-
</modules>
62-
6364
<build>
6465
<plugins>
6566
<plugin>
@@ -77,6 +78,39 @@
7778
<version>${tycho.version}</version>
7879
<extensions>true</extensions>
7980
</plugin>
81+
<plugin>
82+
<groupId>org.eclipse.tycho</groupId>
83+
<artifactId>target-platform-configuration</artifactId>
84+
<configuration>
85+
<environments>
86+
<environment>
87+
<os>linux</os>
88+
<ws>gtk</ws>
89+
<arch>x86</arch>
90+
</environment>
91+
<environment>
92+
<os>linux</os>
93+
<ws>gtk</ws>
94+
<arch>x86_64</arch>
95+
</environment>
96+
<environment>
97+
<os>win32</os>
98+
<ws>win32</ws>
99+
<arch>x86</arch>
100+
</environment>
101+
<environment>
102+
<os>win32</os>
103+
<ws>win32</ws>
104+
<arch>x86_64</arch>
105+
</environment>
106+
<environment>
107+
<os>macosx</os>
108+
<ws>cocoa</ws>
109+
<arch>x86_64</arch>
110+
</environment>
111+
</environments>
112+
</configuration>
113+
</plugin>
80114
</plugins>
81115
<pluginManagement>
82116
<plugins>
@@ -129,6 +163,11 @@
129163
<layout>p2</layout>
130164
<url>${eclipse-repo.url}</url>
131165
</repository>
166+
<repository>
167+
<id>orbit</id>
168+
<layout>p2</layout>
169+
<url>http://download.eclipse.org/tools/orbit/downloads/drops/R20150519210750/repository/</url>
170+
</repository>
132171
</repositories>
133172
<pluginRepositories>
134173
<pluginRepository>

task-unzip-test/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

task-unzip-test/META-INF/MANIFEST.MF

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Manifest-Version: 1.0
2+
Bundle-ManifestVersion: 2
3+
Bundle-Name: Unzip Test
4+
Bundle-Vendor: maybeec
5+
Bundle-SymbolicName: com.github.maybeec.oomph.task.unzip.test;singleton:=true
6+
Bundle-Version: 1.0.0.qualifier
7+
Bundle-ClassPath: .
8+
Bundle-ActivationPolicy: lazy
9+
Bundle-Localization: plugin
10+
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
11+
Require-Bundle: org.junit;bundle-version="4.12.0",
12+
com.github.maybeec.oomph.task.unzip;bundle-version="1.0.0"

task-unzip-test/build.properties

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
bin.includes = .,\
2+
META-INF/,\
3+
plugin.xml,
4+
jars.compile.order = .
5+
source.. = src/main/java
6+
output.. = bin/

task-unzip-test/plugin.xml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<?eclipse version="3.4"?>
3+
<plugin>
4+
5+
</plugin>

task-unzip-test/pom.xml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<name>Oomph Task - Unzip - Test</name>
5+
<artifactId>com.github.maybeec.oomph.task.unzip.test</artifactId>
6+
<packaging>eclipse-test-plugin</packaging>
7+
8+
<parent>
9+
<groupId>com.github.maybeec.oomph</groupId>
10+
<artifactId>task-unzip-parent</artifactId>
11+
<version>1.0.0-SNAPSHOT</version>
12+
</parent>
13+
14+
<properties>
15+
<tycho.testArgLine>-Xms512m -Xmx2048m -XX:+DisableExplicitGC</tycho.testArgLine>
16+
</properties>
17+
18+
<build>
19+
<plugins>
20+
<plugin>
21+
<groupId>org.eclipse.tycho</groupId>
22+
<artifactId>target-platform-configuration</artifactId>
23+
<configuration>
24+
<environments>
25+
<environment>
26+
<os>linux</os>
27+
<ws>gtk</ws>
28+
<arch>x86</arch>
29+
</environment>
30+
<environment>
31+
<os>linux</os>
32+
<ws>gtk</ws>
33+
<arch>x86_64</arch>
34+
</environment>
35+
<environment>
36+
<os>win32</os>
37+
<ws>win32</ws>
38+
<arch>x86</arch>
39+
</environment>
40+
<environment>
41+
<os>win32</os>
42+
<ws>win32</ws>
43+
<arch>x86_64</arch>
44+
</environment>
45+
<environment>
46+
<os>macosx</os>
47+
<ws>cocoa</ws>
48+
<arch>x86_64</arch>
49+
</environment>
50+
</environments>
51+
<dependency-resolution>
52+
<extraRequirements>
53+
<requirement>
54+
<type>p2-installable-unit</type>
55+
<id>com.github.maybeec.oomph.task.unzip</id>
56+
<versionRange>0.0.0</versionRange>
57+
</requirement>
58+
<requirement>
59+
<type>p2-installable-unit</type>
60+
<id>org.eclipse.oomph.setup.feature.group</id>
61+
<versionRange>0.0.0</versionRange>
62+
</requirement>
63+
</extraRequirements>
64+
</dependency-resolution>
65+
</configuration>
66+
</plugin>
67+
</plugins>
68+
</build>
69+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
package com.github.maybeec.oomph.task.unzip.core.impl;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import java.io.File;
6+
7+
import org.junit.AfterClass;
8+
import org.junit.Before;
9+
import org.junit.Test;
10+
11+
import com.github.maybeec.oomph.task.unzip.core.UnzipUtil;
12+
import com.github.maybeec.oomph.task.unzip.core.exceptions.UnzipTaskException;
13+
14+
/**
15+
*
16+
* @author sholzer (14.10.2016)
17+
*/
18+
public class UnzipUtilTest {
19+
20+
public static String resourceFolder = "src/main/resources/";
21+
22+
public static String destination = resourceFolder + "dest";
23+
24+
public static File dest = new File(destination);
25+
26+
private UnzipUtil util;
27+
28+
@Before
29+
public void before() {
30+
util = new UnzipUtilImpl();
31+
}
32+
33+
@Test
34+
public void testZip() throws UnzipTaskException {
35+
String zipFileName = resourceFolder + "zipfile.zip";
36+
util.unzip(zipFileName, destination);
37+
File[] files = dest.listFiles();
38+
boolean zippedExtracted = false;
39+
boolean zippedCopyExtracted = false;
40+
for (File f : files) {
41+
if (f.getName().equals("zipped.txt")) {
42+
zippedExtracted = true;
43+
}
44+
if (f.getName().equals("zipped - Copy.txt")) {
45+
zippedCopyExtracted = true;
46+
}
47+
}
48+
assertTrue("zipped.txt not extracted", zippedExtracted);
49+
assertTrue("zipped - Copy.txt not extracted", zippedCopyExtracted);
50+
}
51+
52+
@Test
53+
public void testTarGZ() throws Exception {
54+
String tarGzFileName = resourceFolder + "tarfile.tar.gz";
55+
util.unzip(tarGzFileName, destination);
56+
File[] files = dest.listFiles();
57+
boolean taredExtracted = false;
58+
boolean taredCopyExtracted = false;
59+
for (File f : files) {
60+
if (f.getName().equals("tared.txt")) {
61+
taredExtracted = true;
62+
}
63+
if (f.getName().equals("tared - Copy.txt")) {
64+
taredCopyExtracted = true;
65+
}
66+
}
67+
assertTrue("tared.txt not extracted", taredExtracted);
68+
assertTrue("tared - Copy.txt not extracted", taredCopyExtracted);
69+
}
70+
71+
@Test
72+
public void testNestedFiles() throws Exception {
73+
String nestedFolders = resourceFolder + "nested.tar";
74+
util.unzip(nestedFolders, destination);
75+
boolean firstLvlFolder = false;
76+
boolean secondLvlFolder = false;
77+
boolean secondLvlFile = false;
78+
boolean thirdLvlFile = false;
79+
80+
for (File f : dest.listFiles()) {
81+
if (f.isDirectory() && f.getName().equals("New folder")) {
82+
firstLvlFolder = true;
83+
for (File ff : f.listFiles()) {
84+
if (ff.isDirectory() && ff.getName().equals("New folder")) {
85+
secondLvlFolder = true;
86+
for (File fff : ff.listFiles()) {
87+
if (fff.getName().equals("test.txt")) {
88+
thirdLvlFile = true;
89+
}
90+
}
91+
}
92+
if (ff.isFile() && ff.getName().equals("test.txt")) {
93+
secondLvlFile = true;
94+
}
95+
}
96+
}
97+
}
98+
99+
assertTrue("Problems in the first lvl", firstLvlFolder);
100+
assertTrue("Problems in the second lvl", secondLvlFile && secondLvlFolder);
101+
assertTrue("Problems in the third lvl", thirdLvlFile);
102+
103+
}
104+
105+
@Test
106+
public void testFirstDataInFolder() throws Exception {
107+
String zipFile = resourceFolder + "data.zip";
108+
util.unzip(zipFile, destination);
109+
110+
boolean aExists = new File(destination + "/elasticsearch-2.3.0/README.textile").exists();
111+
112+
assertTrue("File not found", aExists);
113+
}
114+
115+
@AfterClass
116+
public static void afterAll() {
117+
118+
for (File f : dest.listFiles()) {
119+
if (f.isFile()) {
120+
f.delete();
121+
} else {
122+
deleteFolder(f);
123+
}
124+
}
125+
}
126+
127+
public static void deleteFolder(File f) {
128+
for (File ff : f.listFiles()) {
129+
if (ff.isDirectory()) {
130+
deleteFolder(ff);
131+
}
132+
ff.delete();
133+
}
134+
f.delete();
135+
}
136+
}
File renamed without changes.

task-unzip/META-INF/MANIFEST.MF

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ Bundle-Vendor: %providerName
55
Bundle-SymbolicName: com.github.maybeec.oomph.task.unzip;singleton:=true
66
Bundle-Version: 1.0.0.qualifier
77
Bundle-ClassPath: .,
8-
lib/commons-compress-1.12.jar
8+
lib/commons-compress-1.19.jar
99
Bundle-ActivationPolicy: lazy
1010
Bundle-Localization: plugin
1111
Bundle-RequiredExecutionEnvironment: J2SE-1.5
1212
Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.5.0,4.0.0)",
1313
org.eclipse.emf.ecore;bundle-version="[2.10.0,3.0.0)";visibility:=reexport,
14-
org.eclipse.oomph.setup;bundle-version="[1.1.0,2.0.0)";visibility:=reexport,
1514
org.eclipse.oomph.base;bundle-version="[1.1.0,2.0.0)";visibility:=reexport,
16-
org.junit
15+
org.eclipse.oomph.setup;bundle-version="[1.1.0,2.0.0)"
1716
Export-Package: com.github.maybeec.oomph.task.unzip,
17+
com.github.maybeec.oomph.task.unzip.core,
18+
com.github.maybeec.oomph.task.unzip.core.exceptions,
19+
com.github.maybeec.oomph.task.unzip.core.impl,
1820
com.github.maybeec.oomph.task.unzip.impl,
1921
com.github.maybeec.oomph.task.unzip.util

task-unzip/build.properties

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
#
2-
31
bin.includes = .,\
42
model/,\
53
META-INF/,\
64
plugin.xml,\
75
plugin.properties,\
8-
lib/commons-compress-1.12.jar
6+
lib/commons-compress-1.19.jar
97
jars.compile.order = .
108
source.. = src/
119
output.. = bin/

0 commit comments

Comments
 (0)