Search in sources :

Example 1 with MethodDescription

use of org.apache.tapestry5.plastic.MethodDescription in project tapestry-5 by apache.

the class ComponentEventImplTest method store_result_and_continue.

@Test
public void store_result_and_continue() {
    Object result = new Object();
    String methodDescription = "foo.Bar.baz()";
    ComponentEventCallback handler = mockComponentEventHandler();
    Logger logger = mockLogger();
    ComponentPageElementResources resources = mockResources();
    ComponentModel model = mockComponentModel();
    train_isDebugEnabled(logger, true);
    logger.debug(eq(TapestryMarkers.EVENT_HANDLER_METHOD), isA(String.class));
    train_handleResult(handler, result, false);
    replay();
    ComponentEvent event = new ComponentEventImpl("eventType", "someId", null, handler, resources, false, model, logger);
    event.setMethodDescription(methodDescription);
    assertFalse(event.storeResult(result));
    assertFalse(event.isAborted());
    verify();
}
Also used : ComponentModel(org.apache.tapestry5.model.ComponentModel) ComponentPageElementResources(org.apache.tapestry5.internal.structure.ComponentPageElementResources) ComponentEvent(org.apache.tapestry5.runtime.ComponentEvent) Logger(org.slf4j.Logger) ComponentEventCallback(org.apache.tapestry5.ComponentEventCallback) Test(org.testng.annotations.Test)

Example 2 with MethodDescription

use of org.apache.tapestry5.plastic.MethodDescription in project tapestry-5 by apache.

the class DefaultOpenApiDescriptionGenerator method processParameters.

private void processParameters(Method method, final String uri, final String httpMethod, final JSONObject methodDescription) {
    JSONArray parametersAsJsonArray = new JSONArray();
    for (Parameter parameter : method.getParameters()) {
        final JSONObject parameterDescription = new JSONObject();
        if (!isIgnored(parameter) && !parameter.isAnnotationPresent(StaticActivationContextValue.class)) {
            parameterDescription.put("in", "path");
        } else if (parameter.isAnnotationPresent(RequestParameter.class)) {
            parameterDescription.put("in", "query");
        } else if (parameter.isAnnotationPresent(RequestBody.class)) {
            processRequestBody(method, uri, httpMethod, methodDescription, parametersAsJsonArray, parameter);
        }
        if (!parameterDescription.isEmpty()) {
            // Optional<String> parameterName = getValue(method, uri, httpMethod, parameter, "name");
            // parameterDescription.put("name", parameterName.orElse(parameter.getName()));
            parameterDescription.put("name", getParameterName(parameter));
            getValue(method, uri, httpMethod, parameter, "description").ifPresent((v) -> parameterDescription.put("description", v));
            typeDescriber.describe(parameterDescription, parameter);
            parametersAsJsonArray.add(parameterDescription);
        }
    }
    if (!parametersAsJsonArray.isEmpty()) {
        methodDescription.put("parameters", parametersAsJsonArray);
    }
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) RequestParameter(org.apache.tapestry5.annotations.RequestParameter) JSONArray(org.apache.tapestry5.json.JSONArray) ActivationContextParameter(org.apache.tapestry5.annotations.ActivationContextParameter) RequestParameter(org.apache.tapestry5.annotations.RequestParameter) Parameter(java.lang.reflect.Parameter)

Example 3 with MethodDescription

use of org.apache.tapestry5.plastic.MethodDescription in project tapestry-5 by apache.

the class DefaultOpenApiDescriptionGenerator method processResponses.

private void processResponses(Method method, final String uri, final String httpMethod, final JSONObject methodDescription) {
    JSONObject responses = new JSONObject();
    JSONObject defaultResponse = new JSONObject();
    int statusCode = httpMethod.equals("post") || httpMethod.equals("put") ? HttpServletResponse.SC_CREATED : HttpServletResponse.SC_OK;
    putIfNotEmpty(defaultResponse, "description", getValue(method, uri, httpMethod, statusCode));
    responses.put(String.valueOf(statusCode), defaultResponse);
    String[] produces = getProducedMediaTypes(method);
    if (produces != null && produces.length > 0) {
        JSONObject contentDescription = new JSONObject();
        for (String mediaType : produces) {
            JSONObject responseTypeDescription = new JSONObject();
            typeDescriber.describeReturnType(responseTypeDescription, method);
            contentDescription.put(mediaType, responseTypeDescription);
        }
        defaultResponse.put("content", contentDescription);
    }
    methodDescription.put("responses", responses);
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject)

Example 4 with MethodDescription

use of org.apache.tapestry5.plastic.MethodDescription in project tapestry-5 by apache.

the class HeartbeatDeferredWorkerTest method testFailure.

private void testFailure(MethodDescription description, String messageFragment) {
    PlasticMethod method = newMock(PlasticMethod.class);
    boolean isVoid = description.returnType.equals("void");
    expect(method.isVoid()).andReturn(isVoid);
    if (isVoid) {
        expect(method.getDescription()).andReturn(description).atLeastOnce();
    }
    expect(method.getMethodIdentifier()).andReturn("<MethodId>");
    replay();
    try {
        worker.deferMethodInvocations(method);
        unreachable();
    } catch (RuntimeException ex) {
        assertMessageContains(ex, messageFragment);
    }
    verify();
}
Also used : PlasticMethod(org.apache.tapestry5.plastic.PlasticMethod)

Example 5 with MethodDescription

use of org.apache.tapestry5.plastic.MethodDescription in project tapestry-5 by apache.

the class TapestryModule method add.

private static void add(OrderedConfiguration<ComponentClassTransformWorker2> configuration, Class<? extends Annotation> annotationClass, MethodDescription description) {
    String name = TapestryInternalUtils.lastTerm(annotationClass.getName());
    ComponentClassTransformWorker2 worker = new PageLifecycleAnnotationWorker(annotationClass, description, name);
    configuration.add(name, worker);
}
Also used : ComponentClassTransformWorker2(org.apache.tapestry5.services.transform.ComponentClassTransformWorker2) PageLifecycleAnnotationWorker(org.apache.tapestry5.internal.transform.PageLifecycleAnnotationWorker)

Aggregations

JSONObject (org.apache.tapestry5.json.JSONObject)4 Method (java.lang.reflect.Method)2 ComponentEventCallback (org.apache.tapestry5.ComponentEventCallback)2 ComponentPageElementResources (org.apache.tapestry5.internal.structure.ComponentPageElementResources)2 JSONArray (org.apache.tapestry5.json.JSONArray)2 ComponentModel (org.apache.tapestry5.model.ComponentModel)2 ComponentEvent (org.apache.tapestry5.runtime.ComponentEvent)2 Logger (org.slf4j.Logger)2 Test (org.testng.annotations.Test)2 IFn (clojure.lang.IFn)1 Symbol (clojure.lang.Symbol)1 Parameter (java.lang.reflect.Parameter)1 ActivationContextParameter (org.apache.tapestry5.annotations.ActivationContextParameter)1 RequestParameter (org.apache.tapestry5.annotations.RequestParameter)1 RestInfo (org.apache.tapestry5.annotations.RestInfo)1 Namespace (org.apache.tapestry5.clojure.Namespace)1 StrategyRegistry (org.apache.tapestry5.commons.util.StrategyRegistry)1 PageLifecycleAnnotationWorker (org.apache.tapestry5.internal.transform.PageLifecycleAnnotationWorker)1 ClassInstantiator (org.apache.tapestry5.plastic.ClassInstantiator)1 InstructionBuilder (org.apache.tapestry5.plastic.InstructionBuilder)1