Skip to content

Commit

Permalink
Merge pull request #18 from vertex-github/master
Browse files Browse the repository at this point in the history
Add tests for INSERT and UPDATE on PreparedStatement.executeUpdate()
  • Loading branch information
lvca committed Feb 12, 2015
2 parents f652d00 + 03d4e94 commit d660396
Showing 1 changed file with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.orientechnologies.orient.jdbc;

import org.junit.Test;
import org.junit.*;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
Expand All @@ -9,9 +9,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class OrientJdbcPreparedStatementTest extends OrientJdbcBaseTest {

Expand Down Expand Up @@ -46,7 +44,31 @@ public void shouldExectuteSelectOne() throws SQLException {

}

@Test
@Test
public void testExecuteUpdateReturnsNumberOfRowsInserted() throws Exception {
conn.createStatement().executeQuery("CREATE CLASS Insertable ");

PreparedStatement statement = conn.prepareStatement("INSERT INTO Insertable ( id ) VALUES (?)");
statement.setString(1, "testval");
int rowsInserted = statement.executeUpdate();

assertEquals( 1, rowsInserted );
}

@Test
public void testExecuteUpdateReturnsNumberOfRowsInsertedWhenMultipleInserted() throws Exception {
conn.createStatement().executeQuery("CREATE CLASS Insertable ");
conn.createStatement().executeQuery("INSERT INTO Insertable(id) VALUES(1)");
conn.createStatement().executeQuery("INSERT INTO Insertable(id) VALUES(2)");

PreparedStatement statement = conn.prepareStatement("UPDATE Insertable SET id = ?");
statement.setString(1, "testval");
int rowsInserted = statement.executeUpdate();

assertEquals( 2, rowsInserted );
}

@Test
public void shouldExecutePreparedStatement() throws Exception {
PreparedStatement stmt = conn.prepareStatement("SELECT " + "FROM Item " + "WHERE stringKey = ? OR intKey = ?");
assertNotNull(stmt);
Expand Down

0 comments on commit d660396

Please sign in to comment.