-
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.
- Loading branch information
Showing
5 changed files
with
123 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
= YouTube Listener Service | ||
|
||
Listens for webhook events from PubSubHubbub, then, does nothing, yet. | ||
|
||
Check that the service is health: | ||
|
||
operation::health[snippets='httpie-request'] | ||
|
||
Post the Atom XML event to the service: | ||
|
||
operation::listen[snippets='httpie-request'] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
management.endpoint.info.enabled=true | ||
management.endpoints.web.exposure.include=health,metrics,prometheus,loggers,info | ||
|
||
spring.mvc.problemdetails.enabled=true |
94 changes: 94 additions & 0 deletions
94
src/test/java/com/javagrunt/listener/youtube/WebLayerTest.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,94 @@ | ||
package com.javagrunt.listener.youtube; | ||
|
||
import io.restassured.builder.RequestSpecBuilder; | ||
import io.restassured.specification.RequestSpecification; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.web.server.LocalServerPort; | ||
import org.springframework.restdocs.RestDocumentationContextProvider; | ||
import org.springframework.restdocs.RestDocumentationExtension; | ||
|
||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.modifyUris; | ||
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; | ||
import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.document; | ||
import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.documentationConfiguration; | ||
|
||
|
||
@ExtendWith(RestDocumentationExtension.class) | ||
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
class WebLayerTest { | ||
|
||
private RequestSpecification spec; | ||
|
||
@LocalServerPort | ||
private int port; | ||
|
||
@BeforeEach | ||
void setUp(RestDocumentationContextProvider restDocumentation) { | ||
this.spec = new RequestSpecBuilder() | ||
.addFilter(documentationConfiguration(restDocumentation)) | ||
.build(); | ||
} | ||
|
||
@Test | ||
void postShouldReturnSuccess() throws Exception { | ||
given(this.spec) | ||
.filter(document("listen", | ||
preprocessRequest(modifyUris() | ||
.scheme("https") | ||
.host("youtube-listener.javagrunt.com") | ||
.removePort()))) | ||
.contentType("application/atom+xml") | ||
.body(exampleEvent) | ||
.when() | ||
.port(this.port) | ||
.post("/") | ||
.then() | ||
.assertThat() | ||
.statusCode(is(200)); | ||
} | ||
|
||
@Test | ||
public void actuatorHealth() { | ||
given(this.spec) | ||
.filter(document("health", | ||
preprocessRequest(modifyUris() | ||
.scheme("https") | ||
.host("youtube-listener.javagrunt.com") | ||
.removePort()))) | ||
.when() | ||
.port(this.port) | ||
.get("/actuator/health") | ||
.then() | ||
.assertThat().statusCode(is(200)); | ||
} | ||
|
||
private String exampleEvent = """ | ||
<feed xmlns:yt="http://www.youtube.com/xml/schemas/2015" | ||
xmlns="http://www.w3.org/2005/Atom"> | ||
<link rel="hub" href="https://pubsubhubbub.appspot.com"/> | ||
<link rel="self" href="https://www.youtube.com/xml/feeds/videos.xml?channel_id=CHANNEL_ID"/> | ||
<title>YouTube video feed</title> | ||
<updated>2015-04-01T19:05:24.552394234+00:00</updated> | ||
<entry> | ||
<id>yt:video:VIDEO_ID</id> | ||
<yt:videoId>VIDEO_ID</yt:videoId> | ||
<yt:channelId>CHANNEL_ID</yt:channelId> | ||
<title>Video title</title> | ||
<link rel="alternate" href="http://www.youtube.com/watch?v=VIDEO_ID"/> | ||
<author> | ||
<name>Channel title</name> | ||
<uri>http://www.youtube.com/channel/CHANNEL_ID</uri> | ||
</author> | ||
<published>2015-03-06T21:40:57+00:00</published> | ||
<updated>2015-03-09T19:05:24.552394234+00:00</updated> | ||
</entry> | ||
</feed> | ||
"""; | ||
|
||
} |