JUnit Service Test

For how to use the wizard, refer to the New JUnit Service Test page.

1. JUnit Test Code

The code generated by the New JUnit service test wizard is as follows.

Methods annotated with @Test are test methods that can test individual operations. As many test methods are generated as the number of operations selected in the wizard.

The remaining methods are those executed before/after the test or when an error occurs.

The generated code may vary depending on the project environment.

@DisplayName("Test for 'Service example'")
public class TestMyService
extends JUnitServiceTestSupport<DefaultSystemHeader>
{
    /**
     * {@link test.bxm.service.MyService#sbxm0001a0001a(MyServiceIn)}
     */
    @DisplayName("operation 1")
    @Test
    void testSbxm0001a0001a()
    {
        // TODO Set required header values
        setHeaderValue("recvSvcC", "SBXM0001A001"); /*Receiving service code*/
        setHeaderValue("rqstRespG", "S"); /*Request/Response Distinction*/

        // TODO Creating input instances and setting field values
        MyServiceIn input= new MyServiceIn();
        //input.setName(""); //
        //input.setId(""); //
        //input.setDeptNo(new BigDecimal("0")); //

        try{
            // TODO Set Expected Value: Set the expected value of the test result.
            MyServiceOut expected= new MyServiceOut();

            // Run
            TestResult<DefaultSystemHeader, MyServiceOut> result= doTest(input);

            MyServiceOut actual= result.getResult();

            // Result output
            logger.debug("Output = {}", actual);

            // Compare results
            assertEquals(expected, actual);
        }
        catch(Exception e){
            // Failed test
            logger.error(e.getMessage());
            fail(e.getMessage());
        }
    }

    @Override
    protected String getDefaultEndpointURL() {
        return "http://yourIP:yourPort/serviceEndpoint/httpService/request.obj";
    }

    @Override
    protected void beforeTest(
            URL endpointURL
            , DefaultSystemHeader header
            , IOmmObject optionHeader1
            , IOmmObject optionHeader2
            , IOmmObject optionHeader3
            , IOmmObject input
            )
    {
        // TODO Describe what you want to do before testing.
    }

    @Override
    protected void afterTest(
            TestResult<DefaultSystemHeader, IOmmObject> testResult
            )
    {
        // TODO If the test is successful, describe what you want to do.
    }

    @Override
    protected void catchMalformedEndpointURLError(
        String endpointURL
        , Throwable e
        )
    {
        // TODO Describe what to do when a malformed URL is used.
    }

    @Override
    protected void catchInvalidEndpointURLError(
        URL endpointURL
        )
    {
        // TODO Describe what to do when the wrong URL or data can not be read from the remote location.
    }

    @Override
    protected void catchPlatformError(
            DefaultSystemHeader header
            , IOmmObject optionHeader1
            , IOmmObject optionHeader2
            , IOmmObject optionHeader3
            , IOmmObject input
            , DefaultSystemHeader responseHeader
            )
    {
        // TODO Describe what to do when a platform error occurs.
    }

    @Override
    protected void catchServiceError(
            DefaultSystemHeader header
            , IOmmObject optionHeader1
            , IOmmObject optionHeader2
            , IOmmObject optionHeader3
            , IOmmObject input
            , DefaultSystemHeader responseHeader
            )
    {
        // TODO Describe what to do when a service error occurs.
    }

    @Override
    protected void catchUnknownError(
            DefaultSystemHeader header
            , IOmmObject optionHeader1
            , IOmmObject optionHeader2
            , IOmmObject optionHeader3
            , IOmmObject input
            , Throwable cause
            )
    {
        // TODO Describe what to do when an unknown error occurs.
    }

    @Override
    protected Class<DefaultSystemHeader> getHeaderClass() {
        return DefaultSystemHeader.class;
    }
}

2. Executing the Test

You can test the created test code by using JUnit Test.

Executing the test

  1. Right-click the source code → Run AS → select 'JUnit Test'.

    When the test is executed, you can check the result as shown in the figure below.

    Checking the test

SWLab Bankware Global
  • 전체
  • BXM
  • BXCM
  • BXCP
  • BXI
제품 선택 시 더 정확한 매뉴얼 가이드를 제공해드립니다.

Copyright© Bankwareglobal All Rights Reserved.