pull/10451/merge
Phillip Webb 7 years ago
parent 14af3463ec
commit 69a1eebf68

@ -65,8 +65,7 @@ public class ReflectiveOperationInvoker implements OperationInvoker {
private void validateRequiredParameters(Map<String, Object> arguments) { private void validateRequiredParameters(Map<String, Object> arguments) {
Set<String> missingParameters = Stream.of(this.method.getParameters()) Set<String> missingParameters = Stream.of(this.method.getParameters())
.filter(p -> isMissing(p, arguments)) .filter((p) -> isMissing(p, arguments)).map(Parameter::getName)
.map(Parameter::getName)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
if (!missingParameters.isEmpty()) { if (!missingParameters.isEmpty()) {
throw new ParametersMissingException(missingParameters); throw new ParametersMissingException(missingParameters);

@ -167,7 +167,8 @@ public class EnvironmentEndpoint {
private Map<String, PropertySource<?>> getPropertySourcesAsMap() { private Map<String, PropertySource<?>> getPropertySourcesAsMap() {
Map<String, PropertySource<?>> map = new LinkedHashMap<>(); Map<String, PropertySource<?>> map = new LinkedHashMap<>();
for (PropertySource<?> source : getPropertySources()) { for (PropertySource<?> source : getPropertySources()) {
if (!ConfigurationPropertySources.isAttachedConfigurationPropertySource(source)) { if (!ConfigurationPropertySources
.isAttachedConfigurationPropertySource(source)) {
extract("", map, source); extract("", map, source);
} }
} }

@ -267,33 +267,39 @@ public class EndpointMBeanTests {
} }
@Test @Test
public void invokeWithParameterMappingExceptionMapsToIllegalArgumentException() throws Exception { public void invokeWithParameterMappingExceptionMapsToIllegalArgumentException()
throws Exception {
load(FooEndpoint.class, (discoverer) -> { load(FooEndpoint.class, (discoverer) -> {
ObjectName objectName = registerEndpoint(discoverer, "foo"); ObjectName objectName = registerEndpoint(discoverer, "foo");
try { try {
this.server.invoke(objectName, "getOne", this.server.invoke(objectName, "getOne", new Object[] { "wrong" },
new Object[] { "wrong" }, new String[] { String.class.getName() }); new String[] { String.class.getName() });
} }
catch (Exception ex) { catch (Exception ex) {
assertThat(ex.getCause()).isExactlyInstanceOf(IllegalArgumentException.class); assertThat(ex.getCause())
assertThat(ex.getCause().getMessage()).isEqualTo(String.format("Failed to map wrong of type " + .isExactlyInstanceOf(IllegalArgumentException.class);
"%s to type %s", String.class, FooName.class)); assertThat(ex.getCause().getMessage()).isEqualTo(
String.format("Failed to map wrong of type " + "%s to type %s",
String.class, FooName.class));
} }
}); });
} }
@Test @Test
public void invokeWithMissingRequiredParameterExceptionMapsToIllegalArgumentException() throws Exception { public void invokeWithMissingRequiredParameterExceptionMapsToIllegalArgumentException()
throws Exception {
load(RequiredParametersEndpoint.class, (discoverer) -> { load(RequiredParametersEndpoint.class, (discoverer) -> {
ObjectName objectName = registerEndpoint(discoverer, "requiredparameters"); ObjectName objectName = registerEndpoint(discoverer, "requiredparameters");
try { try {
this.server.invoke(objectName, "read", this.server.invoke(objectName, "read", new Object[] {},
new Object[] {}, new String[] { String.class.getName() }); new String[] { String.class.getName() });
} }
catch (Exception ex) { catch (Exception ex) {
assertThat(ex.getCause()).isExactlyInstanceOf(IllegalArgumentException.class); assertThat(ex.getCause())
assertThat(ex.getCause().getMessage()).isEqualTo("Failed to invoke operation because the following " + .isExactlyInstanceOf(IllegalArgumentException.class);
"required parameters were missing: foo,baz"); assertThat(ex.getCause().getMessage())
.isEqualTo("Failed to invoke operation because the following "
+ "required parameters were missing: foo,baz");
} }
}); });
} }
@ -304,7 +310,8 @@ public class EndpointMBeanTests {
ObjectName objectName = registerEndpoint(discoverer, "requiredparameters"); ObjectName objectName = registerEndpoint(discoverer, "requiredparameters");
try { try {
this.server.invoke(objectName, "read", this.server.invoke(objectName, "read",
new Object[] {null, "hello", "world"}, new String[] { String.class.getName() }); new Object[] { null, "hello", "world" },
new String[] { String.class.getName() });
} }
catch (Exception ex) { catch (Exception ex) {
throw new AssertionError("Nullable parameter should not be required."); throw new AssertionError("Nullable parameter should not be required.");

@ -283,17 +283,16 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
} }
@Test @Test
public void readOperationWithMissingRequiredParametersReturnsBadRequestResponse() throws Exception { public void readOperationWithMissingRequiredParametersReturnsBadRequestResponse()
load(RequiredParameterEndpointConfiguration.class, throws Exception {
(client) -> client.get().uri("/requiredparameters").exchange() load(RequiredParameterEndpointConfiguration.class, (client) -> client.get()
.expectStatus().isBadRequest()); .uri("/requiredparameters").exchange().expectStatus().isBadRequest());
} }
@Test @Test
public void readOperationWithMissingNullableParametersIsOk() throws Exception { public void readOperationWithMissingNullableParametersIsOk() throws Exception {
load(RequiredParameterEndpointConfiguration.class, load(RequiredParameterEndpointConfiguration.class, (client) -> client.get()
(client) -> client.get().uri("/requiredparameters?foo=hello").exchange() .uri("/requiredparameters?foo=hello").exchange().expectStatus().isOk());
.expectStatus().isOk());
} }
protected abstract T createApplicationContext(Class<?>... config); protected abstract T createApplicationContext(Class<?>... config);

@ -40,21 +40,8 @@ import static org.junit.Assert.assertTrue;
*/ */
public class JarCommandIT { public class JarCommandIT {
private static final boolean java9OrLater; private static final boolean JAVA_9_OR_LATER = isClassPresent(
"java.security.cert.URICertStoreParameters");
static {
boolean loaded = false;
try {
Class.forName("java.security.cert.URICertStoreParameters");
loaded = true;
}
catch (Exception ex) {
// Continue
}
finally {
java9OrLater = loaded;
}
}
private final CommandLineInvoker cli = new CommandLineInvoker( private final CommandLineInvoker cli = new CommandLineInvoker(
new File("src/it/resources/jar-command")); new File("src/it/resources/jar-command"));
@ -83,12 +70,12 @@ public class JarCommandIT {
Invocation invocation = this.cli.invoke("run", jar.getAbsolutePath(), Invocation invocation = this.cli.invoke("run", jar.getAbsolutePath(),
"bad.groovy"); "bad.groovy");
invocation.await(); invocation.await();
if (!java9OrLater) { if (!JAVA_9_OR_LATER) {
assertThat(invocation.getErrorOutput(), equalTo("")); assertThat(invocation.getErrorOutput(), equalTo(""));
} }
invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "bad.groovy"); invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "bad.groovy");
invocation.await(); invocation.await();
if (!java9OrLater) { if (!JAVA_9_OR_LATER) {
assertEquals(invocation.getErrorOutput(), 0, assertEquals(invocation.getErrorOutput(), 0,
invocation.getErrorOutput().length()); invocation.getErrorOutput().length());
} }
@ -99,7 +86,7 @@ public class JarCommandIT {
invocation = new Invocation(process); invocation = new Invocation(process);
invocation.await(); invocation.await();
if (!java9OrLater) { if (!JAVA_9_OR_LATER) {
assertThat(invocation.getErrorOutput(), equalTo("")); assertThat(invocation.getErrorOutput(), equalTo(""));
} }
} }
@ -110,7 +97,7 @@ public class JarCommandIT {
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(),
"jar.groovy"); "jar.groovy");
invocation.await(); invocation.await();
if (!java9OrLater) { if (!JAVA_9_OR_LATER) {
assertEquals(invocation.getErrorOutput(), 0, assertEquals(invocation.getErrorOutput(), 0,
invocation.getErrorOutput().length()); invocation.getErrorOutput().length());
} }
@ -121,7 +108,7 @@ public class JarCommandIT {
invocation = new Invocation(process); invocation = new Invocation(process);
invocation.await(); invocation.await();
if (!java9OrLater) { if (!JAVA_9_OR_LATER) {
assertThat(invocation.getErrorOutput(), equalTo("")); assertThat(invocation.getErrorOutput(), equalTo(""));
} }
assertThat(invocation.getStandardOutput(), containsString("Hello World!")); assertThat(invocation.getStandardOutput(), containsString("Hello World!"));
@ -144,7 +131,7 @@ public class JarCommandIT {
Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "--include", Invocation invocation = this.cli.invoke("jar", jar.getAbsolutePath(), "--include",
"-public/**,-resources/**", "jar.groovy"); "-public/**,-resources/**", "jar.groovy");
invocation.await(); invocation.await();
if (!java9OrLater) { if (!JAVA_9_OR_LATER) {
assertEquals(invocation.getErrorOutput(), 0, assertEquals(invocation.getErrorOutput(), 0,
invocation.getErrorOutput().length()); invocation.getErrorOutput().length());
} }
@ -155,7 +142,7 @@ public class JarCommandIT {
invocation = new Invocation(process); invocation = new Invocation(process);
invocation.await(); invocation.await();
if (!java9OrLater) { if (!JAVA_9_OR_LATER) {
assertThat(invocation.getErrorOutput(), equalTo("")); assertThat(invocation.getErrorOutput(), equalTo(""));
} }
assertThat(invocation.getStandardOutput(), containsString("Hello World!")); assertThat(invocation.getStandardOutput(), containsString("Hello World!"));
@ -168,4 +155,15 @@ public class JarCommandIT {
containsString("/templates/template.txt")); containsString("/templates/template.txt"));
assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama")); assertThat(invocation.getStandardOutput(), containsString("Goodbye Mama"));
} }
private static boolean isClassPresent(String name) {
try {
Class.forName(name);
return true;
}
catch (Exception ex) {
return false;
}
}
} }

Loading…
Cancel
Save