Added validation and tests (exactly 1 Message or payload when mapping with toMessage(), etc).

This commit is contained in:
Mark Fisher
2008-09-27 19:33:32 +00:00
parent e86b9eb6d8
commit cf57a20b33
3 changed files with 92 additions and 21 deletions

View File

@@ -0,0 +1,57 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.message;
import java.lang.reflect.Method;
import org.junit.Test;
/**
* @author Mark Fisher
*/
public class MethodParameterMessageMapperInitializationTests {
@Test(expected = IllegalArgumentException.class)
public void messageAndPayload() throws Exception {
Method method = TestService.class.getMethod("messageAndPayload", Message.class, String.class);
new MethodParameterMessageMapper(method);
}
@Test(expected = IllegalArgumentException.class)
public void twoMessages() throws Exception {
Method method = TestService.class.getMethod("twoMessages", Message.class, Message.class);
new MethodParameterMessageMapper(method);
}
@Test(expected = IllegalArgumentException.class)
public void twoPayloads() throws Exception {
Method method = TestService.class.getMethod("twoPayloads", String.class, String.class);
new MethodParameterMessageMapper(method);
}
private static interface TestService {
void messageAndPayload(Message<?> message, String foo);
void twoMessages(Message<?> message1, Message<?> message2);
void twoPayloads(String foo, String bar);
}
}

View File

@@ -173,6 +173,20 @@ public class MethodParameterMessageMapperToMessageTests {
assertNull(message.getHeaders().get("foo"));
}
@Test(expected = IllegalArgumentException.class)
public void noArgs() throws Exception {
Method method = TestService.class.getMethod("noArgs", new Class<?>[] {});
MethodParameterMessageMapper mapper = new MethodParameterMessageMapper(method);
mapper.toMessage(new Object[] {});
}
@Test(expected = IllegalArgumentException.class)
public void onlyHeaders() throws Exception {
Method method = TestService.class.getMethod("onlyHeaders", String.class, String.class);
MethodParameterMessageMapper mapper = new MethodParameterMessageMapper(method);
mapper.toMessage(new Object[] { "abc", "def" });
}
private static interface TestService {
@@ -190,6 +204,12 @@ public class MethodParameterMessageMapperToMessageTests {
void sendMessageAndOptionalHeader(Message<?> message, @Header(value="foo", required=false) String foo);
// invalid methods
void noArgs();
void onlyHeaders(@Header("foo") String foo, @Header("bar") String bar);
}
}