ratpack with google guice (#1542)
* rest with spark java * 4 * Update Application.java * indentation changes * spring @requestmapping shortcuts * removing spring requestmapping and pushing spring-mvc-java * Joining/Splitting Strings with Java and Stream API * adding more join/split functionality * changing package name * testcase change * adding webutils * adding testcase for WebUtils and ServletRequestUtils * adding testcase * spring-security-stormpath * adding ratpack module * adding pom.xml * adding following modules with updated testcase : DB, Filter, Json * adding spring-boot custom banner tutorial * changing banner format in plain text * Delete banner.txt~ * Delete b.txt~ * CORS in JAX-RS * ratpack with google guice
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package com.baeldung.guice;
|
||||
|
||||
import com.baeldung.guice.config.DependencyModule;
|
||||
import com.baeldung.guice.service.DataPumpService;
|
||||
import com.baeldung.guice.service.impl.DataPumpServiceImpl;
|
||||
|
||||
import ratpack.guice.Guice;
|
||||
import ratpack.server.RatpackServer;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
RatpackServer
|
||||
.start(server -> server.registry(Guice.registry(bindings -> bindings.module(DependencyModule.class)))
|
||||
.handlers(chain -> chain.get("randomString", ctx -> {
|
||||
DataPumpService dataPumpService = ctx.get(DataPumpService.class);
|
||||
ctx.render(dataPumpService.generate().length());
|
||||
})));
|
||||
|
||||
// RatpackServer.start(server -> server
|
||||
// .registry(Guice
|
||||
// .registry(bindings -> bindings.bindInstance(DataPumpService.class, new DataPumpServiceImpl())))
|
||||
// .handlers(chain -> chain.get("randomString", ctx -> {
|
||||
// DataPumpService dataPumpService = ctx.get(DataPumpService.class);
|
||||
// ctx.render(dataPumpService.generate());
|
||||
// })));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.guice.config;
|
||||
|
||||
import com.baeldung.guice.service.DataPumpService;
|
||||
import com.baeldung.guice.service.impl.DataPumpServiceImpl;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Scopes;
|
||||
|
||||
public class DependencyModule extends AbstractModule {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(DataPumpService.class).to(DataPumpServiceImpl.class)
|
||||
.in(Scopes.SINGLETON);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.baeldung.guice.service;
|
||||
|
||||
import com.baeldung.guice.service.impl.DataPumpServiceImpl;
|
||||
import com.google.inject.ImplementedBy;
|
||||
|
||||
@ImplementedBy(DataPumpServiceImpl.class)
|
||||
public interface DataPumpService {
|
||||
|
||||
String generate();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.baeldung.guice.service.impl;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.baeldung.guice.service.DataPumpService;
|
||||
|
||||
public class DataPumpServiceImpl implements DataPumpService {
|
||||
|
||||
@Override
|
||||
public String generate() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,22 +24,27 @@ public class ApplicationTest {
|
||||
public void givenDefaultUrl_getStaticText() {
|
||||
assertEquals("Welcome to baeldung ratpack!!!", appUnderTest.getHttpClient().getText("/"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenDynamicUrl_getDynamicText() {
|
||||
assertEquals("Hello dummybot!!!", appUnderTest.getHttpClient().getText("/dummybot"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenUrl_getListOfEmployee() throws JsonProcessingException {
|
||||
List<Employee> employees = new ArrayList<Employee>();
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
employees.add(new Employee(1L, "Mr", "John Doe"));
|
||||
employees.add(new Employee(2L, "Mr", "White Snow"));
|
||||
|
||||
|
||||
assertEquals(mapper.writeValueAsString(employees), appUnderTest.getHttpClient().getText("/data/employees"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenStaticUrl_getDynamicText() {
|
||||
assertEquals(21, appUnderTest.getHttpClient().getText("/randomString").length());
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
appUnderTest.close();
|
||||
|
||||
Reference in New Issue
Block a user