Skip to content

Commit

Permalink
#414 Re-enable testIti56 testcase
Browse files Browse the repository at this point in the history
* side note: Logging must be disabled, otherwise jetty throws a failure
  • Loading branch information
Thopap committed Jul 23, 2024
1 parent 560aa98 commit 84c8591
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import static org.openehealth.ipf.platform.camel.ihe.hl7v3.PixPdqV3CamelValidato
*/
class Iti56TestRouteBuilder extends RouteBuilder {

static final AtomicInteger responseCount = new AtomicInteger()
static final AtomicInteger responseCount = new AtomicInteger()
static final AtomicInteger asyncResponseCount = new AtomicInteger()

static final String RESPONSE = StandardTestContainer.readFile('iti56/iti56-sample-response.xml')

final CountDownLatch countDownLatch, asyncCountDownLatch
Expand All @@ -45,15 +45,13 @@ class Iti56TestRouteBuilder extends RouteBuilder {
countDownLatch = new CountDownLatch(TASKS_COUNT)
asyncCountDownLatch = new CountDownLatch(TASKS_COUNT)
}

@Override
public void configure() throws Exception {

// receiver of asynchronous responses
from('xcpd-iti56-async-response:iti56service-response' +
'?correlator=#correlator' +
'&inInterceptors=#inLogInterceptor' +
'&outInterceptors=#outLogInterceptor')
'?correlator=#correlator')
.process(iti56ResponseValidator())
.process {
if (! it.in.body.contains('<soap:Fault')) {
Expand All @@ -66,9 +64,7 @@ class Iti56TestRouteBuilder extends RouteBuilder {


// responding route
from('xcpd-iti56:iti56service' +
'?inInterceptors=#inLogInterceptor' +
'&outInterceptors=#outLogInterceptor')
from('xcpd-iti56:iti56service')
.process(iti56RequestValidator())
.process {
it.message.body = RESPONSE
Expand All @@ -79,9 +75,7 @@ class Iti56TestRouteBuilder extends RouteBuilder {


// responding route for testing errors
from('xcpd-iti56:iti56service-error' +
'?inInterceptors=#inLogInterceptor' +
'&outInterceptors=#outLogInterceptor')
from('xcpd-iti56:iti56service-error')
.throwException(new RuntimeException("abcd"))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
* Copyright 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.
Expand All @@ -20,7 +20,6 @@ import org.apache.camel.support.DefaultExchange
import org.apache.cxf.binding.soap.SoapFault
import org.apache.cxf.transport.servlet.CXFServlet
import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.MethodOrderer
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestMethodOrder
Expand All @@ -37,27 +36,27 @@ import java.util.concurrent.TimeUnit
@DirtiesContext
@TestMethodOrder(MethodOrderer.MethodName)
class TestIti56 extends HL7v3StandardTestContainer {

def static CONTEXT_DESCRIPTOR = 'iti56/iti-56.xml'
final String SERVICE1_URI = "xcpd-iti56://localhost:${port}/iti56service?correlator=#correlator"
final String SERVICE1_RESPONSE_URI = "http://localhost:${port}/iti56service-response"
final String SERVICE_URI_ERROR = "xcpd-iti56://localhost:${port}/iti56service-error?correlator=#correlator"

final String SERVICE1_URI = "xcpd-iti56://localhost:${port}/iti56service?correlator=#correlator"
final String SERVICE1_RESPONSE_URI = "http://localhost:${port}/iti56service-response"
final String SERVICE_URI_ERROR = "xcpd-iti56://localhost:${port}/iti56service-error?correlator=#correlator"

static final String REQUEST = readFile('iti56/iti56-sample-request.xml')

static final long AWAIT_DELAY = 20 * 1000L

static void main(args) {
startServer(new CXFServlet(), CONTEXT_DESCRIPTOR, false, DEMO_APP_PORT)
}

@BeforeAll
static void setUpClass() {
startServer(new CXFServlet(), CONTEXT_DESCRIPTOR)
}


/**
* Test whether:
* <ol>
Expand All @@ -70,11 +69,11 @@ class TestIti56 extends HL7v3StandardTestContainer {
* <li> ATNA auditing works.
* </ol>
*/
@Test @Disabled
@Test
void testIti56() {
final int N = Iti56TestRouteBuilder.TASKS_COUNT
int i = 0

N.times {
send(SERVICE1_URI, i++, SERVICE1_RESPONSE_URI)
send(SERVICE1_URI, i++)
Expand All @@ -88,11 +87,11 @@ class TestIti56 extends HL7v3StandardTestContainer {

assert Iti56TestRouteBuilder.responseCount.get() == N * 2
assert Iti56TestRouteBuilder.asyncResponseCount.get() == N

assert auditSender.messages.size() == N * 4
}


@Test
void testWithErrorSync() {
def requestExchange = new DefaultExchange(camelContext)
Expand All @@ -101,8 +100,8 @@ class TestIti56 extends HL7v3StandardTestContainer {
assert responseExchange.exception instanceof SoapFault
assert responseExchange.exception.message == 'abcd'
}


@Test
void testWithErrorAsync() {
def requestExchange = new DefaultExchange(camelContext)
Expand All @@ -112,29 +111,29 @@ class TestIti56 extends HL7v3StandardTestContainer {
assert responseExchange.exception == null
assert responseExchange.pattern == ExchangePattern.InOnly
}


private static void send(
String endpointUri,
int n,
String responseEndpointUri = null)
{
def requestExchange = new DefaultExchange(camelContext)
requestExchange.in.body = REQUEST

// set WSA ReplyTo header, when necessary
if (responseEndpointUri) {
requestExchange.in.headers[AbstractWsEndpoint.WSA_REPLYTO_HEADER_NAME] = responseEndpointUri
}

// set correlation key
requestExchange.in.headers[AbstractWsEndpoint.CORRELATION_KEY_HEADER_NAME] = "corr ${n}"

// send and check timing
long startTimestamp = System.currentTimeMillis()
def resultMessage = producerTemplate.send(endpointUri, requestExchange).message
// TODO: reactivate test
//assert (System.currentTimeMillis() - startTimestamp < Iti55TestRouteBuilder.ASYNC_DELAY)
}

}

0 comments on commit 84c8591

Please sign in to comment.