-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
112 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
19 changes: 19 additions & 0 deletions
19
testcontainers-dapr/src/main/java/io/dapr/testcontainers/HttpEndpoint.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,19 @@ | ||
package io.dapr.testcontainers; | ||
|
||
public class HttpEndpoint { | ||
private String name; | ||
private String baseUrl; | ||
|
||
public HttpEndpoint(String name, String baseUrl) { | ||
this.name = name; | ||
this.baseUrl = baseUrl; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getBaseUrl() { | ||
return baseUrl; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ainers-dapr/src/main/java/io/dapr/testcontainers/converter/HttpEndpointYamlConverter.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,32 @@ | ||
package io.dapr.testcontainers.converter; | ||
|
||
import io.dapr.testcontainers.HttpEndpoint; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
public class HttpEndpointYamlConverter implements YamlConverter<HttpEndpoint> { | ||
private final Yaml mapper; | ||
|
||
public HttpEndpointYamlConverter(Yaml mapper) { | ||
this.mapper = mapper; | ||
} | ||
|
||
@Override | ||
public String convert(HttpEndpoint endpoint) { | ||
Map<String, Object> endpointProps = new LinkedHashMap<>(); | ||
endpointProps.put("apiVersion", "dapr.io/v1alpha1"); | ||
endpointProps.put("kind", "HTTPEndpoint"); | ||
|
||
Map<String, String> endpointMetadata = new LinkedHashMap<>(); | ||
endpointMetadata.put("name", endpoint.getName()); | ||
endpointProps.put("metadata", endpointMetadata); | ||
|
||
Map<String, Object> endpointSpec = new LinkedHashMap<>(); | ||
endpointSpec.put("baseUrl", endpoint.getBaseUrl()); | ||
endpointProps.put("spec", endpointSpec); | ||
|
||
return mapper.dumpAsMap(endpointProps); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...rs-dapr/src/test/java/io/dapr/testcontainers/converter/HttpEndpointYamlConverterTest.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 io.dapr.testcontainers.converter; | ||
|
||
import io.dapr.testcontainers.DaprContainer; | ||
import io.dapr.testcontainers.HttpEndpoint; | ||
import org.junit.jupiter.api.Test; | ||
import org.yaml.snakeyaml.Yaml; | ||
|
||
import java.util.Set; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class HttpEndpointYamlConverterTest { | ||
private final Yaml MAPPER = YamlMapperFactory.create(); | ||
|
||
private final HttpEndpointYamlConverter converter = new HttpEndpointYamlConverter(MAPPER); | ||
|
||
@Test | ||
void testHttpEndpointToYaml() { | ||
DaprContainer dapr = new DaprContainer("daprio/daprd") | ||
.withAppName("dapr-app") | ||
.withAppPort(8081) | ||
.withHttpEndpoint(new HttpEndpoint("my-endpoint", "http://localhost:8080")) | ||
.withAppChannelAddress("host.testcontainers.internal"); | ||
|
||
Set<HttpEndpoint> endpoints = dapr.getHttpEndpoints(); | ||
assertEquals(1, endpoints.size()); | ||
|
||
HttpEndpoint endpoint = endpoints.iterator().next(); | ||
String endpointYaml = converter.convert(endpoint); | ||
String expectedEndpointYaml = | ||
"apiVersion: dapr.io/v1alpha1\n" | ||
+ "kind: HTTPEndpoint\n" | ||
+ "metadata:\n" | ||
+ " name: my-endpoint\n" | ||
+ "spec:\n" | ||
+ " baseUrl: http://localhost:8080\n"; | ||
|
||
assertEquals(expectedEndpointYaml, endpointYaml); | ||
} | ||
} |