Commit f89bf8b3 authored by Nicolas Bailliet's avatar Nicolas Bailliet
Browse files

Commit after merge with trunk to integrate jar used by mocks

git-svn-id: https://scm.gforge.inria.fr/authscm/ycadoret/svn/gazelle/Maven/simulators/gazelle-webservice-tester/branches/gazelle-webservice-tester-nbt@67533 356b4b1a-1d2b-0410-8bf1-ffa24008f01e
parents 612bc9f7 cbdcc785
......@@ -33,6 +33,10 @@
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
......@@ -65,4 +69,4 @@
</build>
</project>
\ No newline at end of file
</project>
......@@ -19,14 +19,12 @@ class DAOModel {
* @return integer domain_id
* @throws java.sql.SQLException
*/
int getDomainId(String keyword) throws SQLException, NotUniqueException {
String SQL = "SELECT id from tf_domain where keyword = ?;";
int result = getSelectId(SQL, keyword);
int getOrCreateDomainId(String keyword) throws MessageException, SQLException {
String sql = "SELECT id from tf_domain where keyword = ?;";
int result = getSelectId(sql, keyword);
if (result == 0) {
String insert = "INSERT INTO tf_domain (id, description, keyword, name) VALUES (nextval('tf_domain_id_seq'), NULL, ?, ?);";
insertNewTf(insert, keyword);
result = getSelectId(SQL, keyword);
return result;
String insert = "INSERT INTO tf_domain (id, description, keyword, name) VALUES (nextval('tf_domain_id_seq'), NULL, ?, ?) returning id;";
return insertNewTf(insert, keyword);
} else {
return result;
}
......@@ -39,14 +37,12 @@ class DAOModel {
* @return integer transaction_id
* @throws java.sql.SQLException
*/
int getTransactionId(String keyword) throws SQLException, NotUniqueException {
String SQL = "SELECT id from tf_transaction where keyword = ?;";
int result = getSelectId(SQL, keyword);
int getOrCreateTransactionId(String keyword) throws MessageException, SQLException {
String sql = "SELECT id from tf_transaction where keyword = ?;";
int result = getSelectId(sql, keyword);
if (result == 0) {
String insert = "INSERT INTO tf_transaction (id, description, keyword, name) VALUES (nextval('tf_transaction_id_seq'), NULL, ?, ?);";
insertNewTf(insert, keyword);
result = getSelectId(SQL, keyword);
return result;
String insert = "INSERT INTO tf_transaction (id, description, keyword, name) VALUES (nextval('tf_transaction_id_seq'), NULL, ?, ?) returning id;";
return insertNewTf(insert, keyword);
} else {
return result;
}
......@@ -59,14 +55,12 @@ class DAOModel {
* @return integer actor_id
* @throws java.sql.SQLException
*/
int getActorId(String keyword) throws SQLException, NotUniqueException {
String SQL = "SELECT id from tf_actor where keyword = ?;";
int result = getSelectId(SQL, keyword);
int getOrCreateActorId(String keyword) throws MessageException, SQLException {
String sql = "SELECT id from tf_actor where keyword = ?;";
int result = getSelectId(sql, keyword);
if (result == 0) {
String insert = "INSERT INTO tf_actor (id, description, keyword, name) VALUES (nextval('tf_actor_id_seq'), NULL, ?, ?);";
insertNewTf(insert, keyword);
result = getSelectId(SQL, keyword);
return result;
String insert = "INSERT INTO tf_actor (id, description, keyword, name) VALUES (nextval('tf_actor_id_seq'), NULL, ?, ?) returning id;";
return insertNewTf(insert, keyword);
} else {
return result;
}
......@@ -79,20 +73,21 @@ class DAOModel {
* @return integer select id
* @throws java.sql.SQLException
*/
int getSelectId(String SQL, String keyword) throws SQLException, NotUniqueException {
int getSelectId(String sql, String keyword) throws MessageException, SQLException {
try (PreparedStatement st = connection.getConnection().prepareStatement(SQL)) {
try (PreparedStatement st = connection.getConnection().prepareStatement(sql)) {
st.setString(1, keyword);
try (ResultSet rs = st.executeQuery()) {
while (rs.next()) {
if (rs.isLast()) {
return rs.getInt("id");
} else {
throw new NotUniqueException("We have find several id with the same keyword");
throw new MessageException("We have found several id with the same keyword '" + keyword + "'");
}
}
return 0;
} catch (Exception e) {
throw new MessageException("An error occurred while searching the keyword '" + keyword + "'");
}
}
}
......@@ -103,52 +98,21 @@ class DAOModel {
*
* @throws java.sql.SQLException
*/
void insertNewTf(String SQL, String keyword) throws SQLException {
try (PreparedStatement st = connection.getConnection().prepareStatement(SQL)) {
int insertNewTf(String sql, String keyword) throws MessageException, SQLException {
int id = 0;
try (PreparedStatement st = connection.getConnection().prepareStatement(sql)) {
st.setString(1, keyword);
st.setString(2, keyword);
st.executeUpdate();
}
}
/**
* Get all id in the request table
*
* @return id request
* @throws java.sql.SQLException
*/
public int getRequestId(String address) throws SQLException, NotUniqueException {
String SQL = "SELECT MAX(ID) as id from cmn_message_instance where issuer_ip_address like ?;";
int result = getSelectId(SQL, address);
return result;
}
try (ResultSet resultSet = st.executeQuery()) {
if (resultSet.next()) {
id = (resultSet.getInt("id"));
}
return id;
/**
* Get all id in the response table
*
* @return id response
* @throws java.sql.SQLException
*/
public int getResponseId(String address) throws SQLException, NotUniqueException {
String SQL = "SELECT MAX(ID) as id from cmn_message_instance where issuer_ip_address like ?";
int result = getSelectId(SQL, address);
return result;
} catch (Exception e) {
throw new MessageException("An error occurred while adding the new keyword '" + keyword + "'");
}
}
}
......
package net.ihe.gazelle.wstester.mockrecord;
import java.sql.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
class DAOTransaction {
......@@ -35,64 +37,64 @@ class DAOTransaction {
/**
* insertRequest messages in table
*
* @throws SQLException
* @throws MessageException
*/
void insertRequest(Message message) throws SQLException, NotUniqueException {
void insertRequest(Message message) throws MessageException {
String SQL = "INSERT INTO cmn_message_instance (id, content, issuer, issuer_ip_address, type, validation_detailed_result, validation_status, issuing_actor) "
+ "VALUES (nextval('cmn_message_instance_id_seq'),?,?,?,?, null, null,?);";
DAOModel daoModel = new DAOModel(connection);
Connection conn = connection.getConnection();
try (PreparedStatement st = conn.prepareStatement(SQL)) {
st.setBytes(1, message.getContent());
st.setString(2, message.getIssuer());
st.setString(3, message.getIssuerIP());
st.setString(4, message.getMessageType());
st.setInt(5, daoModel.getActorId(message.getIssuingActor()));
st.executeUpdate();
try (Statement statement = conn.createStatement()) {
try (ResultSet generatedKeys = statement.executeQuery("SELECT MAX(id) as id from cmn_message_instance;")) {
if (generatedKeys.next()) {
this.setRequestId(generatedKeys.getInt("id"));
+ "VALUES (nextval('cmn_message_instance_id_seq'),?,?,?,?, null, null,?) returning id;";
try {
DAOModel daoModel = new DAOModel(connection);
Connection conn = connection.getConnection();
try (PreparedStatement st = conn.prepareStatement(SQL)) {
st.setBytes(1, message.getContent());
st.setString(2, message.getIssuer());
st.setString(3, message.getIssuerIP());
st.setString(4, message.getMessageType());
st.setInt(5, daoModel.getOrCreateActorId(message.getIssuingActor()));
try (ResultSet resultSet = st.executeQuery()) {
if (resultSet.next()) {
this.setRequestId(resultSet.getInt("id"));
}
}
}
} catch (Exception e) {
throw new MessageException("An error occurred while recording the request message");
}
}
/**
* insert Response messages in table
*
* @throws SQLException
* @throws MessageException
*/
void insertResponse(Message message) throws SQLException, NotUniqueException {
void insertResponse(Message message) throws MessageException {
String SQL = "INSERT INTO cmn_message_instance (id, content, issuer, issuer_ip_address, type, validation_detailed_result, validation_status, issuing_actor) "
+ "VALUES (nextval('cmn_message_instance_id_seq'),?,?,?,?, null, null,?);";
DAOModel daoModel = new DAOModel(connection);
Connection conn = connection.getConnection();
try (PreparedStatement st = conn.prepareStatement(SQL)) {
st.setBytes(1, message.getContent());
st.setString(2, message.getIssuer());
st.setString(3, message.getIssuerIP());
st.setString(4, message.getMessageType());
st.setInt(5, daoModel.getActorId(message.getIssuingActor()));
st.executeUpdate();
try (Statement statement = conn.createStatement()) {
try (ResultSet generatedKeys = statement.executeQuery("SELECT MAX(id) as id from cmn_message_instance;")) {
if (generatedKeys.next()) {
this.setResponseId(generatedKeys.getInt("id"));
+ "VALUES (nextval('cmn_message_instance_id_seq'),?,?,?,?, null, null,?) returning id;";
try {
DAOModel daoModel = new DAOModel(connection);
Connection conn = connection.getConnection();
try (PreparedStatement st = conn.prepareStatement(SQL)) {
st.setBytes(1, message.getContent());
st.setString(2, message.getIssuer());
st.setString(3, message.getIssuerIP());
st.setString(4, message.getMessageType());
st.setInt(5, daoModel.getOrCreateActorId(message.getIssuingActor()));
try (ResultSet resultSet = st.executeQuery()) {
if (resultSet.next()) {
this.setResponseId(resultSet.getInt("id"));
}
}
}
} catch (Exception e) {
throw new MessageException("An error occurred while recording the response message");
}
}
......@@ -100,26 +102,33 @@ class DAOTransaction {
/**
* insert transaction in table
*
* @throws java.sql.SQLException
* @throws MessageException
*/
void insertTransactionInstance(Transaction transaction) throws SQLException, NotUniqueException {
void insertTransactionInstance(Transaction transaction) throws MessageException {
this.insertRequest(transaction.getRequest());
this.insertResponse(transaction.getResponse());
String SQL = "INSERT INTO cmn_transaction_instance (id, company_keyword, standard, timestamp, is_visible, domain_id, request_id, response_id, simulated_actor_id, transaction_id) "
+ "VALUES (nextval('cmn_transaction_instance_id_seq'), null, ?, ?, ?, ?, ?, ?, ?, ? );";
try {
DAOModel daoModel = new DAOModel(connection);
Connection conn = connection.getConnection();
try (PreparedStatement st = conn.prepareStatement(SQL)) {
st.setString(1, transaction.getStandard().name());
st.setTimestamp(2, transaction.getTimestamp());
st.setBoolean(3, true);
st.setInt(4, daoModel.getOrCreateDomainId(transaction.getDomainKeyword()));
st.setInt(5, this.getRequestId());
st.setInt(6, this.getResponseId());
st.setInt(7, daoModel.getOrCreateActorId(transaction.getSimulatedActorKeyword()));
st.setInt(8, daoModel.getOrCreateTransactionId(transaction.getTransactionKeyword()));
st.executeUpdate();
DAOModel daoModel = new DAOModel(connection);
Connection conn = connection.getConnection();
try (PreparedStatement st = conn.prepareStatement(SQL)) {
st.setString(1, transaction.getStandard());
st.setTimestamp(2, transaction.getTimestamp());
st.setBoolean(3, true);
st.setInt(4, daoModel.getDomainId(transaction.getDomainKeyword()));
st.setInt(5, this.getRequestId());
st.setInt(6, this.getResponseId());
st.setInt(7, daoModel.getActorId(transaction.getSimulatedActorKeyword()));
st.setInt(8, daoModel.getTransactionId(transaction.getTransactionKeyword()));
st.executeUpdate();
}
} catch (Exception e) {
throw new MessageException("An error occurred while recording the transaction");
}
}
......
package net.ihe.gazelle.wstester.mockrecord;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
......@@ -17,18 +16,21 @@ public class MessageRecorder {
this.passwordDB = passwordDB;
}
public void record(String standardKeyword, String transactionKeyword, String domainKeyword, String simulatedActorKeyword, Message request, Message response) throws SQLException, NotUniqueException {
public void record(EStandard standardKeyword, String transactionKeyword, String domainKeyword, String simulatedActorKeyword, Message request, Message response) throws MessageException {
Date date = new Date();
Timestamp timestamp = new Timestamp(date.getTime());
DBConnection dbConnection = new DBConnection(urlDB, userDB, passwordDB);
try {
Date date = new Date();
Timestamp timestamp = new Timestamp(date.getTime());
DBConnection dbConnection = new DBConnection(urlDB, userDB, passwordDB);
DAOTransaction daoTransaction = new DAOTransaction(dbConnection);
Transaction transaction = new Transaction(standardKeyword, timestamp, domainKeyword, simulatedActorKeyword, transactionKeyword, request, response);
daoTransaction.insertTransactionInstance(transaction);
dbConnection.close();
DAOTransaction daoTransaction = new DAOTransaction(dbConnection);
Transaction transaction = new Transaction(standardKeyword, timestamp, domainKeyword, simulatedActorKeyword, transactionKeyword, request, response);
} catch (Exception e) {
daoTransaction.insertRequest(request);
daoTransaction.insertResponse(response);
daoTransaction.insertTransactionInstance(transaction);
throw new MessageException("An error occurred while inserting the transaction");
}
}
......
......@@ -5,7 +5,7 @@ import java.sql.Timestamp;
class Transaction {
private String standard;
private EStandard standard;
private Timestamp timestamp;
private String domainKeyword;
private String simulatedActorKeyword;
......@@ -14,7 +14,7 @@ class Transaction {
private Message response;
Transaction(String standard, Timestamp timestamp, String domainKeyword, String simulatedActorKeyword, String transactionKeyword, Message request, Message response) {
Transaction(EStandard standard, Timestamp timestamp, String domainKeyword, String simulatedActorKeyword, String transactionKeyword, Message request, Message response) {
this.standard = standard;
this.timestamp = timestamp;
this.domainKeyword = domainKeyword;
......@@ -25,7 +25,7 @@ class Transaction {
}
String getStandard() {
EStandard getStandard() {
return standard;
}
......
package net.ihe.gazelle.wstester.mockrecord;
import org.junit.Assert;
import org.junit.Test;
import java.sql.Timestamp;
import java.util.Date;
public class MessageRecorderTest {
@Test
public void recordMessageTest() throws Exception {
DBConnection dbConnection = new DBConnection("jdbc:postgresql://localhost:5432/gazelle-webservice-tester", "gazelle", "gazelle");
DAOTransaction daoTransaction = new DAOTransaction(dbConnection);
Message request = new Message("Consumer", "127.0.0.1", "SubmitObjectsRequest", "Consumer", null);
Assert.assertEquals("Consumer", request.getIssuer());
Assert.assertEquals("Consumer", request.getIssuingActor());
Assert.assertEquals("127.0.0.1", request.getIssuerIP());
Assert.assertEquals("SubmitObjectsRequest", request.getMessageType());
Assert.assertEquals(null, request.getContent());
}
@Test
public void recordTransactionTest() throws Exception {
DBConnection dbConnection = new DBConnection("jdbc:postgresql://localhost:5432/gazelle-webservice-tester", "gazelle", "gazelle");
DAOTransaction daoTransaction = new DAOTransaction(dbConnection);
Date date = new Date();
Timestamp ts = new Timestamp(date.getTime());
Message request = new Message("Consumer", "127.0.0.1", "SubmitObjectsRequest", "Consumer", null);
Message response = new Message("Provider", "soapui mock", "RegistryResponse", "Provider", null);
Transaction transaction = new Transaction("application/soap+xml", ts, "UNKNOWN", "simulatedActorKeyword", "ITI", request, response);
Assert.assertEquals("application/soap+xml", transaction.getStandard());
Assert.assertEquals("UNKNOWN", transaction.getDomainKeyword());
Assert.assertEquals("simulatedActorKeyword", transaction.getSimulatedActorKeyword());
Assert.assertEquals("ITI", transaction.getTransactionKeyword());
}
// /**
// * TEST
// *
// * @throws java.sql.SQLException
// */
// public static void main(String args[]) throws SQLException, NotUniqueException {
//
// DBConnection dbConnection = new DBConnection("jdbc:postgresql://localhost:5432/gazelle-webservice-tester", "gazelle", "gazelle");
// DAOTransaction daoTransaction = new DAOTransaction(dbConnection);
//
// Date date = new Date();
// Timestamp ts = new Timestamp(date.getTime());
//
// Message request = new Message("Test", "127.0.0.1", "soap:Fault", "test", null);
// Message response = new Message("Test", "soap mock", "soap:Fault", "test", null);
//
// Transaction transaction = new Transaction("standardKeyword", ts, "", "simulatedActorKeyword", "transactionKeyword", request, response);
//
// daoTransaction.insertRequest(request);
// daoTransaction.insertResponse(response);
// daoTransaction.insertTransactionInstance(transaction);
//
// }
}
......@@ -140,6 +140,11 @@
<version>3.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
</dependencyManagement>
......@@ -263,4 +268,4 @@
<module>gazelle-webservice-tester-ear</module>
<module>gwt-message-recording-for-mock</module>
</modules>
</project>
\ No newline at end of file
</project>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment