Skip to content

Commit

Permalink
Fix some unit tests for Windows OS
Browse files Browse the repository at this point in the history
  • Loading branch information
vbauer committed Mar 31, 2015
1 parent 650db4b commit 1b78a41
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 50 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -6,3 +6,4 @@
/.settings/
/.classpath
/.project
/generated/
50 changes: 20 additions & 30 deletions src/test/java/com/github/kongchen/jaxrs/SwaggerMavenPluginTest.java
Expand Up @@ -5,6 +5,7 @@
import com.github.kongchen.swagger.docgen.mavenplugin.ApiDocumentMojo;
import com.github.kongchen.swagger.docgen.mavenplugin.ApiSource;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
Expand All @@ -14,7 +15,6 @@
import org.testng.annotations.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
Expand All @@ -23,7 +23,7 @@
import java.util.List;

/**
* Created by chekong on 8/15/14.
* @author chekong
*/
public class SwaggerMavenPluginTest extends AbstractMojoTestCase {

Expand All @@ -48,50 +48,40 @@ protected void setUp() throws Exception {

@Test
public void testGeneratedDoc() throws Exception {

mojo.execute();
FileInputStream testOutputIs = new FileInputStream(docOutput);
InputStream expectIs = this.getClass().getResourceAsStream("/sample.html");
int count = 0;
while (true) {
count++;
int expect = expectIs.read();
int actual = testOutputIs.read();

Assert.assertEquals(expect, actual, "" + count);
if (expect == -1) {
break;
}

final InputStream resource = getClass().getResourceAsStream("/sample.html");
final List<String> expect = IOUtils.readLines(resource);
final List<String> testOutput = FileUtils.readLines(docOutput);

Assert.assertEquals(expect.size(), testOutput.size());
for (int i = 0; i < expect.size(); i++) {
Assert.assertEquals(expect.get(i), testOutput.get(i));
}
}

@Test
public void testSortApis() throws Exception {
List<ApiSource> apisources = (List<ApiSource>) getVariableValueFromObject(mojo, "apiSources");
final List<ApiSource> apisources = (List<ApiSource>) getVariableValueFromObject(mojo, "apiSources");
apisources.get(0).setApiSortComparator("com.github.kongchen.jaxrs.ApiComparator");
setVariableValueToObject(mojo, "apiSources", apisources);

mojo.execute();
FileInputStream testOutputIs = new FileInputStream(docOutput);
InputStream expectIs = this.getClass().getResourceAsStream("/sorted-sample.html");
int count = 0;
while (true) {
count++;
int expect = expectIs.read();
int actual = testOutputIs.read();

Assert.assertEquals(expect, actual, "" + count);
if (expect == -1) {
break;
}

final InputStream resource = getClass().getResourceAsStream("/sorted-sample.html");
final List<String> expect = IOUtils.readLines(resource);
final List<String> testOutput = FileUtils.readLines(docOutput);

Assert.assertEquals(expect.size(), testOutput.size());
for (int i = 0; i < expect.size(); i++) {
Assert.assertEquals(expect.get(i), testOutput.get(i));
}
}

@Test
public void testSwaggerOutput() throws Exception {

mojo.execute();


List<File> outputFiles = new ArrayList<File>();

Collections.addAll(outputFiles, swaggerOutputDir.listFiles());
Expand Down
Expand Up @@ -5,6 +5,7 @@
import com.github.kongchen.swagger.docgen.mavenplugin.ApiDocumentMojo;
import com.github.kongchen.swagger.docgen.mavenplugin.ApiSource;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
Expand All @@ -14,7 +15,6 @@
import org.testng.annotations.Test;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
Expand All @@ -23,12 +23,13 @@
import java.util.List;

/**
* Created by chekong on 8/15/14.
* @author chekong
*/

public class SwaggerMavenPluginSpringMvcTest extends AbstractMojoTestCase {

private File swaggerOutputDir = new File(getBasedir(), "generated/swagger-ui-springmvc");
private File docOutput = new File(getBasedir(), "generated/document-springmvc.html");
private final File swaggerOutputDir = new File(getBasedir(), "generated/swagger-ui-springmvc");
private final File docOutput = new File(getBasedir(), "generated/document-springmvc.html");
private ApiDocumentMojo mojo;


Expand All @@ -48,29 +49,22 @@ protected void setUp() throws Exception {

@Test
public void testGeneratedDoc() throws Exception {

mojo.execute();
FileInputStream testOutputIs = new FileInputStream(docOutput);
InputStream expectIs = this.getClass().getResourceAsStream("/sample-springmvc.html");
int count = 0;
while (true) {
count++;
int expect = expectIs.read();
int actual = testOutputIs.read();

Assert.assertEquals(expect, actual, "" + count);
if (expect == -1) {
break;
}

final InputStream resource = getClass().getResourceAsStream("/sample-springmvc.html");
final List<String> expect = IOUtils.readLines(resource);
final List<String> testOutput = FileUtils.readLines(docOutput);

Assert.assertEquals(expect.size(), testOutput.size());
for (int i = 0; i < expect.size(); i++) {
Assert.assertEquals(expect.get(i), testOutput.get(i));
}
}

@Test
public void testSwaggerOutput() throws Exception {

mojo.execute();


List<File> outputFiles = new ArrayList<File>();

Collections.addAll(outputFiles, swaggerOutputDir.listFiles());
Expand Down Expand Up @@ -235,7 +229,7 @@ public void testExecuteDirectoryCreated(String path) throws Exception {
private String createTempDirPath() throws Exception {
File tempFile = File.createTempFile("swagmvn", "test");
String path = tempFile.getAbsolutePath();
tempFile.delete();
FileUtils.deleteQuietly(tempFile);
return path;
}
}

0 comments on commit 1b78a41

Please sign in to comment.