Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove test dependency on commons-io #1628

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.smallrye</groupId>
<artifactId>smallrye-open-api-parent</artifactId>
<version>3.7.1-SNAPSHOT</version>
</parent>

<artifactId>smallrye-open-api-core</artifactId>

<name>SmallRye: OpenAPI Core</name>

<properties>
<!-- Excluded model classes for duplication checks (getters/setters treated as duplicates by Sonar) -->
<sonar.cpd.exclusions>src/main/java/io/smallrye/openapi/api/models/**/*.java</sonar.cpd.exclusions>
Expand Down Expand Up @@ -71,12 +71,6 @@
<artifactId>smallrye-config</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package io.smallrye.openapi.api.util;

import static io.smallrye.openapi.runtime.scanner.IndexScannerTestBase.loadResource;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import java.io.IOException;
import java.net.URL;

import org.apache.commons.io.IOUtils;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.openapi.OASFactory;
Expand All @@ -30,16 +29,6 @@
*/
class FilterUtilTest {

/**
* Loads a resource as a string (reads the content at the URL).
*
* @param testResource
* @throws IOException
*/
private static String loadResource(URL testResource) throws IOException {
return IOUtils.toString(testResource, "UTF-8");
}

/**
* Compares two JSON strings.
*
Expand Down
13 changes: 2 additions & 11 deletions core/src/test/java/io/smallrye/openapi/api/util/MergeUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.smallrye.openapi.api.util;

import static io.smallrye.openapi.runtime.scanner.IndexScannerTestBase.loadResource;

import java.io.IOException;
import java.net.URL;
import java.text.ParseException;

import org.apache.commons.io.IOUtils;
import org.eclipse.microprofile.openapi.models.OpenAPI;
import org.json.JSONException;
import org.junit.jupiter.api.Test;
Expand All @@ -19,16 +20,6 @@
*/
class MergeUtilTest {

/**
* Loads a resource as a string (reads the content at the URL).
*
* @param testResource
* @throws IOException
*/
private static String loadResource(URL testResource) throws IOException {
return IOUtils.toString(testResource, "UTF-8");
}

/**
* Compares two JSON strings.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.smallrye.openapi.runtime.io;

import static io.smallrye.openapi.runtime.scanner.IndexScannerTestBase.loadResource;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

Expand All @@ -13,7 +14,6 @@
import java.nio.file.Files;
import java.nio.file.Path;

import org.apache.commons.io.IOUtils;
import org.eclipse.microprofile.openapi.OASFactory;
import org.eclipse.microprofile.openapi.models.OpenAPI;
import org.json.JSONException;
Expand All @@ -36,16 +36,6 @@ class OpenApiParserAndSerializerTest {

static final int REPEAT_BODY_CONTENTS_ITERATIONS = 1536; // ~8MB?

/**
* Loads a resource as a string (reads the content at the URL).
*
* @param testResource
* @throws IOException
*/
private static String loadResource(URL testResource) throws IOException {
return IOUtils.toString(testResource, "UTF-8");
}

/**
* Compares two JSON strings.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UncheckedIOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.IOUtils;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.ConfigSource;
import org.eclipse.microprofile.openapi.models.OpenAPI;
Expand Down Expand Up @@ -181,19 +182,23 @@ public static void assertJsonEquals(String expectedResource, Class<?>... classes
}

public static String loadResource(URL testResource) throws IOException {
return IOUtils.toString(testResource, "UTF-8");
final char[] buffer = new char[8192];
final StringBuilder result = new StringBuilder();

try (Reader reader = new InputStreamReader(testResource.openStream(), StandardCharsets.UTF_8)) {
int count;
while ((count = reader.read(buffer, 0, buffer.length)) > 0) {
result.append(buffer, 0, count);
}
}

return result.toString();
}

public static OpenApiConfig emptyConfig() {
return dynamicConfig(Collections.emptyMap());
}

// public static OpenApiConfig nestingSupportConfig() {
// Map<String, Object> config = new HashMap<>();
// config.put(OpenApiConstants.SMALLRYE_SCHEMA_REFERENCES_ENABLE, Boolean.TRUE);
// return dynamicConfig(config);
// }

public static OpenApiConfig dynamicConfig(String key, Object value) {
Map<String, String> config = new HashMap<>(1);
config.put(key, value.toString());
Expand Down
6 changes: 0 additions & 6 deletions extension-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@
<artifactId>jsonassert</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.14.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
Expand Down
7 changes: 0 additions & 7 deletions extension-vertx/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@
<artifactId>jsonassert</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.14.0</version>
<scope>test</scope>
</dependency>


<!-- Depend on core tests -->
<dependency>
Expand Down