annotationserviceimpldescriptiontests.java

来自「开源的axis2框架的源码。用于开发WEBSERVER」· Java 代码 · 共 1,126 行 · 第 1/5 页

JAVA
1,126
字号
        assertEquals(operations.length, 2);
        assertEquals(operations[0].getJavaMethodName(), "twoWayHolderAsync");
        assertEquals(operations[1].getJavaMethodName(), "twoWayHolderAsync");

        // Check the parameters for each operation
        twoArgSignatureChecked = false;
        boolean threeArgSignatureChecked = false;
        for (OperationDescription operation : operations) {
            String[] checkParams = operation.getJavaParameters();
            String[] webParamNames = operation.getParamNames();
            if (checkParams.length == 3) {
                // Check the one arguement signature
                if (threeArgSignatureChecked) {
                    fail("Three Arg signature occured more than once");
                } else {
                    threeArgSignatureChecked = true;
                    assertEquals(checkParams[0], "java.lang.String");
                    assertEquals(checkParams[1], "int");
                    assertEquals(checkParams[2],
                                 "javax.xml.ws.AsyncHandler<org.test.proxy.doclitwrapped.TwoWayHolder>");
                    // Check the WebParam Names (see note above) 
                    assertEquals(3, webParamNames.length);
                    assertEquals("twoWayHolder_str", webParamNames[0]);
                    assertEquals("twoWayHolder_int", webParamNames[1]);
                    // Check the lack of a WebResult annotation and the default values for
                    // SOAPBinding Style=DOCUMENT, Use=LITERAL, ParamStyle=WRAPPED
                    // Note that the SOAPBinding annotation is also not present and thus fully defaulted.
                    assertNull(((OperationDescriptionJava)operation).getAnnoWebResult());
                    assertEquals("return", operation.getResultName());
                    assertEquals("return", operation.getResultPartName());
                    assertEquals("", operation.getResultTargetNamespace());
                    assertFalse(operation.isResultHeader());
                }
            } else if (checkParams.length == 2) {
                // Check the two arguement signature
                if (twoArgSignatureChecked) {
                    fail("Two Arg signature occured more than once");
                } else {
                    twoArgSignatureChecked = true;
                    assertEquals(checkParams[0], "java.lang.String");
                    assertEquals(checkParams[1], "int");
                    // Check the WebParam Names (see note above) 
                    assertEquals(2, webParamNames.length);
                    assertEquals("twoWayHolder_str", webParamNames[0]);
                    assertEquals("twoWayHolder_int", webParamNames[1]);
                    // Check the lack of a WebResult annotation and the default values for
                    // SOAPBinding Style=DOCUMENT, Use=LITERAL, ParamStyle=WRAPPED
                    // Note that the SOAPBinding annotation is also not present and thus fully defaulted.
                    assertNull(((OperationDescriptionJava)operation).getAnnoWebResult());
                    assertEquals("return", operation.getResultName());
                    assertEquals("return", operation.getResultPartName());
                    assertEquals("", operation.getResultTargetNamespace());
                    assertFalse(operation.isResultHeader());
                }
            } else {
                fail("Wrong number of parameters returned");
            }
        }

        // Test for a one-way, void method with no parameters which also is not overloaded
        operations = endpointIntfDesc.getOperationForJavaMethod("oneWayVoid");
        assertNotNull(operations);
        assertEquals(operations.length, 1);
        assertEquals(operations[0].getJavaMethodName(), "oneWayVoid");
        String[] checkEmptyParams = operations[0].getJavaParameters();
        assertNotNull(checkEmptyParams);
        assertEquals(checkEmptyParams.length, 0);
        assertEquals(true, operations[0].isOneWay());
        // Check the lack of a WebResult annotation and the default values for
        // a ONE-WAY / VOID operation with a SOAPBinding Style=DOCUMENT, Use=LITERAL, ParamStyle=WRAPPED
        // Note that the SOAPBinding annotation is also not present and thus fully defaulted.
        assertNull(((OperationDescriptionJava)operations[0]).getAnnoWebResult());
        assertFalse(((OperationDescriptionJava)operations[0]).isWebResultAnnotationSpecified());
        assertFalse(operations[0].isOperationReturningResult());
        assertEquals(null, operations[0].getResultName());
        assertEquals(null, operations[0].getResultPartName());
        assertEquals(null, operations[0].getResultTargetNamespace());
        assertFalse(operations[0].isResultHeader());

        // Test two-way method for lack of OneWay annotation and WebResult annotation
        operations = endpointIntfDesc.getOperationForJavaMethod("invoke");
        assertNotNull(operations);
        assertEquals(1, operations.length);
        assertEquals(false, operations[0].isOneWay());
        assertNotNull(((OperationDescriptionJava)operations[0]).getAnnoWebResult());
        assertEquals("return_str", operations[0].getResultName());
        assertEquals("return_str", operations[0].getResultPartName());
        assertEquals("", operations[0].getResultTargetNamespace());
        assertFalse(operations[0].isResultHeader());
    }

    // ===========================================
    // The following tests use implementation classes defined below
    // in order to test various specific annotation settings
    // ===========================================

    public void testSOAPBindingDefault() {
        EndpointInterfaceDescription testEndpointInterfaceDesc =
                getEndpointInterfaceDesc(SOAPBindingDefaultTestImpl.class);

        assertNull(
                ((EndpointInterfaceDescriptionJava)testEndpointInterfaceDesc).getAnnoSoapBinding());
        assertEquals(javax.jws.soap.SOAPBinding.Style.DOCUMENT,
                     testEndpointInterfaceDesc.getSoapBindingStyle());
        assertEquals(javax.jws.soap.SOAPBinding.Use.LITERAL,
                     testEndpointInterfaceDesc.getSoapBindingUse());
        assertEquals(javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED,
                     testEndpointInterfaceDesc.getSoapBindingParameterStyle());

        OperationDescription operationDesc =
                testEndpointInterfaceDesc.getOperationForJavaMethod("echoString")[0];
        // Verify WebResult annotation default values for DOC/LIT/WRAPPED from a defaulted SOAPBinding
        assertNull(((OperationDescriptionJava)operationDesc).getAnnoWebResult());
        assertEquals("return", operationDesc.getResultName());
        assertEquals("return", operationDesc.getResultPartName());
        assertEquals("", operationDesc.getResultTargetNamespace());
        assertFalse(operationDesc.isResultHeader());

    }

    public void testSOAPBindingDocEncBare() {
        //verify that we throw an exception when SOAPBinding.Use == ENCODED is specified
        try {
            EndpointInterfaceDescription testEndpointInterfaceDesc =
                getEndpointInterfaceDesc(SOAPBindingDocEncBareTestImpl.class);
            fail("Should have caused exception");
        } catch (Exception e) {
            // Expected path, SOAPBinding.Use == ENCODED is not supported
        }
    }
    
    public void testSOAPBindingDocLitBare() {
        EndpointInterfaceDescription testEndpointInterfaceDesc =
                getEndpointInterfaceDesc(SOAPBindingDocLitBareTestImpl.class);

        assertNotNull(
                ((EndpointInterfaceDescriptionJava)testEndpointInterfaceDesc).getAnnoSoapBinding());
        assertEquals(javax.jws.soap.SOAPBinding.Style.DOCUMENT,
                     testEndpointInterfaceDesc.getSoapBindingStyle());
        assertEquals(javax.jws.soap.SOAPBinding.Use.LITERAL,
                     testEndpointInterfaceDesc.getSoapBindingUse());
        assertEquals(javax.jws.soap.SOAPBinding.ParameterStyle.BARE,
                     testEndpointInterfaceDesc.getSoapBindingParameterStyle());
    }

    public void testSOAPBindingMethodAnnotation() {
        // Verify that an impl without the method annotation uses the settings from the type
        EndpointInterfaceDescription testEndpointInterfaceDesc =
                getEndpointInterfaceDesc(SOAPBindingDocLitBareTestImpl.class);

        assertNotNull(
                ((EndpointInterfaceDescriptionJava)testEndpointInterfaceDesc).getAnnoSoapBinding());
        assertEquals(javax.jws.soap.SOAPBinding.Style.DOCUMENT,
                     testEndpointInterfaceDesc.getSoapBindingStyle());
        assertEquals(javax.jws.soap.SOAPBinding.Use.LITERAL,
                     testEndpointInterfaceDesc.getSoapBindingUse());
        assertEquals(javax.jws.soap.SOAPBinding.ParameterStyle.BARE,
                     testEndpointInterfaceDesc.getSoapBindingParameterStyle());

        OperationDescription operationDesc =
                testEndpointInterfaceDesc.getOperationForJavaMethod("echoString")[0];
        assertNotNull(operationDesc);
        assertNull(((OperationDescriptionJava)operationDesc).getAnnoSoapBinding());
        assertEquals(javax.jws.soap.SOAPBinding.Style.DOCUMENT,
                     operationDesc.getSoapBindingStyle());
        assertEquals(javax.jws.soap.SOAPBinding.Use.LITERAL, operationDesc.getSoapBindingUse());
        assertEquals(javax.jws.soap.SOAPBinding.ParameterStyle.BARE,
                     operationDesc.getSoapBindingParameterStyle());

        // Verify that the method annotation setting overrides the type annotatino setting
        testEndpointInterfaceDesc =
                getEndpointInterfaceDesc(SOAPBindingDefaultMethodTestImpl.class);

        assertNull(
                ((EndpointInterfaceDescriptionJava)testEndpointInterfaceDesc).getAnnoSoapBinding());
        assertEquals(javax.jws.soap.SOAPBinding.Style.DOCUMENT,
                     testEndpointInterfaceDesc.getSoapBindingStyle());
        assertEquals(javax.jws.soap.SOAPBinding.Use.LITERAL,
                     testEndpointInterfaceDesc.getSoapBindingUse());
        assertEquals(javax.jws.soap.SOAPBinding.ParameterStyle.WRAPPED,
                     testEndpointInterfaceDesc.getSoapBindingParameterStyle());

        operationDesc = testEndpointInterfaceDesc.getOperationForJavaMethod("echoString")[0];
        assertNotNull(operationDesc);
        assertNotNull(((OperationDescriptionJava)operationDesc).getAnnoSoapBinding());
        assertEquals(javax.jws.soap.SOAPBinding.Style.DOCUMENT,
                     operationDesc.getSoapBindingStyle());
        assertEquals(javax.jws.soap.SOAPBinding.Use.LITERAL, operationDesc.getSoapBindingUse());
        assertEquals(javax.jws.soap.SOAPBinding.ParameterStyle.BARE,
                     operationDesc.getSoapBindingParameterStyle());
    }

    public void testDefaultReqRspWrapper() {

        // Test paramaterStyle = WRAPPED set a the type level with various combinations of method annotation setting
        EndpointInterfaceDescription testEndpointInterfaceDesc =
                getEndpointInterfaceDesc(DefaultReqRspWrapperTestImpl.class);
        OperationDescription operationDesc =
                testEndpointInterfaceDesc.getOperationForJavaMethod("wrappedParams")[0];
        assertNotNull(operationDesc);
        assertEquals("wrappedParams", operationDesc.getRequestWrapperLocalName());
        assertEquals("wrappedParamsResponse", operationDesc.getResponseWrapperLocalName());
        assertEquals("http://description.jaxws.axis2.apache.org/",
                     operationDesc.getRequestWrapperTargetNamespace());
        assertEquals("http://description.jaxws.axis2.apache.org/",
                     operationDesc.getResponseWrapperTargetNamespace());
        assertNull(operationDesc.getRequestWrapperClassName());
        assertNull(operationDesc.getResponseWrapperClassName());
        // Test WebResult annotation defaults
        assertNull(((OperationDescriptionJava)operationDesc).getAnnoWebResult());
        assertFalse(((OperationDescriptionJava)operationDesc).isWebResultAnnotationSpecified());
        assertTrue(operationDesc.isOperationReturningResult());
        assertEquals("return", operationDesc.getResultName());
        assertEquals("return", operationDesc.getResultPartName());
        assertEquals("", operationDesc.getResultTargetNamespace());
        assertFalse(operationDesc.isResultHeader());

        operationDesc = testEndpointInterfaceDesc.getOperationForJavaMethod("bareParams")[0];
        assertNotNull(operationDesc);
        assertNull(operationDesc.getRequestWrapperLocalName());
        assertNull(operationDesc.getResponseWrapperLocalName());
        assertNull(operationDesc.getRequestWrapperTargetNamespace());
        assertNull(operationDesc.getResponseWrapperTargetNamespace());
        assertNull(operationDesc.getRequestWrapperClassName());
        assertNull(operationDesc.getResponseWrapperClassName());
        // Test WebResult annotation defaults

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?