SWS-544 - Added more JUnit tests

This commit is contained in:
Arjen Poutsma
2010-07-16 14:41:17 +00:00
parent 1859c89040
commit 18dee1a352
5 changed files with 168 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
/*
* Copyright 2005-2010 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.ws.mock.client;
import java.io.IOException;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class ErrorResponseCallbackTest {
@Test
public void callback() throws IOException {
String errorMessage = "Error message";
ErrorResponseCallback callback = new ErrorResponseCallback(errorMessage);
callback.doWithResponse(null, null);
assertEquals(errorMessage, callback.getErrorMessage());
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright 2005-2010 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.ws.mock.client;
import java.io.IOException;
import org.springframework.xml.transform.StringSource;
import org.junit.Test;
import static org.junit.Assert.*;
public class MockSenderConnectionTest {
@Test
public void error() throws IOException {
String testErrorMessage = "Test Error Message";
MockSenderConnection connection = new MockSenderConnection();
connection.andRespond(new ErrorResponseCallback(testErrorMessage));
assertTrue(connection.hasError());
assertEquals(testErrorMessage, connection.getErrorMessage());
}
@Test
public void normal() throws IOException {
MockSenderConnection connection = new MockSenderConnection();
connection.andRespond(new PayloadResponseCallback(new StringSource("<response/>")));
assertFalse(connection.hasError());
assertNull(connection.getErrorMessage());
}
@Test(expected = AssertionError.class)
public void noRequestMatchers() throws IOException {
MockSenderConnection connection = new MockSenderConnection();
connection.andRespond(new PayloadResponseCallback(new StringSource("<response/>")));
connection.send(null);
}
}

View File

@@ -0,0 +1,31 @@
/*
* Copyright 2005-2010 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.ws.mock.client;
import java.io.IOException;
import java.net.URI;
import org.junit.Test;
public class MockWebServiceMessageSenderTest {
@Test(expected = AssertionError.class)
public void testNoMoreExpectedConnections() throws IOException {
MockWebServiceMessageSender sender = new MockWebServiceMessageSender();
sender.createConnection(URI.create("http://localhost"));
}
}

View File

@@ -16,7 +16,11 @@
package org.springframework.ws.mock.client;
import javax.xml.soap.MessageFactory;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.springframework.xml.transform.StringSource;
import org.junit.Test;
@@ -50,4 +54,13 @@ public class PayloadDiffMatcherTest {
matcher.match(null, message);
}
@Test(expected = AssertionError.class)
public void noPayload() throws Exception {
PayloadDiffMatcher matcher = new PayloadDiffMatcher(new StringSource("<message/>"));
MessageFactory messageFactory = MessageFactory.newInstance();
SoapMessage soapMessage = new SaajSoapMessage(messageFactory.createMessage());
matcher.createDiff(soapMessage);
}
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright 2005-2010 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.ws.mock.client;
import java.net.URI;
import org.junit.Test;
public class UriMatcherTest {
private static final URI GOOD_URI = URI.create("http://localhost");
@Test
public void match() {
UriMatcher matcher = new UriMatcher(GOOD_URI);
matcher.match(GOOD_URI, null);
}
@Test(expected = AssertionError.class)
public void nonMatch() {
UriMatcher matcher = new UriMatcher(GOOD_URI);
matcher.match(URI.create("http://www.example.org"), null);
}
}