forked from basivireddy/hello-karyon-rxnetty
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unit tests and re-factored project structure
- Loading branch information
Darren Bathgate
committed
Nov 6, 2015
1 parent
83e6535
commit a2eae43
Showing
8 changed files
with
149 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/com/kenzan/karyon/rxnetty/endpoint/HelloEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.kenzan.karyon.rxnetty.endpoint; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.reactivex.netty.protocol.http.server.HttpServerRequest; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
import com.sun.jersey.api.uri.UriPattern; | ||
|
||
import rx.Observable; | ||
|
||
public class HelloEndpoint { | ||
|
||
public Observable<String> getHello() { | ||
return Observable.just("Hello"); | ||
} | ||
|
||
public Observable<String> getHelloName(HttpServerRequest<ByteBuf> request) { | ||
UriPattern pattern = new UriPattern(Pattern.compile("/hello/(.*)")); | ||
String name = pattern.match(request.getUri()).group(1); | ||
|
||
return Observable.just("Hello " + name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/java/com/kenzan/karyon/rxnetty/endpoint/HelloEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.kenzan.karyon.rxnetty.endpoint; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.reactivex.netty.protocol.http.server.HttpServerRequest; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import rx.Observable; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class HelloEndpointTest { | ||
|
||
@Mock | ||
private HttpServerRequest<ByteBuf> request; | ||
|
||
@Test | ||
public void helloTest() { | ||
HelloEndpoint helloEndpoint = new HelloEndpoint(); | ||
|
||
Observable<String> hello = helloEndpoint.getHello(); | ||
|
||
Assert.assertEquals("Hello", hello.toBlocking().first()); | ||
} | ||
|
||
@Test | ||
public void helloNameTest() { | ||
HelloEndpoint helloEndpoint = new HelloEndpoint(); | ||
|
||
Mockito.when(request.getUri()).thenReturn("/hello/name"); | ||
|
||
Observable<String> hello = helloEndpoint.getHelloName(request); | ||
|
||
Assert.assertEquals("Hello name", hello.toBlocking().first()); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/com/kenzan/karyon/rxnetty/resource/HelloResourceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.kenzan.karyon.rxnetty.resource; | ||
|
||
import io.netty.buffer.ByteBuf; | ||
import io.netty.channel.Channel; | ||
import io.netty.util.Attribute; | ||
import io.reactivex.netty.protocol.http.server.HttpServerRequest; | ||
import io.reactivex.netty.protocol.http.server.HttpServerResponse; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Matchers; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
import com.kenzan.karyon.rxnetty.resource.HelloResource; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class HelloResourceTest { | ||
|
||
@Mock | ||
private HttpServerRequest<ByteBuf> request; | ||
|
||
@Mock | ||
private HttpServerResponse<ByteBuf> response; | ||
|
||
@Mock | ||
private Attribute<Object> attribute; | ||
|
||
@Mock | ||
private Channel channel; | ||
|
||
@Before | ||
public void setup() { | ||
Mockito.when(channel.attr(Matchers.any())).thenReturn(attribute); | ||
Mockito.when(response.getChannel()).thenReturn(channel); | ||
} | ||
|
||
@Test | ||
public void helloTest() { | ||
HelloResource helloResource = new HelloResource(); | ||
|
||
Mockito.when(request.getUri()).thenReturn("/hello"); | ||
|
||
helloResource.handle(request, response); | ||
} | ||
|
||
@Test | ||
public void helloNameTest() { | ||
HelloResource helloResource = new HelloResource(); | ||
|
||
Mockito.when(request.getUri()).thenReturn("/hello/name"); | ||
|
||
helloResource.handle(request, response); | ||
} | ||
} |