* Evaluation article: Different Types of Bean Injection in Spring * added tests & changed configuration to Java-based config * removed xml config files * rename unit tests * BAEL-972 - Apache Commons Text * remove code from evaluation article * remove code from evaluation article * BAEL-972 - Apache Commons Text - added another example * BAEL-972 - Apache Commons Text - just indentation * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java - fix problems * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * fix formatting * BAEL-1033 minor refactor * BAEL-1035 Introduction to Eclipse Collections * format * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * cleanup * cleanup * BAEL-1109 Introduction to JCache * BAEL-1109 Introduction to JCache * remove unneeded property in pom.xml * fix formatting * close cache instances properly * remove latest commit * BAEL-1057 Introduction to rxjava-jdbc
68 lines
2.1 KiB
Java
68 lines
2.1 KiB
Java
package com.baeldung.rxjava.jdbc;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import java.io.FileInputStream;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
import org.junit.After;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
import com.github.davidmoten.rx.jdbc.ConnectionProvider;
|
|
import com.github.davidmoten.rx.jdbc.ConnectionProviderFromUrl;
|
|
import com.github.davidmoten.rx.jdbc.Database;
|
|
|
|
import rx.Observable;
|
|
|
|
public class InsertClobTest {
|
|
|
|
private String DB_CONNECTION = Connector.DB_CONNECTION;
|
|
private String DB_USER = Connector.DB_USER;
|
|
private String DB_PASSWORD = Connector.DB_PASSWORD;
|
|
|
|
ConnectionProvider cp = new ConnectionProviderFromUrl(DB_CONNECTION, DB_USER, DB_PASSWORD);
|
|
Database db = Database.from(cp);
|
|
|
|
String expectedDocument = null;
|
|
String actualDocument = null;
|
|
|
|
Observable<Integer> create, insert = null;
|
|
|
|
@Before
|
|
public void setup() throws IOException {
|
|
create = db.update("CREATE TABLE IF NOT EXISTS SERVERLOG (id int primary key, document CLOB)")
|
|
.count();
|
|
|
|
InputStream actualInputStream = new FileInputStream("src/test/resources/actual_clob");
|
|
this.actualDocument = Utils.getStringFromInputStream(actualInputStream);
|
|
|
|
InputStream expectedInputStream = new FileInputStream("src/test/resources/expected_clob");
|
|
this.expectedDocument = Utils.getStringFromInputStream(expectedInputStream);
|
|
this.insert = db.update("insert into SERVERLOG(id,document) values(?,?)")
|
|
.parameter(1)
|
|
.parameter(Database.toSentinelIfNull(actualDocument))
|
|
.dependsOn(create)
|
|
.count();
|
|
}
|
|
|
|
@Test
|
|
public void whenSelectCLOB_thenCorrect() throws IOException {
|
|
db.select("select document from SERVERLOG where id = 1")
|
|
.dependsOn(create)
|
|
.dependsOn(insert)
|
|
.getAs(String.class)
|
|
.toList()
|
|
.toBlocking()
|
|
.single();
|
|
assertEquals(expectedDocument, actualDocument);
|
|
}
|
|
|
|
@After
|
|
public void close() {
|
|
db.update("DROP TABLE SERVERLOG")
|
|
.dependsOn(create);
|
|
cp.close();
|
|
}
|
|
} |