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) {
Set<String> missingParameters = Stream.of(this.method.getParameters())
.filter(p -> isMissing(p, arguments))
.map(Parameter::getName)
.filter((p) -> isMissing(p, arguments)).map(Parameter::getName)
.collect(Collectors.toSet());
if (!missingParameters.isEmpty()) {
throw new ParametersMissingException(missingParameters);

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

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

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

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