Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sfge/src/main/java/com/salesforce/graph/Schema.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class Schema {
public static final String NAMESPACE_ACCESSIBLE = "NamespaceAccessible";
public static final String OPERATOR = "Operator";
public static final String REFERENCE_TYPE = "ReferenceType";
public static final String REMOTE_ACTION = "RemoteAction";
public static final String RETURN_TYPE = "ReturnType";
public static final String RULE_NAMES = "RulesNames";
public static final String STATIC = "Static";
Expand Down
9 changes: 9 additions & 0 deletions sfge/src/main/java/com/salesforce/graph/ops/MethodUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ public static List<MethodVertex> getNamespaceAccessibleMethods(
return getMethodsWithAnnotation(g, targetFiles, Schema.NAMESPACE_ACCESSIBLE);
}

/**
* Returns non-test methods in the target files with a @RemoteAction annotation. An empty
* list implicitly includes all files.
*/
public static List<MethodVertex> getRemoteActionMethods(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Analogous to the other methods like this.

GraphTraversalSource g, List<String> targetFiles) {
return getMethodsWithAnnotation(g, targetFiles, Schema.REMOTE_ACTION);
}

static List<MethodVertex> getMethodsWithAnnotation(
GraphTraversalSource g, List<String> targetFiles, String annotation) {
// Only look at UserClass vertices. Uninterested in Enums, Interfaces, or Triggers.
Expand Down
2 changes: 2 additions & 0 deletions sfge/src/main/java/com/salesforce/rules/RuleUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public static List<MethodVertex> getPathEntryPoints(
methods.addAll(MethodUtil.getAuraEnabledMethods(g, fileLevelTargets));
// ...and NamespaceAccessible methods...
methods.addAll(MethodUtil.getNamespaceAccessibleMethods(g, fileLevelTargets));
// ...and RemoteAction methods...
methods.addAll(MethodUtil.getRemoteActionMethods(g, fileLevelTargets));
// ...and PageReference methods...
methods.addAll(MethodUtil.getPageReferenceMethods(g, fileLevelTargets));
// ...and exposed methods on VF controllers.
Expand Down
58 changes: 29 additions & 29 deletions sfge/src/test/java/com/salesforce/graph/ops/MethodUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,20 +181,20 @@ public void getTargetMethods_targetMultipleMethods() {

MatcherAssert.assertThat(methodVertices, hasSize(equalTo(2)));

boolean method1Found = false;
boolean method2Found = false;
for (MethodVertex methodVertex : methodVertices) {
String name = methodVertex.getName();
if (METHOD_WITHOUT_OVERLOADS_1.equals(name)) {
method1Found = true;
} else if (METHOD_WITHOUT_OVERLOADS_2.equals(name)) {
method2Found = true;
} else {
fail("Unexpected method name " + name);
}
}
assertTrue(method1Found);
assertTrue(method2Found);
boolean method1Found = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace changes made by gradle.

boolean method2Found = false;
for (MethodVertex methodVertex : methodVertices) {
String name = methodVertex.getName();
if (METHOD_WITHOUT_OVERLOADS_1.equals(name)) {
method1Found = true;
} else if (METHOD_WITHOUT_OVERLOADS_2.equals(name)) {
method2Found = true;
} else {
fail("Unexpected method name " + name);
}
}
assertTrue(method1Found);
assertTrue(method2Found);
String messages = CliMessager.getInstance().getAllMessages();
assertEquals("[]", messages);
}
Expand Down Expand Up @@ -242,20 +242,20 @@ public void getTargetMethods_targetNameDupedMethods() {

MatcherAssert.assertThat(methodVertices, hasSize(equalTo(2)));

boolean line18Found = false;
boolean line22Found = false;
for (MethodVertex methodVertex : methodVertices) {
assertEquals(METHOD_WITH_EXTERNAL_NAME_DUPLICATION, methodVertex.getName());
if (methodVertex.getBeginLine() == 18) {
line18Found = true;
} else if (methodVertex.getBeginLine() == 22) {
line22Found = true;
} else {
fail("Unexpected line number " + methodVertex.getBeginLine());
}
}
assertTrue(line18Found);
assertTrue(line22Found);
boolean line18Found = false;
boolean line22Found = false;
for (MethodVertex methodVertex : methodVertices) {
assertEquals(METHOD_WITH_EXTERNAL_NAME_DUPLICATION, methodVertex.getName());
if (methodVertex.getBeginLine() == 18) {
line18Found = true;
} else if (methodVertex.getBeginLine() == 22) {
line22Found = true;
} else {
fail("Unexpected line number " + methodVertex.getBeginLine());
}
}
assertTrue(line18Found);
assertTrue(line22Found);

String messages = CliMessager.getInstance().getAllMessages();
MatcherAssert.assertThat(
Expand Down Expand Up @@ -335,7 +335,7 @@ public void getTargetMethods_targetMethodInInnerAndOuterClass() {
containsString(EventKey.WARNING_MULTIPLE_METHOD_TARGET_MATCHES.getMessageKey()));
}

@ValueSource(strings = {Schema.AURA_ENABLED, Schema.NAMESPACE_ACCESSIBLE})
@ValueSource(strings = {Schema.AURA_ENABLED, Schema.REMOTE_ACTION, Schema.NAMESPACE_ACCESSIBLE})
@ParameterizedTest(name = "{displayName}: {0}")
public void testGetMethodsWithAnnotation(String annotation) {
String[] sourceCode = {
Expand Down
40 changes: 12 additions & 28 deletions sfge/src/test/java/com/salesforce/rules/RuleUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.junit.jupiter.api.Assertions.fail;

import com.salesforce.TestUtil;
import com.salesforce.graph.Schema;
import com.salesforce.graph.vertex.MethodVertex;
import com.salesforce.metainfo.MetaInfoCollectorTestProvider;
import com.salesforce.metainfo.VisualForceHandlerImpl;
Expand All @@ -25,6 +26,8 @@
import org.hamcrest.MatcherAssert;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

public class RuleUtilTest {
private static final Logger LOGGER = LogManager.getLogger(RuleUtilTest.class);
Expand All @@ -35,16 +38,19 @@ public void setup() {
this.g = TestUtil.getGraph();
}

@Test
public void getPathEntryPoints_includesAuraEnabledMethods() {
@ValueSource(strings = {Schema.AURA_ENABLED, Schema.REMOTE_ACTION, Schema.NAMESPACE_ACCESSIBLE})
@ParameterizedTest(name = "{displayName}: {0}")
public void getPathEntryPoints_includesAnnotatedMethods(String annotation) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converted the individual tests into a parameterized test that covers all three annotations.

String sourceCode =
"public class Foo {\n"
+ " @AuraEnabled\n"
+ " public boolean auraMethod() {\n"
+ " @"
+ annotation
+ "\n"
+ " public boolean annotatedMethod() {\n"
+ " return true;\n"
+ " }\n"
+ "\n"
+ " public boolean nonAuraMethod() {\n"
+ " public boolean nonAnnotatedMethod() {\n"
+ " return true;\n"
+ " }\n"
+ "}\n";
Expand All @@ -54,29 +60,7 @@ public void getPathEntryPoints_includesAuraEnabledMethods() {

MatcherAssert.assertThat(entryPoints, hasSize(equalTo(1)));
MethodVertex firstVertex = entryPoints.get(0);
assertEquals("auraMethod", firstVertex.getName());
}

@Test
public void getPathEntryPoints_includesNamespaceAccessibleMethods() {
String sourceCode =
"public class Foo {\n"
+ " @NamespaceAccessible\n"
+ " public boolean nsMethod() {\n"
+ " return true;\n"
+ " }\n"
+ "\n"
+ " public boolean nonNsMethod() {\n"
+ " return true;\n"
+ " }\n"
+ "}\n";
TestUtil.buildGraph(g, sourceCode, true);

List<MethodVertex> entryPoints = RuleUtil.getPathEntryPoints(g);

MatcherAssert.assertThat(entryPoints, hasSize(equalTo(1)));
MethodVertex firstVertex = entryPoints.get(0);
assertEquals("nsMethod", firstVertex.getName());
assertEquals("annotatedMethod", firstVertex.getName());
}

@Test
Expand Down