Skip to content

Commit

Permalink
Upgrade github workflow action versions and dependencies version (#688)
Browse files Browse the repository at this point in the history
- Upgrade github checkout action version.
 - Upgrade spring boot version
 - Add inline template doc and sample code
  • Loading branch information
yinan-symphony authored Nov 16, 2022
1 parent d47c1c3 commit 0c8fd1d
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 23 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK 1.8
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: 1.8
distribution: 'adopt'
java-version: '8'
- name: Cache Gradle packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gradle-wrapper-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ jobs:
name: "Validation"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: gradle/wrapper-validation-action@v1
9 changes: 5 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK 1.8
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: 1.8
distribution: 'adopt'
java-version: '8'
- name: Cache Gradle packages
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
Expand Down
19 changes: 19 additions & 0 deletions docs/message.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ engine implementations:
> In the code examples below, we will assume that FreeMarker as been selected as template engine implementation.
> See [how to select the template engine implementation](#select-your-template-engine-implementation).
#### Template file

First you need to define your message template file. Here `src/main/resources/templates/simple.ftl`:
```
<messageML>Hello, ${name}!</messageML>
Expand Down Expand Up @@ -125,5 +127,22 @@ dependencies {
> :warning: If multiple implementations found in classpath, an exception is throw in order to help you to define which one
> your project really needs to use.

#### Inline template string

Simple template can be created as an inline template. Take the same example above, simply pass the template string to the function, such like

```java
public class Example {

public static void main(String[] args) {
final SymphonyBdk bdk = new SymphonyBdk(loadFromClasspath("/config.yaml"));
final Template template = bdk.messages().templates().newTemplateFromString("<messageML>Hello, ${name}!</messageML>");
final String content = template.process(Collections.singletonMap("name", "Freemarker"));
log.info(content);
}
}
```

----
[Home :house:](./index.md)
8 changes: 4 additions & 4 deletions symphony-bdk-bom/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ repositories {

dependencies {
// import Spring Boot's BOM
api platform('org.springframework.boot:spring-boot-dependencies:2.7.3')
api platform('org.springframework.boot:spring-boot-dependencies:2.7.5')
// import Jackson's BOM
api platform('com.fasterxml.jackson:jackson-bom:2.13.2.20220328')
api platform('com.fasterxml.jackson:jackson-bom:2.13.4.20221013')
// define all our dependencies versions
constraints {
// Internal modules dependencies (Keep them first)
Expand Down Expand Up @@ -88,8 +88,8 @@ dependencies {
api 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
api 'com.tngtech.archunit:archunit-junit5:0.22.0'
api 'org.mock-server:mockserver-netty:5.12.0'
api 'org.mockito:mockito-core:4.3.1'
api 'org.mockito:mockito-junit-jupiter:4.3.1'
api 'org.mockito:mockito-core:4.5.1'
api 'org.mockito:mockito-junit-jupiter:4.5.1'
api 'org.assertj:assertj-core:3.22.0'
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@

import io.netty.channel.ConnectTimeoutException;
import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.web.reactive.function.client.WebClientRequestException;

import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.URI;

import javax.annotation.Nonnull;
import javax.ws.rs.ProcessingException;
Expand All @@ -38,12 +40,14 @@ public TestAbstractOboAuthenticator(BdkRetryConfig retryConfig) {
}

@Override
protected String authenticateAndRetrieveOboSessionToken(@Nonnull String appSessionToken, @Nonnull Long userId) throws ApiException {
protected String authenticateAndRetrieveOboSessionToken(@Nonnull String appSessionToken, @Nonnull Long userId)
throws ApiException {
return null;
}

@Override
protected String authenticateAndRetrieveOboSessionToken(@Nonnull String appSessionToken, @Nonnull String username) throws ApiException {
protected String authenticateAndRetrieveOboSessionToken(@Nonnull String appSessionToken, @Nonnull String username)
throws ApiException {
return null;
}

Expand Down Expand Up @@ -172,7 +176,9 @@ void testRetrieveTokenByUsernameShouldRetry() throws ApiException, AuthUnauthori
doReturn("").when(authenticator).retrieveAppSessionToken();
doThrow(new ApiException(429, ""))
.doThrow(new ApiException(503, ""))
.doThrow(new WebClientRequestException(new ConnectTimeoutException(), HttpMethod.GET, null, null))
.doThrow(
new WebClientRequestException(new ConnectTimeoutException(), HttpMethod.GET, URI.create("http://localhost"),
new HttpHeaders()))
.doReturn(token).when(authenticator).authenticateAndRetrieveOboSessionToken(anyString(), anyString());

assertEquals(token, authenticator.retrieveOboSessionTokenByUsername(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
import com.symphony.bdk.http.api.ApiRuntimeException;

import org.junit.jupiter.api.Test;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.web.reactive.function.client.WebClientRequestException;

import java.net.SocketTimeoutException;
import java.net.URI;

class AuthenticationRetryTest {

Expand All @@ -27,7 +29,7 @@ void testCallSucceedsFirstTime() throws AuthUnauthorizedException {
AuthenticationRetry<String> authenticationRetry = new AuthenticationRetry<>(ofMinimalInterval(1));

final String output = "output";
assertEquals(output, authenticationRetry.executeAndRetry("test", "addressTest", () -> output, ""));
assertEquals(output, authenticationRetry.executeAndRetry("test", "addressTest", () -> output, ""));
}

@Test
Expand All @@ -38,7 +40,7 @@ void testCallFailsWithServerErrorSucceedsSecondTime() throws ApiException, AuthU
when(supplier.get()).thenThrow(new ApiException(502, "")).thenReturn(output);

AuthenticationRetry<String> authenticationRetry = new AuthenticationRetry<>(ofMinimalInterval(2));
assertEquals(output, authenticationRetry.executeAndRetry("test","addressTest", supplier, ""));
assertEquals(output, authenticationRetry.executeAndRetry("test", "addressTest", supplier, ""));

verify(supplier, times(2)).get();
verifyNoMoreInteractions(supplier);
Expand All @@ -64,7 +66,8 @@ void testCallFailsWithProcessingExceptionSucceedsSecondTime() throws AuthUnautho

SupplierWithApiException<String> supplier = mock(SupplierWithApiException.class);
when(supplier.get()).thenThrow(
new WebClientRequestException(new SocketTimeoutException(), HttpMethod.GET, null, null)).thenReturn(output);
new WebClientRequestException(new SocketTimeoutException(), HttpMethod.GET, URI.create("http://localhost"),
new HttpHeaders())).thenReturn(output);

AuthenticationRetry<String> authenticationRetry = new AuthenticationRetry<>(ofMinimalInterval(2));

Expand All @@ -80,7 +83,8 @@ void testCallFailsAfterRetriesExhausted() throws ApiException {

AuthenticationRetry<String> authenticationRetry = new AuthenticationRetry<>(ofMinimalInterval(2));

assertThrows(ApiRuntimeException.class, () -> authenticationRetry.executeAndRetry("test", "addressTest", supplier, ""));
assertThrows(ApiRuntimeException.class,
() -> authenticationRetry.executeAndRetry("test", "addressTest", supplier, ""));
verify(supplier, times(2)).get();
verifyNoMoreInteractions(supplier);
}
Expand All @@ -92,7 +96,8 @@ void testCallFailsWithUnauthorized() throws ApiException {

AuthenticationRetry<String> authenticationRetry = new AuthenticationRetry<>(ofMinimalInterval(2));

assertThrows(AuthUnauthorizedException.class, () -> authenticationRetry.executeAndRetry("test", "addressTest", supplier, ""));
assertThrows(AuthUnauthorizedException.class,
() -> authenticationRetry.executeAndRetry("test", "addressTest", supplier, ""));
verify(supplier, times(1)).get();
verifyNoMoreInteractions(supplier);
}
Expand All @@ -104,7 +109,8 @@ void testCallFailsWithUnexpectedApiException() throws ApiException {

AuthenticationRetry<String> authenticationRetry = new AuthenticationRetry<>(ofMinimalInterval(2));

assertThrows(ApiRuntimeException.class, () -> authenticationRetry.executeAndRetry("test", "addressTest", supplier, ""));
assertThrows(ApiRuntimeException.class,
() -> authenticationRetry.executeAndRetry("test", "addressTest", supplier, ""));
verify(supplier, times(1)).get();
verifyNoMoreInteractions(supplier);
}
Expand All @@ -116,7 +122,8 @@ void testCallFailsWithUnexpectedError() throws ApiException {

AuthenticationRetry<String> authenticationRetry = new AuthenticationRetry<>(ofMinimalInterval(2));

assertThrows(RuntimeException.class, () -> authenticationRetry.executeAndRetry("test", "addressTest", supplier, ""));
assertThrows(RuntimeException.class,
() -> authenticationRetry.executeAndRetry("test", "addressTest", supplier, ""));
verify(supplier, times(1)).get();
verifyNoMoreInteractions(supplier);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,16 @@ public static void main(String[] args) throws Exception {

// display processed template content
log.info(content);

// load inline template
final Template inlineTemplate = bdk.messages().templates().newTemplateFromString("<messageML>\n"
+ " This is a complex message, that supports ${name} templating\n"
+ "</messageML>");

// process template with some vars and retrieve content
final String inlineContent = inlineTemplate.process(Collections.singletonMap("name", "Freemarker"));

// display processed template content
log.info(inlineContent);
}
}

0 comments on commit 0c8fd1d

Please sign in to comment.