Skip to content

Commit

Permalink
test working
Browse files Browse the repository at this point in the history
  • Loading branch information
dashaun committed Dec 14, 2023
1 parent 4887410 commit ecb133f
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 21 deletions.
35 changes: 15 additions & 20 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<groupId>com.javagrunt.listener</groupId>
<artifactId>youtube</artifactId>
<version>0</version>
<name>youtube</name>
<name>${project.groupId}:${project.artifactId}</name>
<properties>
<java.version>21</java.version>
</properties>
Expand Down Expand Up @@ -77,11 +77,6 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
Expand All @@ -107,9 +102,12 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
Expand All @@ -118,36 +116,33 @@
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/static/docs
</outputDirectory>
<outputDirectory>${project.build.outputDirectory}/static/docs</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
<directory>${project.build.directory}/generated-docs</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>dashaun/builder:tiny</builder>
<createdDate>now</createdDate>
<name>${project.groupId}/${project.artifactId}:v${project.version}-${os.detected.arch}</name>
</image>
</configuration>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
<configuration>
<image>
<builder>dashaun/builder:tiny</builder>
<createdDate>now</createdDate>
<name>${project.groupId}/${project.artifactId}:v${project.version}-${os.detected.arch}</name>
</image>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
11 changes: 11 additions & 0 deletions src/main/asciidoc/index.adoc
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']
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class YouTubeController {
Logger logger = LoggerFactory.getLogger(YouTubeController.class);

@PostMapping("/")
String subscriber(@RequestBody String atomXml) {
String listen(@RequestBody String atomXml) {
logger.info("Received: " + atomXml);
return "OK";
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
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 src/test/java/com/javagrunt/listener/youtube/WebLayerTest.java
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>
""";

}

0 comments on commit ecb133f

Please sign in to comment.