Search in sources :

Example 1 with DatabaseDescription

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(), "éç");
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DatabaseDescription(eu.rssw.antlr.database.objects.DatabaseDescription) Test(org.testng.annotations.Test)

Example 2 with DatabaseDescription

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");
}
Also used : Field(eu.rssw.antlr.database.objects.Field) DatabaseDescription(eu.rssw.antlr.database.objects.DatabaseDescription) Test(org.testng.annotations.Test)

Example 3 with DatabaseDescription

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());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DatabaseDescription(eu.rssw.antlr.database.objects.DatabaseDescription) Test(org.testng.annotations.Test)

Example 4 with DatabaseDescription

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);
        }
    }
}
Also used : Field(eu.rssw.antlr.database.objects.Field) Table(eu.rssw.antlr.database.objects.Table) FilePredicates(org.sonar.api.batch.fs.FilePredicates) IOException(java.io.IOException) DatabaseDescription(eu.rssw.antlr.database.objects.DatabaseDescription) InputFile(org.sonar.api.batch.fs.InputFile)

Example 5 with DatabaseDescription

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);
}
Also used : Schema(org.prorefactor.core.schema.Schema) ITable(org.prorefactor.core.schema.ITable) IField(org.prorefactor.core.schema.IField) DatabaseDescription(eu.rssw.antlr.database.objects.DatabaseDescription) DatabaseWrapper(org.sonar.plugins.openedge.api.objects.DatabaseWrapper) Test(org.testng.annotations.Test)

Aggregations

DatabaseDescription (eu.rssw.antlr.database.objects.DatabaseDescription)9 Test (org.testng.annotations.Test)7 InputStream (java.io.InputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Field (eu.rssw.antlr.database.objects.Field)2 Table (eu.rssw.antlr.database.objects.Table)2 IOException (java.io.IOException)2 InputFile (org.sonar.api.batch.fs.InputFile)2 DatabaseWrapper (org.sonar.plugins.openedge.api.objects.DatabaseWrapper)2 Index (eu.rssw.antlr.database.objects.Index)1 Trigger (eu.rssw.antlr.database.objects.Trigger)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 IDatabase (org.prorefactor.core.schema.IDatabase)1 IField (org.prorefactor.core.schema.IField)1 ITable (org.prorefactor.core.schema.ITable)1