Search in sources :

Example 1 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project webtools.servertools by eclipse.

the class XmlTestCase method testServerInstance32.

/**
 * Test behavior of ServerInstance with Tomcat 3.2 default server.xml.
 */
public void testServerInstance32() {
    org.eclipse.jst.server.tomcat.core.internal.xml.server32.Server server = getXml32Server("default.serverxml.32");
    assertNotNull(server);
    org.eclipse.jst.server.tomcat.core.internal.xml.server32.ServerInstance si = new org.eclipse.jst.server.tomcat.core.internal.xml.server32.ServerInstance(server);
    assertNotNull(si.getContextManager());
    org.eclipse.jst.server.tomcat.core.internal.xml.server32.Connector[] connectors = si.getConnectors();
    assertNotNull(connectors);
    assertEquals(2, connectors.length);
    Parameter parameter = connectors[0].getParameter(0);
    assertEquals("handler", parameter.getName());
    assertEquals("org.apache.tomcat.service.http.HttpConnectionHandler", parameter.getValue());
    parameter = connectors[0].getParameter(1);
    assertEquals("port", parameter.getName());
    assertEquals("8080", parameter.getValue());
    parameter = connectors[1].getParameter(0);
    assertEquals("handler", parameter.getName());
    assertEquals("org.apache.tomcat.service.connector.Ajp12ConnectionHandler", parameter.getValue());
    parameter = connectors[1].getParameter(1);
    assertEquals("port", parameter.getName());
    assertEquals("8007", parameter.getValue());
    parameter = si.getConnector(0).getParameter(0);
    assertEquals("handler", parameter.getName());
    assertEquals("org.apache.tomcat.service.http.HttpConnectionHandler", parameter.getValue());
    parameter = si.getConnector(0).getParameter(1);
    assertEquals("port", parameter.getName());
    assertEquals("8080", parameter.getValue());
    parameter = si.getConnector(1).getParameter(0);
    assertEquals("handler", parameter.getName());
    assertEquals("org.apache.tomcat.service.connector.Ajp12ConnectionHandler", parameter.getValue());
    parameter = si.getConnector(1).getParameter(1);
    assertEquals("port", parameter.getName());
    assertEquals("8007", parameter.getValue());
    org.eclipse.jst.server.tomcat.core.internal.xml.server32.Context[] contexts = si.getContexts();
    assertNotNull(contexts);
    assertEquals(2, contexts.length);
    assertEquals("/examples", contexts[0].getPath());
    assertEquals("/admin", contexts[1].getPath());
    assertEquals("/examples", si.getContext(0).getPath());
    assertEquals("/admin", si.getContext(1).getPath());
    assertEquals("/examples", si.getContext("examples").getPath());
    assertEquals("/admin", si.getContext("/admin").getPath());
    org.eclipse.jst.server.tomcat.core.internal.xml.server32.Context context = si.createContext(2);
    context.setPath("/WebApp1");
    contexts = si.getContexts();
    assertNotNull(contexts);
    assertEquals(3, contexts.length);
    assertEquals("/examples", contexts[0].getPath());
    assertEquals("/admin", contexts[1].getPath());
    assertEquals("/WebApp1", contexts[2].getPath());
    assertEquals(new Path("/Base/work/localhost_8080%2Fexamples"), si.getContextWorkDirectory(new Path("/Base"), si.getContext("examples")));
    assertEquals(new Path("/Base/work/localhost_8080%2Fadmin"), si.getContextWorkDirectory(new Path("/Base"), si.getContext("admin")));
    assertEquals(new Path("/Base/work/localhost_8080%2FWebApp1"), si.getContextWorkDirectory(new Path("/Base"), si.getContext("WebApp1")));
    assertTrue(si.removeContext(2));
    contexts = si.getContexts();
    assertNotNull(contexts);
    assertEquals(2, contexts.length);
    assertEquals("/examples", contexts[0].getPath());
    assertEquals("/admin", contexts[1].getPath());
    context = si.createContext(2);
    context.setPath("");
    context = si.getContext("");
    assertNotNull(context);
    assertEquals("", context.getPath());
    assertEquals(new Path("/Base/work/localhost_8080"), si.getContextWorkDirectory(new Path("/Base"), si.getContext("")));
    assertEquals(si.getServerWorkDirectory(new Path("/Base")), new Path("/Base/work"));
}
Also used : Context(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Context) Path(org.eclipse.core.runtime.Path) Connector(org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector) Parameter(org.eclipse.jst.server.tomcat.core.internal.xml.server32.Parameter) ServerInstance(org.eclipse.jst.server.tomcat.core.internal.xml.server40.ServerInstance)

Example 2 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project webtools.servertools by eclipse.

the class XmlTestCase method testDefaultServerXml32.

/**
 * Test reading of the default server.xml provided by the
 * current Tomcat 3.2.
 */
public void testDefaultServerXml32() {
    org.eclipse.jst.server.tomcat.core.internal.xml.server32.Server server = getXml32Server("default.serverxml.32");
    assertNotNull(server);
    ContextManager contextManager = server.getContextManager();
    assertNotNull(contextManager);
    assertEquals(2, contextManager.getConnectorCount());
    assertNotNull(contextManager.getConnector(0));
    Parameter parameter = contextManager.getConnector(0).getParameter(0);
    assertEquals("handler", parameter.getName());
    assertEquals("org.apache.tomcat.service.http.HttpConnectionHandler", parameter.getValue());
    parameter = contextManager.getConnector(0).getParameter(1);
    assertEquals("port", parameter.getName());
    assertEquals("8080", parameter.getValue());
    assertNotNull(contextManager.getConnector(1));
    parameter = contextManager.getConnector(1).getParameter(0);
    assertEquals("handler", parameter.getName());
    assertEquals("org.apache.tomcat.service.connector.Ajp12ConnectionHandler", parameter.getValue());
    parameter = contextManager.getConnector(1).getParameter(1);
    assertEquals("port", parameter.getName());
    assertEquals("8007", parameter.getValue());
    assertEquals(2, contextManager.getContextCount());
    assertNotNull(contextManager.getContext(0));
    assertEquals("/examples", contextManager.getContext(0).getPath());
    assertNotNull(contextManager.getContext(1));
    assertEquals("/admin", contextManager.getContext(1).getPath());
}
Also used : ContextManager(org.eclipse.jst.server.tomcat.core.internal.xml.server32.ContextManager) Parameter(org.eclipse.jst.server.tomcat.core.internal.xml.server32.Parameter)

Example 3 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project cobigen by devonfw.

the class OpenAPIInputReader method extractParameters.

/**
 * @param operationOverlay overlay of the operation to get all parameters from
 * @return a list of {@link ParameterDef} from a collection of parameters of an operation
 */
private List<ParameterDef> extractParameters(Overlay<Operation> operationOverlay) {
    Collection<? extends Parameter> parameters = operationOverlay.get().getParameters();
    Collection<String> tags = operationOverlay.get().getTags();
    RequestBody requestBody = operationOverlay.get().getRequestBody();
    List<ParameterDef> parametersList = new LinkedList<>();
    ParameterDef parameter;
    for (Parameter param : parameters) {
        parameter = new ParameterDef();
        parameter.setIsBody(false);
        switch(param.getIn()) {
            case "path":
                parameter.setInPath(true);
                break;
            case "query":
                parameter.setInQuery(true);
                break;
            case "header":
                parameter.setInHeader(true);
                break;
        }
        parameter.setName(param.getName());
        Schema schema = param.getSchema();
        Map<String, Object> constraints = extractConstraints(schema);
        if (param.isRequired()) {
            constraints.put(ModelConstant.NOTNULL, true);
        } else {
            constraints.put(ModelConstant.NOTNULL, false);
        }
        parameter.setConstraints(constraints);
        parameter.setDescription(param.getDescription());
        if (schema.getType().equals(Constants.ARRAY)) {
            parameter.setIsCollection(true);
            if (schema.getItemsSchema() != null) {
                parameter.setIsEntity(true);
            }
        }
        try {
            if (Overlay.isReference(operationOverlay.getOverlay(), param.getKey())) {
                parameter.setIsEntity(true);
                parameter.setType(schema.getName());
            } else {
                parameter.setType(schema.getType());
                parameter.setFormat(schema.getFormat());
            }
        } catch (NullPointerException e) {
            throw new CobiGenRuntimeException("Error at parameter " + param.getName() + ". Invalid OpenAPI file, path parameters need to have a schema defined.");
        }
        parametersList.add(parameter);
    }
    if (requestBody != null) {
        Schema mediaSchema;
        for (String media : requestBody.getContentMediaTypes().keySet()) {
            parameter = new ParameterDef();
            parameter.setIsBody(true);
            parameter.setMediaType(media);
            if (tags.contains(Constants.SEARCH_CRITERIA) || tags.contains(Constants.SEARCH_CRITERIA.toLowerCase())) {
                parameter.setIsSearchCriteria(true);
                parameter.setName("criteria");
            }
            if (requestBody.getContentMediaTypes().get(media).getSchema() != null) {
                mediaSchema = requestBody.getContentMediaTypes().get(media).getSchema();
                parameter.setIsEntity(true);
                parameter.setType(requestBody.getContentMediaType(media).getSchema().getName());
                if (!parameter.getIsSearchCriteria()) {
                    char[] c = mediaSchema.getName().toCharArray();
                    c[0] = Character.toLowerCase(c[0]);
                    parameter.setName(new String(c));
                }
            }
            if (parameter.getType() != null) {
                Map<String, Object> constraints = new HashMap<>();
                constraints.put(ModelConstant.NOTNULL, true);
                parameter.setConstraints(constraints);
                parametersList.add(parameter);
            }
        }
    }
    return parametersList;
}
Also used : CobiGenRuntimeException(com.devonfw.cobigen.api.exception.CobiGenRuntimeException) ParameterDef(com.devonfw.cobigen.openapiplugin.model.ParameterDef) HashMap(java.util.HashMap) Schema(com.reprezen.kaizen.oasparser.model3.Schema) LinkedList(java.util.LinkedList) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) RequestBody(com.reprezen.kaizen.oasparser.model3.RequestBody)

Example 4 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project osate2 by osate.

the class SubprogramTypeImpl method createOwnedParameter.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public Parameter createOwnedParameter() {
    Parameter newOwnedParameter = (Parameter) create(Aadl2Package.eINSTANCE.getParameter());
    getOwnedParameters().add(newOwnedParameter);
    return newOwnedParameter;
}
Also used : Parameter(org.osate.aadl2.Parameter)

Example 5 with Parameter

use of com.reprezen.kaizen.oasparser.model3.Parameter in project ets-ogcapi-features10 by opengeospatial.

the class FeaturesTime method timeParameterDefinition.

/**
 * <pre>
 * Abstract Test 18: /ats/core/fc-time-definition
 * Test Purpose: Validate that the dateTime query parameters are constructed correctly.
 * Requirement: /req/core/fc-time-definition
 *
 * Test Method: Verify that the datetime query parameter complies with the following definition (using an OpenAPI Specification 3.0 fragment):
 *
 * name: datetime
 * in: query
 * required: false
 * schema:
 *   type: string
 * style: form
 * explode: false
 * </pre>
 *
 * @param testPoint
 *            the testPoint under test, never <code>null</code>
 */
@Test(description = "A.2.7. Features {root}/collections/{collectionId}/items - Datetime, Abstract Test 18: (Requirement /req/core/fc-time-definition)", dataProvider = "collectionPaths", dependsOnGroups = "featuresBase", alwaysRun = true)
public void timeParameterDefinition(TestPoint testPoint) {
    Parameter time = retrieveParameterByName(testPoint.getPath(), getApiModel(), "datetime");
    assertNotNull(time, "Required datetime parameter for collections with path '" + testPoint.getPath() + "'  in OpenAPI document is missing");
    String msg = "Expected property '%s' with value '%s' but was '%s'";
    assertEquals(time.getName(), "datetime", String.format(msg, "name", "datetime", time.getName()));
    assertEquals(time.getIn(), "query", String.format(msg, "in", "query", time.getIn()));
    assertFalse(isRequired(time), String.format(msg, "required", "false", time.getRequired()));
    assertEquals(time.getStyle(), "form", String.format(msg, "style", "form", time.getStyle()));
    assertFalse(isExplode(time), String.format(msg, "explode", "false", time.getExplode()));
    Schema schema = time.getSchema();
    assertEquals(schema.getType(), "string", String.format(msg, "schema -> type", "string", schema.getType()));
}
Also used : Schema(com.reprezen.kaizen.oasparser.model3.Schema) Parameter(com.reprezen.kaizen.oasparser.model3.Parameter) Test(org.testng.annotations.Test)

Aggregations

Parameter (com.reprezen.kaizen.oasparser.model3.Parameter)26 Path (com.reprezen.kaizen.oasparser.model3.Path)17 Operation (com.reprezen.kaizen.oasparser.model3.Operation)13 Schema (com.reprezen.kaizen.oasparser.model3.Schema)7 Parameter (org.osate.aadl2.Parameter)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 DataAccess (org.osate.aadl2.DataAccess)4 FeatureGroup (org.osate.aadl2.FeatureGroup)3 Test (org.testng.annotations.Test)3 Map (java.util.Map)2 Parameter (org.eclipse.jst.server.tomcat.core.internal.xml.server32.Parameter)2 TestPoint (org.opengis.cite.ogcapifeatures10.openapi3.TestPoint)2 AbstractFeature (org.osate.aadl2.AbstractFeature)2 ClassifierValue (org.osate.aadl2.ClassifierValue)2 DataSubcomponent (org.osate.aadl2.DataSubcomponent)2 Port (org.osate.aadl2.Port)2 SubprogramSubcomponent (org.osate.aadl2.SubprogramSubcomponent)2 CobiGenRuntimeException (com.devonfw.cobigen.api.exception.CobiGenRuntimeException)1 ParameterDef (com.devonfw.cobigen.openapiplugin.model.ParameterDef)1