-
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.
Provide links to spring academy guides in response if present
- Loading branch information
Showing
8 changed files
with
100 additions
and
17 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
45 changes: 45 additions & 0 deletions
45
src/main/java/io/spring/renderer/guides/GuideMetadata.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,45 @@ | ||
/* | ||
* Copyright 2022-2023 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.spring.renderer.guides; | ||
|
||
import io.spring.renderer.github.Repository; | ||
|
||
/** | ||
* Metadata needed to create a {@link GuideModel}. | ||
* | ||
* @author Madhura Bhave | ||
*/ | ||
class GuideMetadata { | ||
|
||
private final Repository repository; | ||
|
||
private final String academyUrl; | ||
|
||
GuideMetadata(Repository repository, String academyUrl) { | ||
this.repository = repository; | ||
this.academyUrl = academyUrl; | ||
} | ||
|
||
public Repository getRepository() { | ||
return this.repository; | ||
} | ||
|
||
public String getAcademyUrl() { | ||
return this.academyUrl; | ||
} | ||
|
||
} |
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
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
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 |
---|---|---|
|
@@ -18,8 +18,8 @@ | |
|
||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import io.spring.renderer.github.Repository; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
|
@@ -35,7 +35,8 @@ public void nullRepositoryDescription() { | |
"git://example.org/spring-guides/gs-sample-guide.git", | ||
"[email protected]:spring-guides/gs-sample-guide.git", | ||
"https://example.org/spring-guides/gs-sample-guide.git", null); | ||
GuideModel guideModel = new GuideModel(repository); | ||
GuideMetadata guideMetadata = new GuideMetadata(repository, null); | ||
GuideModel guideModel = new GuideModel(guideMetadata); | ||
assertThat(guideModel.getName()).isEqualTo("sample-guide"); | ||
assertThat(guideModel.getRepositoryName()).isEqualTo("spring-guides/gs-sample-guide"); | ||
assertThat(guideModel.getTitle()).isEmpty(); | ||
|
@@ -55,13 +56,15 @@ public void noGuideProjects() { | |
"git://example.org/spring-guides/tut-sample-guide.git", | ||
"[email protected]:spring-guides/tut-sample-guide.git", | ||
"https://example.org/spring-guides/tut-sample-guide.git", null); | ||
GuideModel guideModel = new GuideModel(repository); | ||
GuideMetadata guideMetadata = new GuideMetadata(repository, "http://test.academy"); | ||
GuideModel guideModel = new GuideModel(guideMetadata); | ||
assertThat(guideModel.getName()).isEqualTo("sample-guide"); | ||
assertThat(guideModel.getRepositoryName()).isEqualTo("spring-guides/tut-sample-guide"); | ||
assertThat(guideModel.getTitle()).isEqualTo("Title"); | ||
assertThat(guideModel.getDescription()).isEqualTo("Description"); | ||
assertThat(guideModel.getType()).isEqualTo(GuideType.TUTORIAL); | ||
assertThat(guideModel.getProjects()).isEmpty(); | ||
assertThat(guideModel.getAcademyUrl()).isEqualTo("http://test.academy"); | ||
} | ||
|
||
@Test | ||
|
@@ -72,7 +75,8 @@ public void withGuideProjects() { | |
"[email protected]:spring-guides/top-sample-guide.git", | ||
"https://example.org/spring-guides/top-sample-guide.git", | ||
Arrays.asList("spring-framework", "spring-boot")); | ||
GuideModel guideModel = new GuideModel(repository); | ||
GuideMetadata guideMetadata = new GuideMetadata(repository, null); | ||
GuideModel guideModel = new GuideModel(guideMetadata); | ||
assertThat(guideModel.getName()).isEqualTo("sample-guide"); | ||
assertThat(guideModel.getRepositoryName()).isEqualTo("spring-guides/top-sample-guide"); | ||
assertThat(guideModel.getTitle()).isEqualTo("Title"); | ||
|
@@ -90,7 +94,8 @@ public void deprecatedGuide() { | |
"[email protected]:spring-guides/deprecated-gs-sample-guide.git", | ||
"https://example.org/spring-guides/deprecated-gs-sample-guide.git", | ||
Arrays.asList("spring-framework", "spring-boot")); | ||
GuideModel guideModel = new GuideModel(repository); | ||
GuideMetadata guideMetadata = new GuideMetadata(repository, null); | ||
GuideModel guideModel = new GuideModel(guideMetadata); | ||
assertThat(guideModel.getName()).isEqualTo("deprecated-gs-sample-guide"); | ||
assertThat(guideModel.getTitle()).isEqualTo("Title"); | ||
assertThat(guideModel.getDescription()).isEqualTo("Description"); | ||
|
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 |
---|---|---|
|
@@ -19,9 +19,9 @@ | |
import java.util.Arrays; | ||
|
||
import io.spring.renderer.github.GithubClient; | ||
import io.spring.renderer.github.GithubResourceNotFoundException; | ||
import io.spring.renderer.github.Repository; | ||
import org.junit.jupiter.api.Test; | ||
import io.spring.renderer.github.GithubResourceNotFoundException; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
|
@@ -45,7 +45,7 @@ | |
/** | ||
* Tests for {@link GuidesController} | ||
*/ | ||
@WebMvcTest(GuidesController.class) | ||
@WebMvcTest(controllers = GuidesController.class, properties = "renderer.academy.gs-rest-service: http://test.com") | ||
@WithMockUser | ||
public class GuidesControllerTests { | ||
|
||
|
@@ -77,10 +77,12 @@ public void fetchAllGuides() throws Exception { | |
|
||
this.mvc.perform(get("/guides/")).andExpect(status().isOk()) | ||
.andExpect(jsonPath("$._embedded.guides[0].name").value("rest-service")) | ||
.andExpect(jsonPath("$._embedded.guides[0].academyUrl").value("http://test.com")) | ||
.andExpect(jsonPath("$._embedded.guides[0].projects[0]").value("spring-boot")) | ||
.andExpect(hasLink("$._embedded.guides[0]._links", "self", | ||
"http://localhost/guides/getting-started/rest-service")) | ||
.andExpect(jsonPath("$._embedded.guides[1].name").value("securing-web")) | ||
.andExpect(jsonPath("$._embedded.guides[1].academyUrl").isEmpty()) | ||
.andExpect(jsonPath("$._embedded.guides[1].projects").isEmpty()) | ||
.andExpect(hasLink("$._embedded.guides[1]._links", "self", | ||
"http://localhost/guides/getting-started/securing-web")); | ||
|
@@ -122,6 +124,7 @@ public void fetchGuide() throws Exception { | |
.andExpect(jsonPath("$.gitUrl").value("git://example.org/spring-guides/gs-rest-service.git")) | ||
.andExpect(jsonPath("$.sshUrl").value("[email protected]:spring-guides/gs-rest-service.git")) | ||
.andExpect(jsonPath("$.cloneUrl").value("https://example.org/spring-guides/gs-rest-service.git")) | ||
.andExpect(jsonPath("$.academyUrl").value("http://test.com")) | ||
.andExpect(jsonPath("$.projects[0]").value("spring-boot")) | ||
.andExpect(hasLink("self", "http://localhost/guides/getting-started/rest-service")); | ||
} | ||
|