SoqlQueryAnalyzer { public List getFieldDefinitions() { if (fieldDefinitions == null) { fieldDefinitions = new ArrayList<>(); SelectSpecVisitor visitor = new SelectSpecVisitor(); getQueryData().getSelectSpecs() .forEach(spec -> spec.accept(visitor)); } return fieldDefinitions; } SoqlQueryAnalyzer(String soql, Function<String, DescribeSObjectResult> objectDescriptor);  SoqlQueryAnalyzer(String soql, Function<String, DescribeSObjectResult> objectDescriptor, Map<String, DescribeSObjectResult> describedObjectsCache); List getFieldDefinitions();  }
@Test public void testGetAggregateFieldDefinition() { SoqlQueryAnalyzer analyzer = new SoqlQueryAnalyzer("SELECT MIN(Name) FROM Contact", n -> this.describeSObject(n)); List<FieldDef> actuals = listFlatFieldDefinitions(analyzer.getFieldDefinitions()); assertEquals(1, actuals.size()); assertEquals("MIN", actuals.get(0).getName()); assertEquals("string", actuals.get(0).getType()); }
@Test public void testGetAggregateFieldDefinitionWithoutParameter() { SoqlQueryAnalyzer analyzer = new SoqlQueryAnalyzer("SELECT Count() FROM Contact", n -> this.describeSObject(n)); List<FieldDef> actuals = listFlatFieldDefinitions(analyzer.getFieldDefinitions()); assertEquals(1, actuals.size()); assertEquals("Count", actuals.get(0).getName()); assertEquals("int", actuals.get(0).getType()); }
@Test public void testGetSimpleFieldWithQualifier() { SoqlQueryAnalyzer analyzer = new SoqlQueryAnalyzer("SELECT Contact.Id FROM Contact", n -> this.describeSObject(n)); List<FieldDef> actuals = listFlatFieldDefinitions(analyzer.getFieldDefinitions()); assertEquals(1, actuals.size()); assertEquals("Id", actuals.get(0).getName()); assertEquals("id", actuals.get(0).getType()); }
@Test public void testGetNamedAggregateFieldDefinitions() { SoqlQueryAnalyzer analyzer = new SoqlQueryAnalyzer("SELECT count(Name) nameCount FROM Account", n -> this.describeSObject(n)); List<FieldDef> actuals = listFlatFieldDefinitions(analyzer.getFieldDefinitions()); assertEquals(1, actuals.size()); assertEquals("nameCount", actuals.get(0).getName()); assertEquals("int", actuals.get(0).getType()); }
@Test public void testFetchFieldDefinitions_WithIncludedSeslect() { SoqlQueryAnalyzer analyzer = new SoqlQueryAnalyzer("SELECT Name, (SELECT Id, max(LastName) maxLastName FROM Contacts), Id FROM Account", n -> this.describeSObject(n)); List actuals = analyzer.getFieldDefinitions(); assertEquals(3, actuals.size()); FieldDef fieldDef = (FieldDef) actuals.get(0); assertEquals("Name", fieldDef.getName()); assertEquals("string", fieldDef.getType()); List suqueryDef = (List) actuals.get(1); fieldDef = (FieldDef) suqueryDef.get(0); assertEquals("Id", fieldDef.getName()); assertEquals("id", fieldDef.getType()); fieldDef = (FieldDef) suqueryDef.get(1); assertEquals("maxLastName", fieldDef.getName()); assertEquals("string", fieldDef.getType()); fieldDef = (FieldDef) actuals.get(2); assertEquals("Id", fieldDef.getName()); assertEquals("id", fieldDef.getType()); }
@Test public void testGetSimpleFieldDefinitions() { SoqlQueryAnalyzer analyzer = new SoqlQueryAnalyzer("SELECT Id, Name FROM Account", n -> this.describeSObject(n)); List<FieldDef> actuals = listFlatFieldDefinitions(analyzer.getFieldDefinitions()); assertEquals(2, actuals.size()); assertEquals("Id", actuals.get(0).getName()); assertEquals("id", actuals.get(0).getType()); assertEquals("Name", actuals.get(1).getName()); assertEquals("string", actuals.get(1).getType()); }
@Test public void testGetReferenceFieldDefinitions() { SoqlQueryAnalyzer analyzer = new SoqlQueryAnalyzer("SELECT Account.Name FROM Contact", n -> this.describeSObject(n)); List<FieldDef> actuals = listFlatFieldDefinitions(analyzer.getFieldDefinitions()); assertEquals(1, actuals.size()); assertEquals("Name", actuals.get(0).getName()); assertEquals("string", actuals.get(0).getType()); }