如何模拟动态(toD)端点

时间:2018-12-07 14:03:10

标签: apache-camel

嗨,

假设我必须遵循以下生产代码:

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "cross-env NODE_ENV=development node_modules/webpack/bin/webpack.js --progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js",
        "watch": "npm run development -- --watch",
        "watch-poll": "npm run watch -- --watch-poll",
        "hot": "cross-env NODE_ENV=development node_modules/webpack-dev-server/bin/webpack-dev-server.js --inline --hot --config=node_modules/laravel-mix/setup/webpack.config.js",
        "prod": "npm run production",
        "production": "cross-env NODE_ENV=production node_modules/webpack/bin/webpack.js --no-progress --hide-modules --config=node_modules/laravel-mix/setup/webpack.config.js"
    },
    "devDependencies": {},
    "dependencies": {
        "axios": "^0.18",
        "babel-preset-react": "^6.23.0",
        "cross-env": "^5.1",
        "jquery": "^3.2",
        "laravel-mix": "^2.0",
        "lodash": "^4.17.4",
        "popper.js": "^1.12",
        "react": "^16.2.0",
        "react-dom": "^16.2.0",
        "gh-pages": "^2.0.1",
        "react-icons": "^3.2.2",
        "react-redux": "^5.0.7",
        "react-scripts": "1.1.5",
        "redux": "^4.0.0",
        "styled-components": "^4.0.2",
        "react-router-dom": "^4.3.1",
        "redux-thunk": "^2.3.0"
    }
}

我如何模拟生产者端点('toD')?

我将能够猜出传递给'toD'的字符串,因为它是通过StringBoot属性设置的

1 个答案:

答案 0 :(得分:1)

在测试中,您可以使用AdviceWith并调用方法weaveByType

例如:

camelContext.getRouteDefinition("routeId").adviceWith(camelContext, new AdviceWithRouteBuilder() {
        @Override
        public void configure() {
            weaveByType(ToDynamicDefinition.class).replace().to("mock:someMock")
        }
    });

MockEndpoint someMockEndpoint = camelContext.getEndpoint("mock:someMock", MockEndpoint.class);

或者您甚至可以给生产者端点一个id并使用方法weaveById