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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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