Skip to content

Commit

Permalink
squash w/ genquery2
Browse files Browse the repository at this point in the history
  • Loading branch information
korydraughn committed May 14, 2024
1 parent 962db1c commit 019ca89
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public interface IRODSGenquery2Executor extends IRODSAccessObject {
*
* The zone defined in the IRODSAccount will be used.
*
* This method DOES NOT provide support for pagination.
*
* @param queryString The GenQuery2 string to execute.
* @return A JSON string containing the results. The structure will be a list of
* list of strings.
Expand All @@ -22,6 +24,8 @@ public interface IRODSGenquery2Executor extends IRODSAccessObject {
/**
* Query the catalog using a GenQuery2 string.
*
* This method DOES NOT provide support for pagination.
*
* @param queryString The GenQuery2 string to execute.
* @param zone The zone to execute against.
* @return A JSON string containing the results. The structure will be a list of
Expand Down
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", ""));
}

}

0 comments on commit 019ca89

Please sign in to comment.