diff options
author | Instrumental <jonathan.gathman@att.com> | 2019-02-03 06:09:34 -0600 |
---|---|---|
committer | Instrumental <jonathan.gathman@att.com> | 2019-02-03 06:09:46 -0600 |
commit | 59ffb7d529245c3bd0233dbf6cb0ae9fe9ccb856 (patch) | |
tree | 48f79984b766211d0f570f50485cbe288dd2f990 /cadi/core | |
parent | e36daf12cf4c5aa4b22fa3cec66a79ff2e2b8b94 (diff) |
Approval Batch, prep better JUnit
Issue-ID: AAF-740
Change-Id: Id9e8ca121c9bf92c2f98c7a61631e2417bba70b1
Signed-off-by: Instrumental <jonathan.gathman@att.com>
Diffstat (limited to 'cadi/core')
6 files changed, 36 insertions, 19 deletions
diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/basic/BasicHttpTaf.java b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/basic/BasicHttpTaf.java index 3466a8d8..d5c88464 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/taf/basic/BasicHttpTaf.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/taf/basic/BasicHttpTaf.java @@ -83,7 +83,7 @@ public class BasicHttpTaf implements HttpTaf { mapIds=null; } else { try { - mapIds = new MapBathConverter(access, new CSV(csvFile)); + mapIds = new MapBathConverter(access, new CSV(access,csvFile)); } catch (IOException | CadiException e) { access.log(e,"Bath Map Conversion is not initialzed (non fatal)"); } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java b/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java index ed4fcde6..a834db51 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/util/CSV.java @@ -30,7 +30,9 @@ import java.io.PrintStream; import java.util.ArrayList; import java.util.List; +import org.onap.aaf.cadi.Access; import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.Access.Level; /** * Read CSV file for various purposes @@ -40,17 +42,26 @@ import org.onap.aaf.cadi.CadiException; */ public class CSV { private File csv; + private Access access; + private boolean processAll; - public CSV(File file) { + public CSV(Access access, File file) { + this.access = access; csv = file; + processAll = false; } - public CSV(String csvFilename) { + public CSV(Access access, String csvFilename) { + this.access = access; csv = new File(csvFilename); + processAll = false; } - - /** + public CSV processAll() { + processAll = true; + return this; + } + /* * Create your code to accept the List<String> row. * * Your code may keep the List... CSV does not hold onto it. @@ -117,7 +128,15 @@ public class CSV { row.add(sb.toString()); sb.setLength(0); } - visitor.visit(row); + try { + visitor.visit(row); + } catch (CadiException e) { + if(processAll) { + access.log(Level.ERROR,e); + } else { + throw e; + } + } } } } finally { @@ -147,7 +166,8 @@ public class CSV { } else { ps.append(','); } - if(o instanceof String[]) { + if(o == null) { + } else if(o instanceof String[]) { for(String str : (String[])o) { print(str); } diff --git a/cadi/core/src/main/java/org/onap/aaf/cadi/util/Vars.java b/cadi/core/src/main/java/org/onap/aaf/cadi/util/Vars.java index 9751969e..417351f5 100644 --- a/cadi/core/src/main/java/org/onap/aaf/cadi/util/Vars.java +++ b/cadi/core/src/main/java/org/onap/aaf/cadi/util/Vars.java @@ -31,8 +31,8 @@ public class Vars { * @return */ public static String convert(final String text, final List<String> vars) { - String[] array = new String[vars.size()]; StringBuilder sb = new StringBuilder(); + Object[] array = new Object[vars.size()]; convert(sb,text,vars.toArray(array)); return sb.toString(); } @@ -44,7 +44,7 @@ public class Vars { * @param vars * @return */ - public static String convert(final StringBuilder holder, final String text, final String ... vars) { + public static String convert(final StringBuilder holder, final String text, final Object ... vars) { StringBuilder sb = null; int idx,index=0,prev = 0; diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_MapBathConverter.java b/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_MapBathConverter.java index 9db542db..d9a5a0eb 100644 --- a/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_MapBathConverter.java +++ b/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_MapBathConverter.java @@ -62,7 +62,7 @@ public class JU_MapBathConverter { public static void createFile() throws IOException { // Note, you cate a "MapBathConverter" by access to a File. // We will create that file now. Local is fine. - csv = new CSV("JU_MapBathConverter.csv"); + csv = new CSV(access,"JU_MapBathConverter.csv"); } @BeforeClass @@ -109,7 +109,7 @@ public class JU_MapBathConverter { break; case 2: try { - Date d = Date.valueOf(s); + Date.valueOf(s); } catch (Exception e) { Assert.assertTrue("Last entry should be a date",false); } @@ -199,7 +199,7 @@ public class JU_MapBathConverter { @Test public void testNoFile() { try { - new MapBathConverter(access, new CSV("Bogus")); + new MapBathConverter(access, new CSV(access,"Bogus")); Assert.fail("Non Existent File should throw exception"); } catch(CadiException | IOException e) { Assert.assertTrue("Correctly thrown Exception",true); diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java b/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java index f3e05d9b..46fd741d 100644 --- a/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java +++ b/cadi/core/src/test/java/org/onap/aaf/cadi/config/test/JU_RegistrationPropHolder.java @@ -85,12 +85,6 @@ public class JU_RegistrationPropHolder { String ns2 = "onap"; pa.setProperty(Config.AAF_LOCATOR_NS+".helm", ns2); for(String dot_le : new String[] {"",".helm"}) { - String pns; - if(dot_le.isEmpty()) { - pns = ns; - } else { - pns = ns2; - } assertEquals(rph.hostname,rph.default_fqdn); assertEquals("",rph.lcontainer); assertEquals(rph.hostname,rph.public_hostname); diff --git a/cadi/core/src/test/java/org/onap/aaf/cadi/util/test/JU_CSV.java b/cadi/core/src/test/java/org/onap/aaf/cadi/util/test/JU_CSV.java index 54c48daf..9df6de7b 100644 --- a/cadi/core/src/test/java/org/onap/aaf/cadi/util/test/JU_CSV.java +++ b/cadi/core/src/test/java/org/onap/aaf/cadi/util/test/JU_CSV.java @@ -34,7 +34,9 @@ import org.junit.Assert; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.onap.aaf.cadi.Access; import org.onap.aaf.cadi.CadiException; +import org.onap.aaf.cadi.PropAccess; import org.onap.aaf.cadi.util.CSV; import org.onap.aaf.cadi.util.CSV.Visitor; import org.onap.aaf.cadi.util.CSV.Writer; @@ -65,7 +67,8 @@ public class JU_CSV { @Test public void test() throws IOException, CadiException { - CSV csv = new CSV(file); + Access access = new PropAccess(); + CSV csv = new CSV(access,file); // Can't visit for file that doesn't exist try { csv.visit(new Visitor() { |