Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove uri validation when @TestHTTPResource is injected as String
Browse files Browse the repository at this point in the history
Eng-Fouad committed Jul 24, 2023

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 7597447 commit be299c1
Showing 5 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.test.common.http;

import java.lang.reflect.Field;
import java.net.URI;

public class StringTestHTTPResourceProvider implements TestHTTPResourceProvider<String> {
@Override
@@ -10,7 +9,7 @@ public Class<String> getProvidedType() {
}

@Override
public String provide(URI testUri, Field field) {
return testUri.toASCIIString();
public String provide(String testUri, Field field) {
return testUri;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.test.common.http;

import java.lang.reflect.Field;
import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -102,7 +101,7 @@ public static void inject(Object testCase, List<Function<Class<?>, String>> endp
}
f.setAccessible(true);
try {
f.set(testCase, provider.provide(new URI(val), f));
f.set(testCase, provider.provide(val, f));
} catch (Exception e) {
throw new RuntimeException(e);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.quarkus.test.common.http;

import java.lang.reflect.Field;
import java.net.URI;

public interface TestHTTPResourceProvider<T> {

@@ -13,6 +12,6 @@ public interface TestHTTPResourceProvider<T> {
* Note that there is no need to directly call set() on the field, it is only provided
* to allow you to examine the generic type and any additional annotations.
*/
T provide(URI testUri, Field field);
T provide(String testUri, Field field);

}
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@

import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;

public class URITestHTTPResourceProvider implements TestHTTPResourceProvider<URI> {
@Override
@@ -10,7 +11,11 @@ public Class<URI> getProvidedType() {
}

@Override
public URI provide(URI testUri, Field field) {
return testUri;
public URI provide(String testUri, Field field) {
try {
return new URI(testUri);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

public class URLTestHTTPResourceProvider implements TestHTTPResourceProvider<URL> {
@@ -12,10 +13,10 @@ public Class<URL> getProvidedType() {
}

@Override
public URL provide(URI testUri, Field field) {
public URL provide(String testUri, Field field) {
try {
return testUri.toURL();
} catch (MalformedURLException e) {
return new URI(testUri).toURL();
} catch (MalformedURLException | URISyntaxException e) {
throw new RuntimeException(e);
}
}

0 comments on commit be299c1

Please sign in to comment.