All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jmms.testing.server.TestRoutes Maven / Gradle / Ivy

/*
 * Copyright 2018 the original author or authors.
 *
 * Licensed 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 jmms.testing.server;

import jmms.testing.TestSuite;
import leap.core.web.path.PathTemplate;
import leap.lang.ExtensibleBase;
import leap.web.App;
import leap.web.route.AbstractNestedRoute;
import leap.web.route.NestedRoute;
import leap.web.route.Route;
import leap.web.route.Routes;

import java.util.Map;

class TestRoutes extends AbstractNestedRoute implements NestedRoute {

    private final App          app;
    private final PathTemplate pathTemplate;

    private SuiteAndRoutes suiteAndRoutes;

    TestRoutes(App app, PathTemplate pathTemplate) {
        this.app          = app;
        this.pathTemplate = pathTemplate;
    }

    void accept(SuiteAndRoutes suiteAndRoutes) {
        if(!app.routes().exists(this)) {
            app.routes().add(this);
        }
        this.suiteAndRoutes = suiteAndRoutes;
    }

    @Override
    public Route matchNested(String method, String path, Map in, Map outVariables) {
        if(null == suiteAndRoutes) {
            return null;
        }
        return suiteAndRoutes.routes.match(method, path, in, outVariables);
    }

    @Override
    public boolean isCheckAmbiguity() {
        return false;
    }

    @Override
    public Object getSource() {
        return "jmms";
    }

    @Override
    public String getMethod() {
        return "*";
    }

    @Override
    public PathTemplate getPathTemplate() {
        return pathTemplate;
    }

    static final class SuiteAndRoutes {
        final TestSuite suite;
        final Routes    routes;

        public SuiteAndRoutes(TestSuite suite, Routes routes) {
            this.suite = suite;
            this.routes = routes;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy