001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.service.model;
019:
020: import javax.xml.namespace.QName;
021:
022: import org.junit.Assert;
023: import org.junit.Before;
024: import org.junit.Test;
025:
026: public class OperationInfoTest extends Assert {
027:
028: private OperationInfo operationInfo;
029:
030: @Before
031: public void setUp() throws Exception {
032: operationInfo = new OperationInfo(null, new QName(
033: "urn:test:ns", "operationTest"));
034: }
035:
036: @Test
037: public void testName() throws Exception {
038: assertNull(operationInfo.getInterface());
039: assertEquals("operationTest", operationInfo.getName()
040: .getLocalPart());
041: operationInfo
042: .setName(new QName("urn:test:ns", "operationTest2"));
043: assertEquals("operationTest2", operationInfo.getName()
044: .getLocalPart());
045: try {
046: operationInfo.setName(null);
047: fail("should catch IllegalArgumentException since name is null");
048: } catch (NullPointerException e) {
049: assertEquals(e.getMessage(),
050: "Operation Name cannot be null.");
051: }
052: }
053:
054: @Test
055: public void testInput() throws Exception {
056: assertFalse(operationInfo.hasInput());
057: MessageInfo inputMessage = operationInfo
058: .createMessage(new QName(
059: "http://apache.org/hello_world_soap_http",
060: "testInputMessage"));
061: operationInfo.setInput("input", inputMessage);
062: assertTrue(operationInfo.hasInput());
063: inputMessage = operationInfo.getInput();
064: assertEquals("testInputMessage", inputMessage.getName()
065: .getLocalPart());
066: assertEquals("http://apache.org/hello_world_soap_http",
067: inputMessage.getName().getNamespaceURI());
068: assertEquals(operationInfo.getInputName(), "input");
069: }
070:
071: @Test
072: public void testOutput() throws Exception {
073: assertFalse(operationInfo.hasOutput());
074: MessageInfo outputMessage = operationInfo
075: .createMessage(new QName(
076: "http://apache.org/hello_world_soap_http",
077: "testOutputMessage"));
078: operationInfo.setOutput("output", outputMessage);
079: assertTrue(operationInfo.hasOutput());
080: outputMessage = operationInfo.getOutput();
081: assertEquals("testOutputMessage", outputMessage.getName()
082: .getLocalPart());
083: assertEquals("http://apache.org/hello_world_soap_http",
084: outputMessage.getName().getNamespaceURI());
085: assertEquals(operationInfo.getOutputName(), "output");
086: }
087:
088: @Test
089: public void testOneWay() throws Exception {
090: assertFalse(operationInfo.isOneWay());
091: MessageInfo inputMessage = operationInfo
092: .createMessage(new QName(
093: "http://apache.org/hello_world_soap_http",
094: "testInputMessage"));
095: operationInfo.setInput("input", inputMessage);
096: assertTrue(operationInfo.isOneWay());
097: }
098:
099: @Test
100: public void testFault() throws Exception {
101: assertEquals(operationInfo.getFaults().size(), 0);
102: QName faultName = new QName("urn:test:ns", "fault");
103: operationInfo.addFault(faultName, new QName(
104: "http://apache.org/hello_world_soap_http",
105: "faultMessage"));
106: assertEquals(operationInfo.getFaults().size(), 1);
107: FaultInfo fault = operationInfo.getFault(faultName);
108: assertNotNull(fault);
109: assertEquals(fault.getFaultName().getLocalPart(), "fault");
110: assertEquals(fault.getName().getLocalPart(), "faultMessage");
111: assertEquals(fault.getName().getNamespaceURI(),
112: "http://apache.org/hello_world_soap_http");
113: operationInfo.removeFault(faultName);
114: assertEquals(operationInfo.getFaults().size(), 0);
115: try {
116: operationInfo.addFault(null, null);
117: fail("should get NullPointerException");
118: } catch (NullPointerException e) {
119: assertEquals(e.getMessage(), "Faule Name cannot be null.");
120: }
121: try {
122: operationInfo.addFault(faultName, null);
123: operationInfo.addFault(faultName, null);
124: fail("should get IllegalArgumentException");
125: } catch (IllegalArgumentException e) {
126: assertEquals(e.getMessage(),
127: "A fault with name [{urn:test:ns}fault] already exists in this operation");
128: }
129: }
130:
131: }
|