JLVDodMedicationsMap { public JLVMappedCode getMedicationRxNormFromDodNcid(String sDodNcid) throws TermLoadException { JLVMappedCode oMappedCode = null; if (NullChecker.isNotNullish(sDodNcid)) { PreparedStatement psSelectStatement = null; ResultSet oResults = null; try { psSelectStatement = this.oDBConnection.prepareStatement(SQL_SELECT); psSelectStatement.setString(SQL_PARAM_DOD_NCID, sDodNcid); oResults = psSelectStatement.executeQuery(); boolean bHasResult = false; if (oResults.next()) { JLVMappedCode oTempMappedCode = new JLVMappedCode(); String sCode = oResults.getString(SQL_FIELD_DRUGS_RXNORM_CODE); if (NullChecker.isNotNullish(sCode)) { oTempMappedCode.setCode(sCode); bHasResult = true; } String sText = oResults.getString(SQL_FIELD_DRUGS_RXNORM_TEXT); if (NullChecker.isNotNullish(sText)) { oTempMappedCode.setDisplayText(sText); bHasResult = true; } if (bHasResult) { oTempMappedCode.setCodeSystem(CODE_SYSTEM_RXNORM); oMappedCode = oTempMappedCode; } } } catch (SQLException e) { throw new TermLoadException("Failed to read RXNORM information from the 'dod_medications' table. Error: " + e.getMessage(), e); } finally { TermLoadException exceptionToThrow = null; if (oResults != null) { try { oResults.close(); oResults = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the result set. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (psSelectStatement != null) { try { psSelectStatement.close(); psSelectStatement = null; } catch (SQLException e) { String sErrorMessage = "Failed to close the prepared statement. Error: " + e.getMessage(); LOG.error(sErrorMessage, e); exceptionToThrow = new TermLoadException(sErrorMessage, e); } } if (exceptionToThrow != null) { throw exceptionToThrow; } } } return oMappedCode; } @SuppressWarnings("unused") private  JLVDodMedicationsMap();  JLVDodMedicationsMap(Connection oDBConnection); JLVMappedCode getMedicationRxNormFromDodNcid(String sDodNcid); static final int SQL_PARAM_DOD_NCID; static final int SQL_FIELD_DOD_MEDICATIONS_DOD_NCID; static final int SQL_FIELD_DOD_MEDICATIONS_RXNORM; static final int SQL_FIELD_DRUGS_RXNORM_CODE; static final int SQL_FIELD_DRUGS_RXNORM_TEXT; static final String CODE_SYSTEM_RXNORM; }
@Test public void testGetRxNormFromDodNcidHappyPath() { try { when(mockResultSet.next()).thenReturn(true); when(mockResultSet.getString(JLVDodMedicationsMap.SQL_FIELD_DRUGS_RXNORM_CODE)).thenReturn(GENERATED_RXNORM_CODE); when(mockResultSet.getString(JLVDodMedicationsMap.SQL_FIELD_DRUGS_RXNORM_TEXT)).thenReturn(GENERATED_DISPLAY_TEXT); JLVMappedCode oMappedCode = testSubject.getMedicationRxNormFromDodNcid(GENERATED_DOD_NCID); verifyGeneratedContent(oMappedCode); verifyCloseMethodsCalled(); } catch (Exception e) { System.out.println("An unexpected exception occurred. Error: " + e.getMessage()); e.printStackTrace(); fail("An unexpected exception occurred. Error: " + e.getMessage()); } }
@Test public void testRxNormFromDodNcidCodeNoMappingBecauseFieldsEmpty() { try { when(mockResultSet.next()).thenReturn(true); when(mockResultSet.getString(JLVDodMedicationsMap.SQL_FIELD_DRUGS_RXNORM_CODE)).thenReturn(""); when(mockResultSet.getString(JLVDodMedicationsMap.SQL_FIELD_DRUGS_RXNORM_TEXT)).thenReturn(""); JLVMappedCode oMappedCode = testSubject.getMedicationRxNormFromDodNcid(GENERATED_DOD_NCID); assertNull("The result should have been null", oMappedCode); verifyCloseMethodsCalled(); } catch (Exception e) { System.out.println("An unexpected exception occurred. Error: " + e.getMessage()); e.printStackTrace(); fail("An unexpected exception occurred. Error: " + e.getMessage()); } }
@Test public void testRxNormFromDodNcidCodeNoMappingHappyPath() { try { when(mockResultSet.next()).thenReturn(false); JLVMappedCode oMappedCode = testSubject.getMedicationRxNormFromDodNcid(GENERATED_DOD_NCID); assertNull("The result should have been null", oMappedCode); verifyCloseMethodsCalled(); } catch (Exception e) { System.out.println("An unexpected exception occurred. Error: " + e.getMessage()); e.printStackTrace(); fail("An unexpected exception occurred. Error: " + e.getMessage()); } }
@Test public void testRxNormFromDodNcidCodeNull() { try { when(mockResultSet.next()).thenReturn(false); JLVMappedCode oMappedCode = testSubject.getMedicationRxNormFromDodNcid(null); assertNull("The result should have been null", oMappedCode); } catch (Exception e) { System.out.println("An unexpected exception occurred. Error: " + e.getMessage()); e.printStackTrace(); fail("An unexpected exception occurred. Error: " + e.getMessage()); } }
@Test public void testRxNormFromDodNcidCodeSQLException() { try { when(mockResultSet.next()).thenThrow(new SQLException()); @SuppressWarnings("unused") JLVMappedCode oMappedCode = testSubject.getMedicationRxNormFromDodNcid(GENERATED_DOD_NCID); fail("There should have been a TermLoadException thrown."); } catch (TermLoadException e) { try { verifyCloseMethodsCalled(); } catch (Exception e2) { System.out.println("An unexpected exception occurred. Error: " + e2.getMessage()); e2.printStackTrace(); fail("An unexpected exception occurred. Error: " + e2.getMessage()); } } catch (Exception e) { System.out.println("An unexpected exception occurred. Error: " + e.getMessage()); e.printStackTrace(); fail("An unexpected exception occurred. Error: " + e.getMessage()); } }
@Test public void testRxNormFromDodNcidCodeSQLExceptionOnResultSetClose() { try { when(mockResultSet.next()).thenReturn(false); Mockito.doThrow(new SQLException()).when(mockResultSet).close(); @SuppressWarnings("unused") JLVMappedCode oMappedCode = testSubject.getMedicationRxNormFromDodNcid(GENERATED_DOD_NCID); fail("There should have been a TermLoadException thrown."); } catch (TermLoadException e) { try { verifyCloseMethodsCalled(); } catch (Exception e2) { System.out.println("An unexpected exception occurred. Error: " + e2.getMessage()); e2.printStackTrace(); fail("An unexpected exception occurred. Error: " + e2.getMessage()); } } catch (Exception e) { System.out.println("An unexpected exception occurred. Error: " + e.getMessage()); e.printStackTrace(); fail("An unexpected exception occurred. Error: " + e.getMessage()); } }
@Test public void testRxNormFromDodNcidCodeSQLExceptionOnPreparedStatementClose() { try { when(mockResultSet.next()).thenReturn(false); Mockito.doThrow(new SQLException()).when(mockPreparedStatement).close(); @SuppressWarnings("unused") JLVMappedCode oMappedCode = testSubject.getMedicationRxNormFromDodNcid(GENERATED_DOD_NCID); fail("There should have been a TermLoadException thrown."); } catch (TermLoadException e) { try { verifyCloseMethodsCalled(); } catch (Exception e2) { System.out.println("An unexpected exception occurred. Error: " + e2.getMessage()); e2.printStackTrace(); fail("An unexpected exception occurred. Error: " + e2.getMessage()); } } catch (Exception e) { System.out.println("An unexpected exception occurred. Error: " + e.getMessage()); e.printStackTrace(); fail("An unexpected exception occurred. Error: " + e.getMessage()); } }