Skip to content

Commit 1390a84

Browse files
authored
[TEST] improve REST high-level client naming conventions check (#32244)
Check the deprecated methods are effectively deprecated. Also compare the class rather than their names when checking argument types.
1 parent 042424b commit 1390a84

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/RestHighLevelClientTests.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -724,8 +724,8 @@ public void testApiNamingConventions() throws Exception {
724724
assertEquals(0, method.getExceptionTypes().length);
725725
assertEquals(3, method.getParameterTypes().length);
726726
assertThat(method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
727-
assertThat(method.getParameterTypes()[1].getName(), equalTo(RequestOptions.class.getName()));
728-
assertThat(method.getParameterTypes()[2].getName(), equalTo(ActionListener.class.getName()));
727+
assertThat(method.getParameterTypes()[1], equalTo(RequestOptions.class));
728+
assertThat(method.getParameterTypes()[2], equalTo(ActionListener.class));
729729
} else {
730730
//A few methods return a boolean rather than a response object
731731
if (apiName.equals("ping") || apiName.contains("exist")) {
@@ -738,18 +738,23 @@ public void testApiNamingConventions() throws Exception {
738738
//a few methods don't accept a request object as argument
739739
if (apiName.equals("ping") || apiName.equals("info")) {
740740
assertEquals(1, method.getParameterTypes().length);
741-
assertThat(method.getParameterTypes()[0].getName(), equalTo(RequestOptions.class.getName()));
741+
assertThat(method.getParameterTypes()[0], equalTo(RequestOptions.class));
742742
} else {
743743
assertEquals(apiName, 2, method.getParameterTypes().length);
744744
assertThat(method.getParameterTypes()[0].getSimpleName(), endsWith("Request"));
745-
assertThat(method.getParameterTypes()[1].getName(), equalTo(RequestOptions.class.getName()));
745+
assertThat(method.getParameterTypes()[1], equalTo(RequestOptions.class));
746746
}
747747

748748
boolean remove = apiSpec.remove(apiName);
749-
if (remove == false && deprecatedMethods.contains(apiName) == false) {
750-
//TODO xpack api are currently ignored, we need to load xpack yaml spec too
751-
if (apiName.startsWith("xpack.") == false) {
752-
apiNotFound.add(apiName);
749+
if (remove == false) {
750+
if (deprecatedMethods.contains(apiName)) {
751+
assertTrue("method [" + method.getName() + "], api [" + apiName + "] should be deprecated",
752+
method.isAnnotationPresent(Deprecated.class));
753+
} else {
754+
//TODO xpack api are currently ignored, we need to load xpack yaml spec too
755+
if (apiName.startsWith("xpack.") == false) {
756+
apiNotFound.add(apiName);
757+
}
753758
}
754759
}
755760
}

0 commit comments

Comments
 (0)