Skip to content

Commit

Permalink
(citrusframework/citrus-db#28) Added blob integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
svettwer committed Mar 27, 2019
1 parent 0dedc74 commit 8ee4c03
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
import com.consol.citrus.jdbc.message.JdbcMessage;
import com.consol.citrus.jdbc.server.JdbcServer;
import com.consol.citrus.message.MessageType;
import org.springframework.core.io.ClassPathResource;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import java.io.IOException;
import java.sql.Blob;
import java.sql.CallableStatement;
import java.sql.Clob;
import java.sql.Connection;
Expand Down Expand Up @@ -319,4 +322,52 @@ public void doExecute(final TestContext context) {
"</row>" +
"</dataset>"));
}

@CitrusTest
public void testBlobIntegration() throws IOException {

//GIVEN
final String sql = "{? = CALL someClobFunction(?)}";
final ClassPathResource blobRequestValue = new ClassPathResource("jdbc/RequestBlob.pdf");
final ClassPathResource blobReturnValue = new ClassPathResource("jdbc/ResponseBlob.pdf");


//WHEN + THEN
async().actions(new AbstractTestAction() {
@Override
public void doExecute(final TestContext context) {
try {
final Connection connection = jdbcDriver.connect(serverUrl, new Properties());
Assert.assertNotNull(connection);
try(final PreparedStatement statement = connection.prepareStatement(sql)){

statement.setBinaryStream(1, blobRequestValue.getInputStream());
statement.execute();

final ResultSet resultSet = statement.getResultSet();
resultSet.next();

final Blob responseBlob = resultSet.getBlob(1);

assertEquals(blobReturnValue.getInputStream(), responseBlob.getBinaryStream());
}
} catch (final SQLException | AssertionError | IOException e) {
throw new CitrusRuntimeException(e);
}
}
}
);

receive(jdbcServer)
.message(JdbcMessage.execute("{? = CALL someClobFunction(?)} - ("+blobRequestValue+")"));

send(jdbcServer)
.messageType(MessageType.XML)
.message(JdbcMessage.success().dataSet("" +
"<dataset>" +
"<row>" +
"<RETURN_BLOB>"+blobReturnValue.getInputStream()+"</RETURN_BLOB>"+
"</row>" +
"</dataset>"));
}
}
Binary file not shown.
Binary file not shown.

0 comments on commit 8ee4c03

Please sign in to comment.