-
Notifications
You must be signed in to change notification settings - Fork 230
Java sdk wip #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+132
−0
Merged
Java sdk wip #77
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f71915e
Fixing issue regarding GET and DELETE method
mestizoLopez c18fc7f
Adding unit test for DaprHttp.java
mestizoLopez 67e5a03
Adding test scope
mestizoLopez 6f9b7fd
Renaming a property and fixing conflict to merge.
mestizoLopez 15bffaf
Merge branch 'java_sdk_wip' into java_sdk_wip
artursouza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,115 @@ | ||
| /* | ||
| * Copyright (c) Microsoft Corporation. | ||
| * Licensed under the MIT License. | ||
| */ | ||
| package io.dapr.client; | ||
|
|
||
| import okhttp3.*; | ||
| import okhttp3.mock.Behavior; | ||
| import okhttp3.mock.MockInterceptor; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import reactor.core.publisher.Mono; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
|
|
||
| public class DaprHttpTest { | ||
|
|
||
| private OkHttpClient okHttpClient; | ||
|
|
||
| private MockInterceptor mockInterceptor; | ||
|
|
||
| private final String EXPECTED_RESULT = "{\"data\":\"ewoJCSJwcm9wZXJ0eUEiOiAidmFsdWVBIiwKCQkicHJvcGVydHlCIjogInZhbHVlQiIKCX0=\"}"; | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| mockInterceptor = new MockInterceptor(Behavior.UNORDERED); | ||
| okHttpClient = new OkHttpClient.Builder().addInterceptor(mockInterceptor).build(); | ||
| } | ||
|
|
||
| @Test | ||
| public void invokePostMethod() throws IOException { | ||
|
|
||
| mockInterceptor.addRule() | ||
| .post("http://localhost:3500/v1.0/state") | ||
| .respond(EXPECTED_RESULT); | ||
|
|
||
| DaprHttp daprHttp = new DaprHttp("http://localhost",3500,okHttpClient); | ||
|
|
||
| Mono<String> mono = daprHttp.invokeAPI("POST","v1.0/state",null); | ||
| assertEquals(EXPECTED_RESULT,mono.block()); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void invokeDeleteMethod() throws IOException { | ||
|
|
||
| mockInterceptor.addRule() | ||
| .delete("http://localhost:3500/v1.0/state") | ||
| .respond(EXPECTED_RESULT); | ||
|
|
||
| DaprHttp daprHttp = new DaprHttp("http://localhost",3500,okHttpClient); | ||
|
|
||
| Mono<String> mono = daprHttp.invokeAPI("DELETE","v1.0/state",null); | ||
| assertEquals(EXPECTED_RESULT,mono.block()); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void invokeGetMethod() throws IOException { | ||
|
|
||
| mockInterceptor.addRule() | ||
| .get("http://localhost:3500/v1.0/get") | ||
| .respond(EXPECTED_RESULT); | ||
|
|
||
| DaprHttp daprHttp = new DaprHttp("http://localhost",3500,okHttpClient); | ||
|
|
||
| Mono<String> mono = daprHttp.invokeAPI("GET","v1.0/get",null); | ||
|
|
||
| assertEquals(EXPECTED_RESULT,mono.block()); | ||
|
|
||
| } | ||
|
|
||
| @Test | ||
| public void invokeMethodWithHeaders() { | ||
|
|
||
| Map<String, String> headers = new HashMap<>(); | ||
| headers.put("header","value"); | ||
| headers.put("header1","value1"); | ||
|
|
||
| mockInterceptor.addRule() | ||
| .get("http://localhost:3500/v1.0/get") | ||
| .respond(EXPECTED_RESULT); | ||
| DaprHttp daprHttp = new DaprHttp("http://localhost",3500,okHttpClient); | ||
|
|
||
| Mono<String> mono = daprHttp.invokeAPI("GET","v1.0/get",headers); | ||
|
|
||
| assertEquals(EXPECTED_RESULT,mono.block()); | ||
|
|
||
| } | ||
|
|
||
| @Test(expected = RuntimeException.class) | ||
| public void invokeMethodRuntimeException(){ | ||
|
|
||
| Map<String, String> headers = new HashMap<>(); | ||
| headers.put("header","value"); | ||
| headers.put("header1","value1"); | ||
|
|
||
| mockInterceptor.addRule() | ||
| .get("http://localhost:3500/v1.0/get") | ||
| .respond(500, ResponseBody.create(MediaType.parse("application/json"), | ||
| "{\"errorCode\":\"500\",\"message\":\"Error\"}")); | ||
|
|
||
| DaprHttp daprHttp = new DaprHttp("http://localhost",3500,okHttpClient); | ||
|
|
||
| Mono<String> mono = daprHttp.invokeAPI("GET","v1.0/get",headers); | ||
|
|
||
| assertEquals(EXPECTED_RESULT,mono.block()); | ||
| } | ||
|
|
||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.