*/
package org.sonar.server.activity;
-import org.apache.commons.io.IOUtils;
import org.assertj.core.data.MapEntry;
import org.junit.Before;
import org.junit.ClassRule;
import org.sonar.server.es.EsTester;
import org.sonar.server.issue.db.IssueDao;
-import java.sql.Clob;
import java.util.List;
import java.util.Map;
assertThat(dbMap).containsEntry("type", "ANALYSIS_REPORT");
assertThat(dbMap).containsEntry("action", "THE_ACTION");
assertThat(dbMap).containsEntry("msg", "THE_MSG");
- Clob data = (Clob) dbMap.get("data");
- assertThat(IOUtils.toString(data.getAsciiStream())).isEqualTo("foo=bar");
+ assertThat(dbMap.get("data")).isEqualTo("foo=bar");
List<ActivityDoc> docs = es.getDocuments("activities", "activity", ActivityDoc.class);
assertThat(docs).hasSize(1);
*/
package org.sonar.server.activity.db;
-import org.apache.commons.io.IOUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.sonar.core.persistence.DbTester;
import org.sonar.test.DbTests;
-import java.sql.Clob;
import java.sql.Timestamp;
import java.util.Map;
Map<String, Object> map = dbTester.selectFirst("select created_at as \"createdAt\", log_action as \"action\", data_field as \"data\" from activities where log_key='UUID_1'");
assertThat(map.get("action")).isEqualTo("THE_ACTION");
assertThat(((Timestamp)map.get("createdAt")).getTime()).isEqualTo(1_500_000_000_000L);
- Clob data = (Clob) map.get("data");
- assertThat(IOUtils.toString(data.getAsciiStream())).isEqualTo("THE_DATA");
+ assertThat(map.get("data")).isEqualTo("THE_DATA");
}
}
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
+import java.sql.Clob;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
return rows.get(0);
}
- private static List<Map<String, Object>> getHashMap(ResultSet resultSet) throws SQLException {
+ private static List<Map<String, Object>> getHashMap(ResultSet resultSet) throws Exception {
ResultSetMetaData metaData = resultSet.getMetaData();
int colCount = metaData.getColumnCount();
List<Map<String, Object>> rows = newArrayList();
while (resultSet.next()) {
Map<String, Object> columns = newHashMap();
for (int i = 1; i <= colCount; i++) {
- columns.put(metaData.getColumnLabel(i), resultSet.getObject(i));
+ Object value = resultSet.getObject(i);
+ if (value instanceof Clob) {
+ value = IOUtils.toString(((Clob)value).getAsciiStream());
+ }
+ columns.put(metaData.getColumnLabel(i), value);
}
rows.add(columns);
}