Refactor bootique (#2380)

This commit is contained in:
Grzegorz Piwowarek 2017-08-06 13:23:19 +02:00 committed by GitHub
parent 40b3cc7d2b
commit b6e59c2ae7
8 changed files with 64 additions and 71 deletions

View File

@ -1,42 +1,41 @@
package com.baeldung.bootique;
import java.util.function.Supplier;
import com.baeldung.bootique.module.ModuleBinder;
import com.baeldung.bootique.router.IndexController;
import com.baeldung.bootique.router.SaveController;
import com.google.inject.Module;
import io.bootique.Bootique;
import io.bootique.jersey.JerseyModule;
import io.bootique.log.BootLogger;
import java.util.function.Supplier;
public class App {
public static void main(String[] args) {
Module module = binder -> JerseyModule.extend(binder).addResource(IndexController.class)
.addResource(SaveController.class);
Bootique.app(args).module(module).module(ModuleBinder.class).bootLogger(new BootLogger() {
@Override
public void trace(Supplier<String> arg0) {
// ...
}
public static void main(String[] args) {
Module module = binder -> JerseyModule.extend(binder).addResource(IndexController.class)
.addResource(SaveController.class);
Bootique.app(args).module(module).module(ModuleBinder.class).bootLogger(new BootLogger() {
@Override
public void trace(Supplier<String> arg0) {
// ...
}
@Override
public void stdout(String arg0) {
// ...
}
@Override
public void stdout(String arg0) {
// ...
}
@Override
public void stderr(String arg0, Throwable arg1) {
// ...
}
@Override
public void stderr(String arg0, Throwable arg1) {
// ...
}
@Override
public void stderr(String arg0) {
// ...
}
}).autoLoadModules().exec();
}
@Override
public void stderr(String arg0) {
// ...
}
}).autoLoadModules().exec();
}
}

View File

@ -7,9 +7,9 @@ import com.google.inject.Module;
public class ModuleBinder implements Module {
@Override
public void configure(Binder binder) {
binder.bind(HelloService.class).to(HelloServiceImpl.class);
}
@Override
public void configure(Binder binder) {
binder.bind(HelloService.class).to(HelloServiceImpl.class);
}
}

View File

@ -1,14 +1,13 @@
package com.baeldung.bootique.module;
import com.google.inject.Module;
import io.bootique.BQModuleProvider;
public class ModuleProvider implements BQModuleProvider {
@Override
public Module module() {
return new ModuleBinder();
}
@Override
public Module module() {
return new ModuleBinder();
}
}

View File

@ -5,10 +5,10 @@ import javax.ws.rs.Path;
@Path("/")
public class IndexController {
@GET
public String index() {
return "Hello, baeldung!";
}
@GET
public String index() {
return "Hello, baeldung!";
}
}

View File

@ -1,20 +1,20 @@
package com.baeldung.bootique.router;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import com.baeldung.bootique.service.HelloService;
import com.google.inject.Inject;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
@Path("/save")
public class SaveController {
@Inject
HelloService helloService;
@POST
public String save() {
return "Data Saved!";
}
@Inject
HelloService helloService;
@POST
public String save() {
return "Data Saved!";
}
}

View File

@ -1,29 +1,27 @@
package com.baeldung.bootique;
import static org.junit.Assert.assertEquals;
import org.junit.Rule;
import org.junit.Test;
import com.baeldung.bootique.service.HelloService;
import io.bootique.BQRuntime;
import io.bootique.test.junit.BQDaemonTestFactory;
import io.bootique.test.junit.BQTestFactory;
import org.junit.Rule;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class AppTest {
@Rule
public BQTestFactory bqTestFactory = new BQTestFactory();
@Rule
public BQTestFactory bqTestFactory = new BQTestFactory();
@Rule
public BQDaemonTestFactory bqDaemonTestFactory = new BQDaemonTestFactory();
@Rule
public BQDaemonTestFactory bqDaemonTestFactory = new BQDaemonTestFactory();
@Test
public void givenService_expectBoolen() {
BQRuntime runtime = bqTestFactory.app("--server").autoLoadModules().createRuntime();
HelloService service = runtime.getInstance(HelloService.class);
assertEquals(true, service.save());
}
@Test
public void givenService_expectBoolen() {
BQRuntime runtime = bqTestFactory.app("--server").autoLoadModules().createRuntime();
HelloService service = runtime.getInstance(HelloService.class);
assertEquals(true, service.save());
}
}

View File

@ -1,15 +1,11 @@
package com.baeldung.hashcode.application;
import com.baeldung.hashcode.entities.User;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class ApplicationTest {

View File

@ -38,6 +38,7 @@
<module>apache-thrift</module>
<module>autovalue</module>
<module>axon</module>
<module>bootique</module>
<module>cdi</module>
<!-- <module>core-java-9</module> -->