From f327e0cb4a14ff8d4f85e5ae9da5986b8c87ab8c Mon Sep 17 00:00:00 2001 From: "Thomas Nelson Jr (arthurdent3) tn1381@att.com" Date: Sun, 4 Mar 2018 03:28:07 -0500 Subject: Sonar Fixes to increate Coverage on Unit tests Including bug fix that added proper Exception handling on REST Calls. Change-Id: I618faa69ab549e76c148bb7c664a5ffe0eae84ca Issue-ID: MUSIC-44, MUSIC-45 Signed-off-by: Thomas Nelson Jr (arthurdent3) tn1381@att.com --- .../org/onap/music/datastore/MusicDataStore.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src/main/java/org/onap/music/datastore/MusicDataStore.java') diff --git a/src/main/java/org/onap/music/datastore/MusicDataStore.java b/src/main/java/org/onap/music/datastore/MusicDataStore.java index e1ae5b08..09bdc8a7 100644 --- a/src/main/java/org/onap/music/datastore/MusicDataStore.java +++ b/src/main/java/org/onap/music/datastore/MusicDataStore.java @@ -33,6 +33,8 @@ import org.onap.music.eelf.logging.EELFLoggerDelegate; import org.onap.music.exceptions.MusicQueryException; import org.onap.music.exceptions.MusicServiceException; import org.onap.music.main.MusicUtil; +import org.onap.music.main.ResultType; + import com.datastax.driver.core.Cluster; import com.datastax.driver.core.ColumnDefinitions; import com.datastax.driver.core.ColumnDefinitions.Definition; @@ -46,6 +48,7 @@ import com.datastax.driver.core.Row; import com.datastax.driver.core.Session; import com.datastax.driver.core.TableMetadata; import com.datastax.driver.core.exceptions.AlreadyExistsException; +import com.datastax.driver.core.exceptions.InvalidQueryException; import com.datastax.driver.core.exceptions.NoHostAvailableException; /** @@ -65,6 +68,13 @@ public class MusicDataStore { public void setSession(Session session) { this.session = session; } + + /** + * @param session + */ + public Session getSession() { + return session; + } /** * @param cluster @@ -245,7 +255,7 @@ public class MusicDataStore { } } - public boolean doesRowSatisfyCondition(Row row, Map condition) { + public boolean doesRowSatisfyCondition(Row row, Map condition) throws Exception { ColumnDefinitions colInfo = row.getColumnDefinitions(); for (Map.Entry entry : condition.entrySet()) { @@ -310,7 +320,14 @@ public class MusicDataStore { "In preprared Execute Put: the actual insert query:" + queryObject.getQuery() + "; the values" + queryObject.getValues()); - PreparedStatement preparedInsert = session.prepare(queryObject.getQuery()); + PreparedStatement preparedInsert = null; + try { + preparedInsert = session.prepare(queryObject.getQuery()); + } catch(InvalidQueryException iqe) { + logger.error(EELFLoggerDelegate.errorLogger, iqe.getMessage()); + throw new MusicQueryException(iqe.getMessage()); + } + try { if (consistency.equalsIgnoreCase(MusicUtil.CRITICAL)) { logger.info(EELFLoggerDelegate.applicationLogger, "Executing critical put query"); @@ -327,6 +344,7 @@ public class MusicDataStore { catch (AlreadyExistsException ae) { logger.error(EELFLoggerDelegate.errorLogger, "Executing Session Failure for Request = " + "[" + queryObject.getQuery() + "]" + " Reason = " + ae.getMessage()); + throw new MusicServiceException(ae.getMessage()); } catch (Exception e) { logger.error(EELFLoggerDelegate.errorLogger, "Executing Session Failure for Request = " -- cgit 1.2.3-korg