Skip to content

Commit

Permalink
Add more grant db tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rpoet-jh committed Jun 4, 2024
1 parent 6718b1d commit 10af3a3
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ private List<GrantIngestRecord> retrieveGrantUpdates(String startDate, String aw
String sql = buildGrantQueryString(grant);
List<GrantIngestRecord> grantIngestRecords = new ArrayList<>();

LOG.info("Retrieving Grants from JHU Grant DB using start date={}, award end date={}", startDate, awardEndDate);

try (
Connection con = DriverManager.getConnection(grantDbUrl, grantDbUser, grantDbPassword);
PreparedStatement ps = con.prepareStatement(sql);
Expand Down Expand Up @@ -218,7 +220,7 @@ private List<GrantIngestRecord> retrieveGrantUpdates(String startDate, String aw
}
}
}
LOG.info("Retrieved result set from JHU Grant DB: {} records processed", grantIngestRecords.size());
LOG.info("Retrieved Grants result set from JHU Grant DB: {} records processed", grantIngestRecords.size());
return grantIngestRecords;
}

Expand Down Expand Up @@ -249,6 +251,7 @@ private List<GrantIngestRecord> retrieveFunderUpdates(Set<String> funderIds) thr
}
}
}
LOG.info("Retrieved Funders result set from JHU Grant DB: {} records processed", grantIngestRecords.size());
return grantIngestRecords;
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2023 Johns Hopkins University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.eclipse.pass.support.grant.data.jhu;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.sql.SQLException;
import java.util.List;

import org.eclipse.pass.support.grant.GrantLoaderCLIRunner;
import org.eclipse.pass.support.grant.data.GrantIngestRecord;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.TestPropertySource;

/**
* @author [email protected]
*/
@SpringBootTest
@TestPropertySource("classpath:test-application.properties")
public class JhuGrantDbConnectorTest {

@MockBean protected GrantLoaderCLIRunner grantLoaderCLIRunner;
@Autowired private JhuGrantDbConnector connector;

@Test
public void testGrantQuery() throws SQLException {
List<GrantIngestRecord> results =
connector.retrieveUpdates("2011-01-01 00:00:00", "2011-01-01", "grant", null);
List<String> actualAwardNums = results.stream().map(GrantIngestRecord::getAwardNumber).distinct().toList();
assertEquals(2, actualAwardNums.size());
assertTrue(actualAwardNums.contains("B10000000"));
assertTrue(actualAwardNums.contains("B10000003"));
}

@Test
public void testGrantQueryStartDate() throws SQLException {
List<GrantIngestRecord> results =
connector.retrieveUpdates("2023-03-01 00:00:00", "2011-01-01", "grant", null);
List<String> actualAwardNums = results.stream().map(GrantIngestRecord::getAwardNumber).distinct().toList();
assertEquals(1, actualAwardNums.size());
assertTrue(actualAwardNums.contains("B10000000"));
}

@Test
public void testGrantQueryAwardEndDate() throws SQLException {
List<GrantIngestRecord> results =
connector.retrieveUpdates("2011-01-01 00:00:00", "2024-01-01", "grant", null);
List<String> actualAwardNums = results.stream().map(GrantIngestRecord::getAwardNumber).distinct().toList();
assertEquals(1, actualAwardNums.size());
assertTrue(actualAwardNums.contains("B10000000"));
}

@Test
public void testUserQuery() throws SQLException {
List<GrantIngestRecord> results =
connector.retrieveUpdates("2023-03-01 00:00:00", null, "user", null);
assertEquals(1, results.size());
assertEquals("[email protected]", results.get(0).getPiEmail());
}

@Test
public void testFunderQuery() throws SQLException {
List<GrantIngestRecord> results =
connector.retrieveUpdates(null, null, "funder", null);
assertEquals(2, results.size());
List<String> actualNames = results.stream().map(GrantIngestRecord::getPrimaryFunderName).toList();
assertTrue(actualNames.contains("Sponsor 1"));
assertTrue(actualNames.contains("Sponsor 2"));
}

}
16 changes: 12 additions & 4 deletions pass-grant-loader/src/test/resources/data.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
DELETE FROM JHU_PASS_AWD_VIEW;
DELETE FROM JHU_FIBI_IP_INV_VIEW;
DELETE FROM JHU_PERSON_VIEW;
DELETE FROM JHU_SPONSOR_VIEW;

INSERT INTO JHU_PASS_AWD_VIEW (INST_PROPOSAL, AWARD_ID, AWARD_STATUS, SAP_GRANT_NUMBER, TITLE, AWARD_DATE, AWARD_START_DATE,
AWARD_END_DATE, SPONSOR_CODE, SPONSOR_NAME, PRIME_SPONSOR_CODE, PRIME_SPONSOR_NAME,
Expand All @@ -10,10 +14,10 @@ VALUES ('1', '31000000', 'PI');
INSERT INTO JHU_FIBI_IP_INV_VIEW (INST_PROPOSAL, EMPLOYEE_ID, ROLE)
VALUES ('1', '31000001', 'Co-I');

INSERT INTO JHU_PERSON_VIEW (EMPLOYEE_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, EMAIL_ADDRESS, JHED_ID)
VALUES ('31000000', 'Amanda', 'Bea', 'Reckondwith', '[email protected]', 'arecko1');
INSERT INTO JHU_PERSON_VIEW (EMPLOYEE_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, EMAIL_ADDRESS, JHED_ID)
VALUES ('31000001', 'Skip', 'Avery', 'Class', '[email protected]', 'sclass1');
INSERT INTO JHU_PERSON_VIEW (EMPLOYEE_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, EMAIL_ADDRESS, JHED_ID, UPDATE_TIMESTAMP)
VALUES ('31000000', 'Amanda', 'Bea', 'Reckondwith', '[email protected]', 'arecko1', '2022-03-11 00:00:00.0');
INSERT INTO JHU_PERSON_VIEW (EMPLOYEE_ID, FIRST_NAME, MIDDLE_NAME, LAST_NAME, EMAIL_ADDRESS, JHED_ID, UPDATE_TIMESTAMP)
VALUES ('31000001', 'Skip', 'Avery', 'Class', '[email protected]', 'sclass1', '2023-03-11 00:00:00.0');

INSERT INTO JHU_PASS_AWD_VIEW (INST_PROPOSAL, AWARD_ID, AWARD_STATUS, SAP_GRANT_NUMBER, TITLE, AWARD_DATE, AWARD_START_DATE,
AWARD_END_DATE, SPONSOR_CODE, SPONSOR_NAME, PRIME_SPONSOR_CODE, PRIME_SPONSOR_NAME,
Expand All @@ -24,4 +28,8 @@ VALUES('2', 'B10000003', 'Active', '10000002', 'Stupendous Research ProjectIV',
INSERT INTO JHU_FIBI_IP_INV_VIEW (INST_PROPOSAL, EMPLOYEE_ID, ROLE)
VALUES ('2', '31000001', 'PI');

INSERT INTO JHU_SPONSOR_VIEW (SPONSOR_CODE, SPONSOR_NAME)
VALUES ('20000000', 'Sponsor 1');
INSERT INTO JHU_SPONSOR_VIEW (SPONSOR_CODE, SPONSOR_NAME)
VALUES ('20000001', 'Sponsor 2');

15 changes: 11 additions & 4 deletions pass-grant-loader/src/test/resources/schema.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
DROP ALL OBJECTS;

CREATE TABLE IF NOT EXISTS JHU_PASS_AWD_VIEW (
CREATE TABLE JHU_PASS_AWD_VIEW (
INST_PROPOSAL varchar(100) NOT NULL,
AWARD_ID varchar(100) NOT NULL,
AWARD_STATUS varchar(100),
Expand All @@ -15,17 +16,23 @@ CREATE TABLE IF NOT EXISTS JHU_PASS_AWD_VIEW (
UPDATE_TIMESTAMP timestamp
);

CREATE TABLE IF NOT EXISTS JHU_FIBI_IP_INV_VIEW (
CREATE TABLE JHU_FIBI_IP_INV_VIEW (
INST_PROPOSAL varchar(100) NOT NULL,
EMPLOYEE_ID varchar(100),
ROLE varchar(100)
);

CREATE TABLE IF NOT EXISTS JHU_PERSON_VIEW (
CREATE TABLE JHU_PERSON_VIEW (
EMPLOYEE_ID varchar(100),
FIRST_NAME varchar(100) NOT NULL,
MIDDLE_NAME varchar(100),
LAST_NAME varchar(100),
EMAIL_ADDRESS varchar(100),
JHED_ID varchar(100)
JHED_ID varchar(100),
UPDATE_TIMESTAMP timestamp
);

CREATE TABLE IF NOT EXISTS JHU_SPONSOR_VIEW (
SPONSOR_CODE varchar(100) NOT NULL,
SPONSOR_NAME varchar(100)
);

0 comments on commit 10af3a3

Please sign in to comment.