-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
962db1c
commit 019ca89
Showing
2 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
jargon-core/src/test/java/org/irods/jargon/core/pub/IRODSGenquery2ExecutorImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
package org.irods.jargon.core.pub; | ||
|
||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import org.irods.jargon.core.connection.IRODSAccount; | ||
import org.irods.jargon.core.exception.JargonException; | ||
import org.irods.jargon.testutils.TestingPropertiesHelper; | ||
import org.junit.AfterClass; | ||
import org.junit.Assert; | ||
import org.junit.Assume; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public class IRODSGenquery2ExecutorImplTest { | ||
|
||
private static final TestingPropertiesHelper testingPropertiesHelper = new TestingPropertiesHelper(); | ||
private static final ObjectMapper objectMapper = new ObjectMapper(); | ||
|
||
private static Properties testingProperties; | ||
private static IRODSFileSystem irodsFileSystem; | ||
private static IRODSAccount irodsAccount; | ||
|
||
@BeforeClass | ||
public static void setUpBeforeClass() throws Exception { | ||
TestingPropertiesHelper testingPropertiesLoader = new TestingPropertiesHelper(); | ||
testingProperties = testingPropertiesLoader.getTestProperties(); | ||
irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties); | ||
irodsFileSystem = IRODSFileSystem.instance(); | ||
} | ||
|
||
@AfterClass | ||
public static void tearDownAfterClass() throws Exception { | ||
irodsFileSystem.closeAndEatExceptions(); | ||
} | ||
|
||
@Test | ||
public final void testExecuteQueryWithoutZone() throws Exception { | ||
IRODSAccessObjectFactory aof = irodsFileSystem.getIRODSAccessObjectFactory(); | ||
|
||
// Skip if pre iRODS 4.3.2. | ||
Assume.assumeFalse("GenQuery2 requires a minimum version of iRODS 4.3.2", | ||
aof.getIRODSServerProperties(irodsAccount).isAtLeastIrods432()); | ||
|
||
IRODSGenquery2Executor gq2e = aof.getIRODSGenquery2Executor(irodsAccount); | ||
|
||
String query = String.format("select ZONE_NAME where ZONE_NAME = '%s'"); | ||
String json = gq2e.execute(query); | ||
List<List<String>> rows = objectMapper.readValue(json, new TypeReference<List<List<String>>>() { | ||
}); | ||
Assert.assertFalse(rows.isEmpty()); | ||
} | ||
|
||
@Test | ||
public final void testExecuteQueryWithZone() throws Exception { | ||
IRODSAccessObjectFactory aof = irodsFileSystem.getIRODSAccessObjectFactory(); | ||
|
||
// Skip if pre iRODS 4.3.2. | ||
Assume.assumeFalse("GenQuery2 requires a minimum version of iRODS 4.3.2", | ||
aof.getIRODSServerProperties(irodsAccount).isAtLeastIrods432()); | ||
|
||
IRODSGenquery2Executor gq2e = aof.getIRODSGenquery2Executor(irodsAccount); | ||
|
||
String query = String.format("select ZONE_NAME where ZONE_NAME = '%s'", irodsAccount.getZone()); | ||
String json = gq2e.execute(query, irodsAccount.getZone()); | ||
List<List<String>> rows = objectMapper.readValue(json, new TypeReference<List<List<String>>>() { | ||
}); | ||
Assert.assertFalse(rows.isEmpty()); | ||
} | ||
|
||
@Test | ||
public final void testGetGeneratedSQLWithoutZone() throws Exception { | ||
IRODSAccessObjectFactory aof = irodsFileSystem.getIRODSAccessObjectFactory(); | ||
|
||
// Skip if pre iRODS 4.3.2. | ||
Assume.assumeFalse("GenQuery2 requires a minimum version of iRODS 4.3.2", | ||
aof.getIRODSServerProperties(irodsAccount).isAtLeastIrods432()); | ||
|
||
IRODSGenquery2Executor gq2e = aof.getIRODSGenquery2Executor(irodsAccount); | ||
|
||
String sql = gq2e.getGeneratedSQL("select COLL_NAME, DATA_NAME"); | ||
Assert.assertTrue(sql.contains(" R_COLL_MAIN ")); | ||
Assert.assertTrue(sql.contains(" R_DATA_MAIN ")); | ||
Assert.assertTrue(sql.contains(" t0.")); | ||
Assert.assertTrue(sql.contains(" from ")); | ||
Assert.assertTrue(sql.contains(" inner join ")); | ||
} | ||
|
||
@Test | ||
public final void testGetGeneratedSQLWithZone() throws Exception { | ||
IRODSAccessObjectFactory aof = irodsFileSystem.getIRODSAccessObjectFactory(); | ||
|
||
// Skip if pre iRODS 4.3.2. | ||
Assume.assumeFalse("GenQuery2 requires a minimum version of iRODS 4.3.2", | ||
aof.getIRODSServerProperties(irodsAccount).isAtLeastIrods432()); | ||
|
||
IRODSGenquery2Executor gq2e = aof.getIRODSGenquery2Executor(irodsAccount); | ||
|
||
String sql = gq2e.getGeneratedSQL("select COLL_NAME, DATA_NAME", irodsAccount.getZone()); | ||
Assert.assertTrue(sql.contains(" R_COLL_MAIN ")); | ||
Assert.assertTrue(sql.contains(" R_DATA_MAIN ")); | ||
Assert.assertTrue(sql.contains(" t0.")); | ||
Assert.assertTrue(sql.contains(" from ")); | ||
Assert.assertTrue(sql.contains(" inner join ")); | ||
} | ||
|
||
@Test | ||
public final void testGetColumnMappings() throws Exception { | ||
IRODSAccessObjectFactory aof = irodsFileSystem.getIRODSAccessObjectFactory(); | ||
|
||
// Skip if pre iRODS 4.3.2. | ||
Assume.assumeFalse("GenQuery2 requires a minimum version of iRODS 4.3.2", | ||
aof.getIRODSServerProperties(irodsAccount).isAtLeastIrods432()); | ||
|
||
IRODSGenquery2Executor gq2e = aof.getIRODSGenquery2Executor(irodsAccount); | ||
|
||
String mappings = gq2e.getColumnMappings(); | ||
Assert.assertTrue(mappings.contains("\"DATA_ID\": {\"R_DATA_MAIN\":\"data_id\"}")); | ||
Assert.assertTrue(mappings.contains("\"COLL_ID\": {\"R_COLL_MAIN\":\"coll_id\"}")); | ||
Assert.assertTrue(mappings.contains("\"RESC_NAME\": {\"R_RESC_MAIN\":\"resc_name\"}")); | ||
} | ||
|
||
@Test | ||
public final void testInvalidInputs() throws Exception { | ||
IRODSAccessObjectFactory aof = irodsFileSystem.getIRODSAccessObjectFactory(); | ||
|
||
// Skip if pre iRODS 4.3.2. | ||
Assume.assumeFalse("GenQuery2 requires a minimum version of iRODS 4.3.2", | ||
aof.getIRODSServerProperties(irodsAccount).isAtLeastIrods432()); | ||
|
||
IRODSGenquery2Executor gq2e = aof.getIRODSGenquery2Executor(irodsAccount); | ||
|
||
Assert.assertThrows(JargonException.class, () -> gq2e.execute(null)); | ||
Assert.assertThrows(JargonException.class, () -> gq2e.execute("")); | ||
Assert.assertThrows(JargonException.class, () -> gq2e.execute(null, irodsAccount.getZone())); | ||
Assert.assertThrows(JargonException.class, () -> gq2e.execute("", irodsAccount.getZone())); | ||
Assert.assertThrows(JargonException.class, () -> gq2e.execute("select ZONE_NAME", null)); | ||
Assert.assertThrows(JargonException.class, () -> gq2e.execute("select ZONE_NAME", "")); | ||
|
||
Assert.assertThrows(JargonException.class, () -> gq2e.getGeneratedSQL(null)); | ||
Assert.assertThrows(JargonException.class, () -> gq2e.getGeneratedSQL("")); | ||
Assert.assertThrows(JargonException.class, () -> gq2e.getGeneratedSQL(null, irodsAccount.getZone())); | ||
Assert.assertThrows(JargonException.class, () -> gq2e.getGeneratedSQL("", irodsAccount.getZone())); | ||
Assert.assertThrows(JargonException.class, () -> gq2e.getGeneratedSQL("select ZONE_NAME", null)); | ||
Assert.assertThrows(JargonException.class, () -> gq2e.getGeneratedSQL("select ZONE_NAME", "")); | ||
} | ||
|
||
} |