use of eu.rssw.antlr.database.objects.DatabaseDescription in project sonar-openedge by Riverside-Software.
the class TestDumpFile method testInputStream.
@Test
public void testInputStream() throws IOException {
InputStream stream1 = Files.newInputStream(Paths.get("src/test/resources/sp3k.df"));
DatabaseDescription db = DumpFileUtils.getDatabaseDescription(stream1, Charset.forName("utf-8"), "sp3k");
assertEquals(db.getTable("Tbl1").getDescription(), "éç");
InputStream stream2 = Files.newInputStream(Paths.get("src/test/resources/sp4k.df"));
DatabaseDescription db2 = DumpFileUtils.getDatabaseDescription(stream2, Charset.forName("utf-8"), "sp4k");
assertEquals(db2.getTable("Tbl1").getDescription(), "éç");
}
use of eu.rssw.antlr.database.objects.DatabaseDescription in project sonar-openedge by Riverside-Software.
the class TestDumpFile method testFieldAttributes.
@Test
public void testFieldAttributes() throws IOException {
DatabaseDescription db = DumpFileUtils.getDatabaseDescription(Paths.get("src/test/resources/sp2k.df"));
Field f = db.getTable("Benefits").getField("EmpNum");
assertEquals(f.getLabel().toUpperCase(), "EMP NO");
assertEquals(f.getPosition().intValue(), 2);
assertEquals(f.getOrder().intValue(), 10);
assertEquals(f.getInitial(), "0");
f = db.getTable("BillTo").getField("State");
assertEquals(f.getDescription(), "Label/Valexp/Valmsg/Help are set based on value of NON-US field!");
assertEquals(f.getLabel(), "State");
assertEquals(f.getMaxWidth().intValue(), 40);
assertEquals(f.getFormat(), "x(20)");
f = db.getTable("Bin").getField("BinName");
assertNull(f.getLabel());
f = db.getTable("Bin").getField("BinNum");
assertEquals(f.getLabel(), "Bin Num");
}
use of eu.rssw.antlr.database.objects.DatabaseDescription in project sonar-openedge by Riverside-Software.
the class TestDumpFile method testComments.
@Test
public void testComments() throws IOException {
InputStream stream = Files.newInputStream(Paths.get("src/test/resources/comments.df"));
DatabaseDescription db = DumpFileUtils.getDatabaseDescription(stream, Charset.forName("utf-8"), "sp2k");
assertNull(db.getTable("Tbl1").getDescription());
assertEquals(db.getTable("Tbl1").getArea(), "XXX");
assertTrue(db.getTable("Tbl1").isFrozen());
}
use of eu.rssw.antlr.database.objects.DatabaseDescription in project sonar-openedge by Riverside-Software.
the class OpenEdgeDBSensor method computeBaseMetrics.
@SuppressWarnings({ "unchecked", "rawtypes" })
private void computeBaseMetrics(SensorContext sensorContext) {
FilePredicates predicates = sensorContext.fileSystem().predicates();
for (InputFile file : sensorContext.fileSystem().inputFiles(predicates.and(predicates.hasLanguage(Constants.DB_LANGUAGE_KEY), predicates.hasType(Type.MAIN)))) {
try {
LOG.info("Analyzing {}", file);
DatabaseDescription desc = DumpFileUtils.getDatabaseDescription(file.inputStream(), file.charset(), Files.getNameWithoutExtension(file.filename()));
sensorContext.newMeasure().on(file).forMetric((Metric) OpenEdgeMetrics.NUM_TABLES).withValue(desc.getTables().size()).save();
sensorContext.newMeasure().on(file).forMetric((Metric) OpenEdgeMetrics.NUM_SEQUENCES).withValue(desc.getSequences().size()).save();
int numFlds = 0;
int numIdx = 0;
int numTriggers = 0;
for (Table tab : desc.getTables()) {
numFlds += tab.getFields().size();
numIdx += tab.getIndexes().size();
numTriggers += tab.getTriggers().size();
for (Field f : tab.getFields()) {
numTriggers += f.getTriggers().size();
}
}
sensorContext.newMeasure().on(file).forMetric((Metric) OpenEdgeMetrics.NUM_FIELDS).withValue(numFlds).save();
sensorContext.newMeasure().on(file).forMetric((Metric) OpenEdgeMetrics.NUM_INDEXES).withValue(numIdx).save();
sensorContext.newMeasure().on(file).forMetric((Metric) OpenEdgeMetrics.NUM_TRIGGERS).withValue(numTriggers).save();
} catch (IOException caught) {
LOG.error("Can not analyze file", caught);
}
}
}
use of eu.rssw.antlr.database.objects.DatabaseDescription in project sonar-openedge by Riverside-Software.
the class TableWrapperTest method testFromDotDF.
@Test
public void testFromDotDF() throws IOException {
DatabaseDescription dbDesc = DumpFileUtils.getDatabaseDescription(Paths.get("src/test/resources/project1/src/schema/sp2k.df"));
Schema sch = new Schema(new DatabaseWrapper(dbDesc));
IField fld1 = sch.lookupUnqualifiedField("minqty");
Assert.assertNotNull(fld1);
IField fld2 = sch.lookupUnqualifiedField("minqt");
Assert.assertNotNull(fld2);
IField fld3 = sch.lookupUnqualifiedField("custnum");
Assert.assertNotNull(fld3);
Assert.assertEquals(fld3.getTable().getName(), "BillTo");
ITable tbl1 = sch.lookupTable("customer");
Assert.assertNotNull(tbl1);
ITable tbl2 = sch.lookupTable("custome");
Assert.assertNotNull(tbl2);
ITable tbl3 = sch.lookupTable("bin");
Assert.assertNotNull(tbl3);
IField fld4 = tbl3.lookupField("binnum");
Assert.assertNotNull(fld4);
Assert.assertEquals(fld4.getName(), "BinNum");
IField fld5 = tbl3.lookupField("binnu");
Assert.assertNotNull(fld5);
Assert.assertEquals(fld5.getName(), "BinNum");
IField fld6 = tbl3.lookupField("binna");
Assert.assertNotNull(fld6);
Assert.assertEquals(fld6.getName(), "BinName");
// TODO Ambiguous field, should return null
// IField fld7 = tbl3.lookupField("binn");
// Assert.assertNull(fld7);
}
Aggregations