我们使用swagger codegen,我试图更改我的应用程序中的swagger.json
以获取新版本。我不知道为什么错误消息会显示一个类没有在本课程中使用它。我在provideApplication
中跟踪了代码,最后我找到了DefaultApplicationController
代码和错误行(imp.healthcheck();
),但是接口已经有了这个方法定义。
代码编译,但是当我运行测试时出现以下错误:
测试部分:
private Application provideApplication() {
return new GuiceApplicationBuilder()
.overrides(bind(Config.class).toInstance(configuration))
.in(new Environment(Mode.TEST))
.build();
}
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
petId = "1234567891";
server = Server.forRouter(components -> RoutingDsl.fromComponents(components)
.GET("/foo/v1/bar/" + petId).routeTo(() -> response("pet.json"))
.GET(PRODUCTS_PATH + "/pets/" + petId + "/cats").routeTo(() -> response("cats.json"))
.build());
setupConfiguration("http://localhost:" + server.httpPort());
app = provideApplication();
}
@Test
public void shouldProcessRequestAndReturnPets() throws Exception {
Pets expectedPets = readJson("pets.json", Pets.class);
Result result = route(app,fakeRequest(
routes.ApplicationApiController.listPets(petId)));
assertEquals(Http.Status.OK, result.status());
Optional<String> contentType = result.contentType();
assertTrue(contentType.isPresent());
assertEquals(MimeTypes.JSON, contentType.get());
Pets actualPets = deserializeResult(result, Pets.class);
assertEquals(expectedPets.get(0), actualPets.get(0));
}
错误:
[error] Test ApplicationIT.shouldProcessRequestAndReturnProducts
failed: com.google.inject.ProvisionException: Unable to provision, see
the following errors:
[error]
[error] 1) No implementation for
controllers.DefaultApiControllerImpInterface was bound.
[error] while locating controllers.DefaultApiControllerImpInterface
[error] for the 1st parameter of controllers.DefaultApiController.
<init>(DefaultApiController.java:39)
[error] while locating controllers.DefaultApiController
[error] for the 5th parameter of router.Routes.<init>
(Routes.scala:47)
[error] while locating router.Routes
[error] while locating play.api.inject.RoutesProvider
[error] while locating play.api.routing.Router
[error] for the 1st parameter of
play.api.http.JavaCompatibleHttpRequestHandler.<init>
(HttpRequestHandler.scala:222)
[error] while locating play.api.http.JavaCompatibleHttpRequestHandler
[error] while locating play.api.http.HttpRequestHandler
[error] for the 6th parameter of play.api.DefaultApplication.<init>
(Application.scala:236)
[error] at play.api.DefaultApplication.class(Application.scala:235)
[error] while locating play.api.DefaultApplication
[error] while locating play.api.Application
[error] for the 1st parameter of play.DefaultApplication.<init>
(DefaultApplication.java:32)
[error] at play.DefaultApplication.class(DefaultApplication.java:32)
[error] while locating play.DefaultApplication
[error] while locating play.Application
[error]
[error] 1 error, took 9.662 sec
[error] at
com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:1028)
[error] at
com.google.inject.internal.InjectorImpl.getInstance
(InjectorImpl.java:1054)
[error] at
play.api.inject.guice.GuiceInjector.instanceOf
(GuiceInjectorBuilder.scala:409)
[error] at
play.api.inject.ContextClassLoaderInjector.$anonfun$instanceOf$3
(Injector.scala:118)
[error] at
play.api.inject.ContextClassLoaderInjector.withContext
(Injector.scala:126)
[error] at play.api.inject.ContextClassLoaderInjector.instanceOf
(Injector.scala:118)
[error] at
play.inject.DelegateInjector.instanceOf(DelegateInjector.java:22)
[error] at play.inject.guice.GuiceApplicationBuilder.build
(GuiceApplicationBuilder.java:156)
[error] at
ApplicationIT.provideApplication
(ApplicationIT.java:47)
[error] at ApplicationIT.setUp(ApplicationIT.java:62)
[error] ...
[error] Failed: Total 1, Failed 1, Errors 0, Passed 0
[error] Failed tests:
[error] ApplicationIT
[error] (aplication/test:test) sbt.TestsFailedException: Tests
unsuccessful
[error] Total time: 17 s, completed 18-abr-2018 13:01:13
此外,这是没有实现错误的类:
import swagger.SwaggerUtils;
import swagger.SwaggerUtils.ApiAction;
@javax.annotation.Generated(value = "com.telefonica.BaikalCodegen",
date = "2018-04-18T13:00:30.424+02:00")
public class DefaultApiController extends Controller {
private final DefaultApiControllerImpInterface imp;
@Inject
private DefaultApiController(DefaultApiControllerImpInterface imp) {
this.imp = imp;
}
@ApiAction
public CompletionStage<Result> healthcheck() throws Exception {
imp.healthcheck();
return CompletableFuture.completedFuture(ok());
}
}
答案 0 :(得分:0)
DefaultApplicationController
需要实施DefaultApiControllerImpInterface
。
在您的代码中DefaultApplicationController
延伸Controller
和不 DefaultApiControllerImpInterface