CPDCallback implements ICallback<NewCpdTokens> { @Override public NewCpdTokens getResult() { return cpdTokens; } CPDCallback(SensorContext context, InputFile file, OpenEdgeSettings settings, ParseUnit unit); @Override NewCpdTokens getResult(); @Override boolean visitNode(JPNode node);  }
@Test public void test1() { SensorContextTester context = SensorContextTester.create(new File(BASEDIR)); OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); settings.init(); InputFile inputFile = getInputFile(context, "cpd01.p"); ParseUnit unit = getParseUnit(inputFile); ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit); unit.getTopNode().walk(callback); callback.getResult().save(); List<TokensLine> lines = context.cpdTokens(inputFile.key()); assertEquals(lines.size(), 3); assertEquals(lines.get(0).getValue(), "definevariablexxasintegerno-undo."); assertEquals(lines.get(1).getValue(), "assignxx=2"); assertEquals(lines.get(2).getValue(), "xx=3."); }
@Test public void test2() { SensorContextTester context = SensorContextTester.create(new File(BASEDIR)); OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); settings.init(); InputFile inputFile = getInputFile(context, "cpd02.p"); ParseUnit unit = getParseUnit(inputFile); ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit); unit.getTopNode().walk(callback); callback.getResult().save(); List<TokensLine> lines = context.cpdTokens(inputFile.key()); assertEquals(lines.size(), 5); assertEquals(lines.get(0).getValue(), "definetemp-tabletttestresultfielddisplayinbrowserascharacter."); assertEquals(lines.get(1).getValue(), "procedureenable_ui:"); assertEquals(lines.get(2).getValue(), "."); assertEquals(lines.get(3).getValue(), "viewresultswindow."); assertEquals(lines.get(4).getValue(), "endprocedure."); }
@Test public void test3() { SensorContextTester context = SensorContextTester.create(new File(BASEDIR)); OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); settings.init(); InputFile inputFile = getInputFile(context, "cpd03.p"); ParseUnit unit = getParseUnit(inputFile); ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit); unit.getTopNode().walk(callback); callback.getResult().save(); List<TokensLine> lines = context.cpdTokens(inputFile.key()); assertEquals(lines.size(), 2); assertEquals(lines.get(0).getValue(), "definetemp-table"); assertEquals(lines.get(1).getValue(), "fieldbarxxxbarascharacter."); }
@Test public void testNoProperties() { SensorContextTester context = SensorContextTester.create(new File(BASEDIR)); OpenEdgeSettings settings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); settings.init(); InputFile inputFile = getInputFile(context, "cpd04.p"); ParseUnit unit = getParseUnit(inputFile); ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, settings, unit); unit.getTopNode().walk(callback); callback.getResult().save(); List<TokensLine> lines = context.cpdTokens(inputFile.key()); assertEquals(lines.size(), 13); }
@Test public void testAnnotations() { MapSettings settings = new MapSettings(); settings.setProperty(Constants.CPD_ANNOTATIONS, "Generated"); SensorContextTester context = SensorContextTester.create(new File(BASEDIR)); context.setSettings(settings); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); oeSettings.init(); InputFile inputFile = getInputFile(context, "cpd04.p"); ParseUnit unit = getParseUnit(inputFile); ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, oeSettings, unit); unit.getTopNode().walk(callback); callback.getResult().save(); List<TokensLine> lines = context.cpdTokens(inputFile.key()); assertEquals(lines.size(), 9); }
@Test public void testProcedures() { MapSettings settings = new MapSettings(); settings.setProperty(Constants.CPD_PROCEDURES, "p1,p4,p3"); SensorContextTester context = SensorContextTester.create(new File(BASEDIR)); context.setSettings(settings); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); oeSettings.init(); InputFile inputFile = getInputFile(context, "cpd04.p"); ParseUnit unit = getParseUnit(inputFile); ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, oeSettings, unit); unit.getTopNode().walk(callback); callback.getResult().save(); List<TokensLine> lines = context.cpdTokens(inputFile.key()); assertEquals(lines.size(), 7); }
@Test public void testAnnotationsAndProcedures() { MapSettings settings = new MapSettings(); settings.setProperty(Constants.CPD_ANNOTATIONS, "Generated"); settings.setProperty(Constants.CPD_PROCEDURES, "p1,p4,p5"); SensorContextTester context = SensorContextTester.create(new File(BASEDIR)); context.setSettings(settings); OpenEdgeSettings oeSettings = new OpenEdgeSettings(context.config(), context.fileSystem(), OpenEdgePluginTest.SONARQUBE_RUNTIME, OpenEdgePluginTest.SERVER); oeSettings.init(); InputFile inputFile = getInputFile(context, "cpd04.p"); ParseUnit unit = getParseUnit(inputFile); ICallback<NewCpdTokens> callback = new CPDCallback(context, inputFile, oeSettings, unit); unit.getTopNode().walk(callback); callback.getResult().save(); List<TokensLine> lines = context.cpdTokens(inputFile.key()); assertEquals(lines.size(), 6); }