From 3c19cc208168279674176dcce30e2ec9cdbeace8 Mon Sep 17 00:00:00 2001 From: Howard Gao Date: Fri, 24 Nov 2017 11:54:56 +0800 Subject: [PATCH] ARTEMIS-1521 Missing Parameter annotations in ActiveMQServerControl Added missing annotations Added test --- .../management/ActiveMQServerControl.java | 10 ++- .../management/OperationAnnotationTest.java | 84 +++++++++++++++++++ 2 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/management/OperationAnnotationTest.java diff --git a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java index 2134902307..b5150c9331 100644 --- a/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java +++ b/artemis-core-client/src/main/java/org/apache/activemq/artemis/api/core/management/ActiveMQServerControl.java @@ -795,13 +795,15 @@ public interface ActiveMQServerControl { * Closes the session with the given id. */ @Operation(desc = "Closes the session with the id", impact = MBeanOperationInfo.INFO) - boolean closeSessionWithID(String connectionID, String ID) throws Exception; + boolean closeSessionWithID(@Parameter(desc = "The connection ID", name = "connectionID") String connectionID, + @Parameter(desc = "The session ID", name = "ID") String ID) throws Exception; /** * Closes the consumer with the given id. */ @Operation(desc = "Closes the consumer with the id", impact = MBeanOperationInfo.INFO) - boolean closeConsumerWithID(String sessionID, String ID) throws Exception; + boolean closeConsumerWithID(@Parameter(desc = "The session ID", name = "sessionID") String sessionID, + @Parameter(desc = "The consumer ID", name = "ID") String ID) throws Exception; /** * Lists all the IDs of the connections connected to this server. @@ -848,7 +850,7 @@ public interface ActiveMQServerControl { * */ @Operation(desc = "List all consumers associated with a connection as a JSON string") - String listConsumersAsJSON(String connectionID) throws Exception; + String listConsumersAsJSON(@Parameter(desc = "a connection ID", name = "connectionID") String connectionID) throws Exception; /** * Lists all the consumers connected to this server. @@ -998,7 +1000,7 @@ public interface ActiveMQServerControl { @Parameter(desc = "allow topics to be created automatically", name = "autoCreateAddresses") boolean autoCreateAddresses, @Parameter(desc = "allow auto-created topics to be deleted automatically", name = "autoDeleteAddresses") boolean autoDeleteAddresses) throws Exception; - void removeAddressSettings(String addressMatch) throws Exception; + void removeAddressSettings(@Parameter(desc = "an address match", name = "addressMatch") String addressMatch) throws Exception; /** * returns the address settings as a JSON string diff --git a/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/management/OperationAnnotationTest.java b/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/management/OperationAnnotationTest.java new file mode 100644 index 0000000000..d59799aff6 --- /dev/null +++ b/artemis-core-client/src/test/java/org/apache/activemq/artemis/api/core/management/OperationAnnotationTest.java @@ -0,0 +1,84 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.activemq.artemis.api.core.management; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Collection; + +import static org.junit.Assert.assertTrue; + +@RunWith(Parameterized.class) +public class OperationAnnotationTest { + + @Parameterized.Parameters(name = "class=({0})") + public static Collection getTestParameters() { + return Arrays.asList(new Object[][]{{ActiveMQServerControl.class}, + {AddressControl.class}, + {QueueControl.class}, + {BridgeControl.class}, + {DivertControl.class}, + {AcceptorControl.class}, + {ClusterConnectionControl.class}, + {BroadcastGroupControl.class}}); + } + + private Class managementClass; + + public OperationAnnotationTest(Class managementClass) { + this.managementClass = managementClass; + } + + @Test + public void testEachParameterAnnotated() throws Exception { + checkControlInterface(managementClass); + } + + private void checkControlInterface(Class controlInterface) { + + Method[] methods = controlInterface.getMethods(); + for (Method m : methods) { + Annotation annotation = m.getAnnotation(Operation.class); + if (annotation != null) { + //each arguments must have a Parameter annotation + Class[] paramTypes = m.getParameterTypes(); + if (paramTypes.length > 0) { + Annotation[][] paramAnnotations = m.getParameterAnnotations(); + for (int i = 0; i < paramTypes.length; i++) { + //one of them must be Parameter + boolean hasParameterAnnotation = false; + for (Annotation panno : paramAnnotations[i]) { + if (panno.annotationType() == Parameter.class) { + hasParameterAnnotation = true; + break; + } + } + assertTrue("method " + m + " has parameters with no Parameter annotation", hasParameterAnnotation); + } + } + } + } + } +}