This repository has been archived by the owner on Dec 23, 2019. It is now read-only.
-
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.
Feature detection mechanism cuba-platform/cuba-rest-js#20
I18n approach cuba-platform/front-generator#33 Added tests for VersionController and UserSessionController
- Loading branch information
1 parent
1cb5426
commit e85b144
Showing
3 changed files
with
98 additions
and
0 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
57 changes: 57 additions & 0 deletions
57
modules/portal/test/com/haulmont/rest/demo/http/rest/UserSessionControllerFT.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.haulmont.rest.demo.http.rest; | ||
|
||
import org.apache.http.HttpHeaders; | ||
import org.apache.http.HttpStatus; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.junit.Test; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Consumer; | ||
|
||
import static com.haulmont.rest.demo.http.rest.RestTestUtils.*; | ||
import static org.junit.Assert.*; | ||
|
||
public class UserSessionControllerFT extends AbstractRestControllerFT { | ||
|
||
@Test | ||
public void setSessionLocale() throws Exception { | ||
setSessionLocale( | ||
"en", | ||
oauthToken, | ||
response -> assertEquals(HttpStatus.SC_OK, statusCode(response)) | ||
); | ||
} | ||
|
||
@Test | ||
public void setSessionLocaleUnauthorized() throws Exception { | ||
setSessionLocale( | ||
"en", | ||
null, | ||
response -> assertEquals(HttpStatus.SC_UNAUTHORIZED, statusCode(response)) | ||
); | ||
} | ||
|
||
@Test | ||
public void setSessionLocaleUnsupported() throws Exception { | ||
setSessionLocale( | ||
"a string representing unsupported locale", | ||
oauthToken, | ||
response -> assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, statusCode(response)) | ||
); | ||
} | ||
|
||
private void setSessionLocale( | ||
String locale, @Nullable String token, Consumer<CloseableHttpResponse> assertionsCallback | ||
) throws Exception { | ||
String url = "/user-session/locale"; | ||
|
||
Map<String, String> headers = new HashMap<>(); | ||
headers.put(HttpHeaders.ACCEPT_LANGUAGE, locale); | ||
|
||
try (CloseableHttpResponse response = sendPutWithHeaders(url, token, "", null, headers)) { | ||
assertionsCallback.accept(response); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
modules/portal/test/com/haulmont/rest/demo/http/rest/VersionControllerFT.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,23 @@ | ||
package com.haulmont.rest.demo.http.rest; | ||
|
||
import org.apache.http.HttpStatus; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.junit.Test; | ||
|
||
import static com.haulmont.rest.demo.http.rest.RestTestUtils.*; | ||
import static org.junit.Assert.*; | ||
|
||
public class VersionControllerFT extends AbstractRestControllerFT { | ||
|
||
@Test | ||
public void getApiVersion() throws Exception { | ||
String url = "/version"; | ||
try (CloseableHttpResponse response = sendGet(url, oauthToken, null)) { | ||
assertEquals(HttpStatus.SC_OK, statusCode(response)); | ||
|
||
String version = responseToString(response); | ||
assertNotNull(version); | ||
assertTrue(version.length() > 0); | ||
} | ||
} | ||
} |