Commit 73fa72f6 authored by Nicolas Bailliet's avatar Nicolas Bailliet
Browse files

Mock messages functionalities added [GWT-122]

git-svn-id: https://scm.gforge.inria.fr/authscm/ycadoret/svn/gazelle/Maven/simulators/gazelle-webservice-tester/branches/gazelle-webservice-tester-nbt@67434 356b4b1a-1d2b-0410-8bf1-ffa24008f01e
parent 83905b5e
......@@ -4,7 +4,7 @@
<parent>
<artifactId>gazelle-webservice-tester</artifactId>
<groupId>net.ihe.gazelle</groupId>
<version>1.6.0-SNAPSHOT</version>
<version>1.6.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
......@@ -45,7 +45,7 @@
<dependency>
<groupId>net.ihe.gazelle</groupId>
<artifactId>gazelle-evsclient-connector</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.3.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.ihe.gazelle.simulators</groupId>
......@@ -180,13 +180,10 @@
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>apache-log4j</groupId>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
<dependency>
<groupId>net.ihe.gazelle.maven</groupId>
<artifactId>GazelleTRMClient</artifactId>
......
......@@ -21,7 +21,11 @@ public enum Pages implements Page {
CONFORMANCE_TOOL("", null, "Conformance tool", Authorizations.ADMIN),
OPTION("/administration/conformanceTool/option.seam", null, "Manage option", Authorizations.ADMIN),
ACTOR_TYPE("/administration/conformanceTool/actorType.seam", null, "Manage actor type", Authorizations.ADMIN),
PROFILE("/administration/conformanceTool/profile.seam", null, "Manage profile", Authorizations.ADMIN);
PROFILE("/administration/conformanceTool/profile.seam", null, "Manage profile", Authorizations.ADMIN),
MOCK_BROWSER("/mock/mockMessageBrowser.seam", null, "Mock Browser", Authorizations.LOGGED),
MOCK_DISPLAY("/mock/mockMessageDisplay.seam", null, "Mock Message", Authorizations.LOGGED);
private String link;
private String icon;
......
......@@ -35,4 +35,23 @@ public class DownloadFile {
LOG.error(msg, e);
}
}
public static void downloadMessage(byte[] content, String fileName) {
try {
HttpServletResponse response = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext()
.getResponse();
ServletOutputStream servletOutputStream = response.getOutputStream();
response.setContentType("text/xml");
response.setContentLength(content.length);
response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
servletOutputStream.write(content);
servletOutputStream.flush();
servletOutputStream.close();
FacesContext.getCurrentInstance().responseComplete();
} catch (IOException e) {
String msg = "Failed to download file";
FacesMessages.instance().add(StatusMessage.Severity.ERROR, msg, e);
LOG.error(msg, e);
}
}
}
......@@ -48,6 +48,7 @@
<artifactId>gazelle-plugins</artifactId>
<configuration>
<ignoredParamNames>
<ignoredParamName>callEVSClient</ignoredParamName>
</ignoredParamNames>
</configuration>
</plugin>
......
......@@ -29,6 +29,8 @@
jndi-name="java:app/version/VersionProvider"/>
<component name="ValueSetCheckerImpl"
class="net.ihe.gazelle.simulator.ws.ValueSetCheckerImpl" jndi-name="java:app/simulator-common-ejb/ValueSetCheckerImpl"/>
<component name="testReportImpl" class="net.ihe.gazelle.simulator.ws.TestReportImpl"
jndi-name="java:app/simulator-common-ejb/TestReportImpl" />
<core:init debug="false" jndi-pattern="java:app/gazelle-webservice-tester/#{ejbName}/local"/>
......
......@@ -187,7 +187,7 @@
<rich:dataTable value="#{executionResult.execution.testStepResults}"
var="testStepResult">
<g:column>
<ui:define name="header">Transaction (TestSuite / TestCase / TestStep)</ui:define>
<ui:define name="header">TransactionF (TestSuite / TestCase / TestStep)</ui:define>
<a4j:commandLink onclick="changeWindowPosition()">
<rich:toggleControl event="click" targetPanel="panel1"
targetItem="#{testStepResult.id}"/>
......
......@@ -17,4 +17,9 @@
<h:outputText value="Run"/>
</h:outputLink>
</li>
<li>
<h:outputLink value="/gazelle-webservice-tester/mock/mockMessageBrowser.seam" rendered="#{identity.loggedIn}">
<h:outputText value="Mock Messages"/>
</h:outputLink>
</li>
</ui:composition>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>gazelle-webservice-tester</artifactId>
<groupId>net.ihe.gazelle</groupId>
<version>1.6.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>gwt-message-recording-for-mock</artifactId>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.1.jre7</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
\ No newline at end of file
package net.ihe.gazelle.wstester.mockrecord;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
class DAOModel {
private DBConnection connection;
DAOModel(DBConnection connection) {
this.connection = connection;
}
/**
* Get id of the tf_domain
*
* @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);
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;
} else {
return result;
}
}
/**
* Get id of the tf_transaction
*
* @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);
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;
} else {
return result;
}
}
/**
* Get id of the tf_actor
*
* @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);
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;
} else {
return result;
}
}
/**
* Get id with select request
*
* @return integer select id
* @throws java.sql.SQLException
*/
int getSelectId(String SQL, String keyword) throws SQLException, NotUniqueException {
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");
}
}
return 0;
}
}
}
/**
* Insert new domain, transaction or actor
*
* @throws java.sql.SQLException
*/
void insertNewTf(String SQL, String keyword) throws SQLException {
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;
}
/**
* 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;
}
}
package net.ihe.gazelle.wstester.mockrecord;
import java.sql.*;
class DAOTransaction {
private DBConnection connection;
private int requestId;
private int responseId;
DAOTransaction(DBConnection connection) {
this.connection = connection;
}
private int getRequestId() {
return requestId;
}
private void setRequestId(int requestId) {
this.requestId = requestId;
}
private int getResponseId() {
return responseId;
}
private void setResponseId(int responseId) {
this.responseId = responseId;
}
/**
* insertRequest messages in table
*
* @throws SQLException
*/
void insertRequest(Message message) throws SQLException, NotUniqueException {
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"));
}
}
}
}
}
/**
* insert Response messages in table
*
* @throws SQLException
*/
void insertResponse(Message message) throws SQLException, NotUniqueException {
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"));
}
}
}
}
}
/**
* insert transaction in table
*
* @throws java.sql.SQLException
*/
void insertTransactionInstance(Transaction transaction) throws SQLException, NotUniqueException {
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, ?, ?, ?, ?, ?, ?, ?, ? );";
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();
}
}
}
package net.ihe.gazelle.wstester.mockrecord;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
class DBConnection {
private String url;
private String user;
private String password;
private Connection connection;
DBConnection(String url, String user, String password) {
this.url = url;
this.user = user;
this.password = password;
}
void connect() throws SQLException {
connection = DriverManager.getConnection(url, user, password);
}
void close() throws SQLException {
getConnection().close();
}
Connection getConnection() throws SQLException {
if (connection == null) {
connect();
}
return connection;
}
}
package net.ihe.gazelle.wstester.mockrecord;
public class Message {
private String issuer;
private String issuerIP;
private String messageType;
private String issuingActor;
private byte[] content;
public Message(String issuer, String issuerIP, String messageType, String issuingActor, byte[] content) {
this.issuer = issuer;
this.issuerIP = issuerIP;
this.messageType = messageType;
this.issuingActor = issuingActor;
this.content = content;
}
public String getIssuer() {
return issuer;
}
public String getIssuerIP() {
return issuerIP;
}
public String getMessageType() {
return messageType;
}
public String getIssuingActor() {
return issuingActor;
}
public byte[] getContent() {
return content;
}
}
package net.ihe.gazelle.wstester.mockrecord;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
public class MessageRecorder {
private String urlDB;
private String userDB;
private String passwordDB;
public MessageRecorder(String urlDB, String userDB, String passwordDB) {
this.urlDB = urlDB;
this.userDB = userDB;
this.passwordDB = passwordDB;
}
public void record(String standardKeyword, String transactionKeyword, String domainKeyword, String simulatedActorKeyword, Message request, Message response) throws SQLException, NotUniqueException {
Date date = new Date();
Timestamp timestamp = new Timestamp(date.getTime());