mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-18 17:48:14 +08:00
Migrate tests to AssertJ
Refactor all existing tests to use AssertJ assertions.
This commit is contained in:
0
initializr-web/src/test/java/io/spring/initializr/web/AbstractFullStackInitializrIntegrationTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/AbstractFullStackInitializrIntegrationTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/AbstractInitializrControllerIntegrationTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/AbstractInitializrControllerIntegrationTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/AbstractInitializrIntegrationTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/AbstractInitializrIntegrationTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/autoconfigure/CloudfoundryEnvironmentPostProcessorTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/autoconfigure/CloudfoundryEnvironmentPostProcessorTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/autoconfigure/InitializrAutoConfigurationTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/autoconfigure/InitializrAutoConfigurationTests.java
Normal file → Executable file
22
initializr-web/src/test/java/io/spring/initializr/web/mapper/DependencyMetadataJsonMapperTests.java
Normal file → Executable file
22
initializr-web/src/test/java/io/spring/initializr/web/mapper/DependencyMetadataJsonMapperTests.java
Normal file → Executable file
@@ -27,7 +27,7 @@ import io.spring.initializr.util.Version;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -51,16 +51,16 @@ public class DependencyMetadataJsonMapperTests {
|
||||
Collections.singletonMap("repo-id", repository),
|
||||
Collections.singletonMap("bom-id", bom));
|
||||
JSONObject content = new JSONObject(this.mapper.write(metadata));
|
||||
assertEquals("my-bom", content.getJSONObject("dependencies").getJSONObject("foo")
|
||||
.getString("bom"));
|
||||
assertEquals("my-repo", content.getJSONObject("dependencies").getJSONObject("foo")
|
||||
.getString("repository"));
|
||||
assertEquals("foo-repo", content.getJSONObject("repositories")
|
||||
.getJSONObject("repo-id").getString("name"));
|
||||
assertEquals("foo-bom", content.getJSONObject("boms").getJSONObject("bom-id")
|
||||
.getString("artifactId"));
|
||||
assertEquals("1.0.0.RELEASE", content.getJSONObject("boms")
|
||||
.getJSONObject("bom-id").getString("version"));
|
||||
assertThat(content.getJSONObject("dependencies").getJSONObject("foo")
|
||||
.getString("bom")).isEqualTo("my-bom");
|
||||
assertThat(content.getJSONObject("dependencies").getJSONObject("foo")
|
||||
.getString("repository")).isEqualTo("my-repo");
|
||||
assertThat(content.getJSONObject("repositories").getJSONObject("repo-id")
|
||||
.getString("name")).isEqualTo("foo-repo");
|
||||
assertThat(content.getJSONObject("boms").getJSONObject("bom-id")
|
||||
.getString("artifactId")).isEqualTo("foo-bom");
|
||||
assertThat(content.getJSONObject("boms").getJSONObject("bom-id")
|
||||
.getString("version")).isEqualTo("1.0.0.RELEASE");
|
||||
}
|
||||
|
||||
}
|
||||
|
17
initializr-web/src/test/java/io/spring/initializr/web/mapper/InitializrMetadataJsonMapperTests.java
Normal file → Executable file
17
initializr-web/src/test/java/io/spring/initializr/web/mapper/InitializrMetadataJsonMapperTests.java
Normal file → Executable file
@@ -26,8 +26,7 @@ import io.spring.initializr.metadata.Link;
|
||||
import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -45,10 +44,9 @@ public class InitializrMetadataJsonMapperTests {
|
||||
.addDependencyGroup("foo", "one", "two").build();
|
||||
String json = this.jsonMapper.write(metadata, null);
|
||||
JsonNode result = objectMapper.readTree(json);
|
||||
assertEquals(
|
||||
assertThat(get(result, "_links.foo.href")).isEqualTo(
|
||||
"/foo.zip?type=foo{&dependencies,packaging,javaVersion,language,bootVersion,"
|
||||
+ "groupId,artifactId,version,name,description,packageName}",
|
||||
get(result, "_links.foo.href"));
|
||||
+ "groupId,artifactId,version,name,description,packageName}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -58,10 +56,9 @@ public class InitializrMetadataJsonMapperTests {
|
||||
.addDependencyGroup("foo", "one", "two").build();
|
||||
String json = this.jsonMapper.write(metadata, "http://server:8080/my-app");
|
||||
JsonNode result = objectMapper.readTree(json);
|
||||
assertEquals(
|
||||
assertThat(get(result, "_links.foo.href")).isEqualTo(
|
||||
"http://server:8080/my-app/foo.zip?type=foo{&dependencies,packaging,javaVersion,"
|
||||
+ "language,bootVersion,groupId,artifactId,version,name,description,packageName}",
|
||||
get(result, "_links.foo.href"));
|
||||
+ "language,bootVersion,groupId,artifactId,version,name,description,packageName}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,8 +72,8 @@ public class InitializrMetadataJsonMapperTests {
|
||||
int first = json.indexOf("https://example.com/how-to");
|
||||
int second = json.indexOf("https://example.com/doc");
|
||||
// JSON objects are not ordered
|
||||
assertTrue(first > 0);
|
||||
assertTrue(second > 0);
|
||||
assertThat(first > 0).isTrue();
|
||||
assertThat(second > 0).isTrue();
|
||||
}
|
||||
|
||||
private Object get(JsonNode result, String path) {
|
||||
|
41
initializr-web/src/test/java/io/spring/initializr/web/mapper/LinkMapperTests.java
Normal file → Executable file
41
initializr-web/src/test/java/io/spring/initializr/web/mapper/LinkMapperTests.java
Normal file → Executable file
@@ -24,8 +24,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.spring.initializr.metadata.Link;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link LinkMapper}.
|
||||
@@ -39,12 +38,12 @@ public class LinkMapperTests {
|
||||
List<Link> links = new ArrayList<>();
|
||||
links.add(Link.create("a", "https://example.com", "some description"));
|
||||
ObjectNode model = LinkMapper.mapLinks(links);
|
||||
assertEquals(1, model.size());
|
||||
assertTrue(model.has("a"));
|
||||
assertThat(model).hasSize(1);
|
||||
assertThat(model.has("a")).isTrue();
|
||||
ObjectNode linkModel = (ObjectNode) model.get("a");
|
||||
assertEquals(2, linkModel.size());
|
||||
assertEquals("https://example.com", linkModel.get("href").textValue());
|
||||
assertEquals("some description", linkModel.get("title").textValue());
|
||||
assertThat(linkModel).hasSize(2);
|
||||
assertThat(linkModel.get("href").textValue()).isEqualTo("https://example.com");
|
||||
assertThat(linkModel.get("title").textValue()).isEqualTo("some description");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,13 +51,13 @@ public class LinkMapperTests {
|
||||
List<Link> links = new ArrayList<>();
|
||||
links.add(Link.create("a", "https://example.com/{bootVersion}/a", true));
|
||||
ObjectNode model = LinkMapper.mapLinks(links);
|
||||
assertEquals(1, model.size());
|
||||
assertTrue(model.has("a"));
|
||||
assertThat(model).hasSize(1);
|
||||
assertThat(model.has("a")).isTrue();
|
||||
ObjectNode linkModel = (ObjectNode) model.get("a");
|
||||
assertEquals(2, linkModel.size());
|
||||
assertEquals("https://example.com/{bootVersion}/a",
|
||||
linkModel.get("href").textValue());
|
||||
assertEquals(true, linkModel.get("templated").booleanValue());
|
||||
assertThat(linkModel).hasSize(2);
|
||||
assertThat(linkModel.get("href").textValue())
|
||||
.isEqualTo("https://example.com/{bootVersion}/a");
|
||||
assertThat(linkModel.get("templated").booleanValue()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,12 +66,14 @@ public class LinkMapperTests {
|
||||
links.add(Link.create("a", "https://example.com", "some description"));
|
||||
links.add(Link.create("a", "https://example.com/2"));
|
||||
ObjectNode model = LinkMapper.mapLinks(links);
|
||||
assertEquals(1, model.size());
|
||||
assertTrue(model.has("a"));
|
||||
assertThat(model).hasSize(1);
|
||||
assertThat(model.has("a")).isTrue();
|
||||
ArrayNode linksModel = (ArrayNode) model.get("a");
|
||||
assertEquals(2, linksModel.size());
|
||||
assertEquals("https://example.com", linksModel.get(0).get("href").textValue());
|
||||
assertEquals("https://example.com/2", linksModel.get(1).get("href").textValue());
|
||||
assertThat(linksModel).hasSize(2);
|
||||
assertThat(linksModel.get(0).get("href").textValue())
|
||||
.isEqualTo("https://example.com");
|
||||
assertThat(linksModel.get(1).get("href").textValue())
|
||||
.isEqualTo("https://example.com/2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,7 +83,7 @@ public class LinkMapperTests {
|
||||
links.add(Link.create("second", "https://example.com"));
|
||||
ObjectNode model = LinkMapper.mapLinks(links);
|
||||
String json = model.toString();
|
||||
assertTrue(json.indexOf("first") < json.indexOf("second"));
|
||||
assertThat(json.indexOf("first") < json.indexOf("second")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,7 +94,7 @@ public class LinkMapperTests {
|
||||
links.add(Link.create("first", "https://example.com"));
|
||||
ObjectNode model = LinkMapper.mapLinks(links);
|
||||
String json = model.toString();
|
||||
assertTrue(json.indexOf("first") < json.indexOf("second"));
|
||||
assertThat(json.indexOf("first") < json.indexOf("second")).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
0
initializr-web/src/test/java/io/spring/initializr/web/project/CommandLineExampleIntegrationTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/project/CommandLineExampleIntegrationTests.java
Normal file → Executable file
7
initializr-web/src/test/java/io/spring/initializr/web/project/LegacyStsControllerIntegrationTests.java
Normal file → Executable file
7
initializr-web/src/test/java/io/spring/initializr/web/project/LegacyStsControllerIntegrationTests.java
Normal file → Executable file
@@ -33,6 +33,7 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.web.servlet.resource.ResourceUrlProvider;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -46,8 +47,8 @@ public class LegacyStsControllerIntegrationTests
|
||||
@Test
|
||||
public void legacyStsHome() {
|
||||
String body = htmlHome();
|
||||
assertTrue("groupId not found", body.contains("com.example"));
|
||||
assertTrue("artifactId not found", body.contains("demo"));
|
||||
assertThat(body.contains("com.example")).as("groupId not found").isTrue();
|
||||
assertThat(body.contains("demo")).as("artifactId not found").isTrue();
|
||||
assertTrue("custom description not found",
|
||||
body.contains("Demo project for Spring Boot"));
|
||||
assertTrue("Wrong body:\n" + body, body
|
||||
@@ -76,4 +77,4 @@ public class LegacyStsControllerIntegrationTests
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
15
initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerDefaultsIntegrationTests.java
Normal file → Executable file
15
initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerDefaultsIntegrationTests.java
Normal file → Executable file
@@ -22,7 +22,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -46,11 +46,12 @@ public class MainControllerDefaultsIntegrationTests
|
||||
@Test
|
||||
public void defaultsAppliedToHome() {
|
||||
String body = htmlHome();
|
||||
assertTrue("custom groupId not found", body.contains("org.foo"));
|
||||
assertTrue("custom artifactId not found", body.contains("foo-bar"));
|
||||
assertTrue("custom name not found", body.contains("FooBar"));
|
||||
assertTrue("custom description not found", body.contains("FooBar Project"));
|
||||
assertTrue("custom package not found", body.contains("org.foo.demo"));
|
||||
assertThat(body.contains("org.foo")).as("custom groupId not found").isTrue();
|
||||
assertThat(body.contains("foo-bar")).as("custom artifactId not found").isTrue();
|
||||
assertThat(body.contains("FooBar")).as("custom name not found").isTrue();
|
||||
assertThat(body.contains("FooBar Project")).as("custom description not found")
|
||||
.isTrue();
|
||||
assertThat(body.contains("org.foo.demo")).as("custom package not found").isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
6
initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerDependenciesTests.java
Normal file → Executable file
6
initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerDependenciesTests.java
Normal file → Executable file
@@ -27,9 +27,9 @@ import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -42,7 +42,7 @@ public class MainControllerDependenciesTests
|
||||
public void noBootVersion() throws JSONException {
|
||||
ResponseEntity<String> response = execute("/dependencies", String.class, null,
|
||||
"application/json");
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
|
||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateDependenciesOutput("1.1.4", response.getBody());
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public class MainControllerDependenciesTests
|
||||
ResponseEntity<String> response = execute(
|
||||
"/dependencies?bootVersion=1.2.1.RELEASE", String.class, null,
|
||||
"application/json");
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
|
||||
validateContentType(response, CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateDependenciesOutput("1.2.1", response.getBody());
|
||||
}
|
||||
|
12
initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerEnvIntegrationTests.java
Normal file → Executable file
12
initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerEnvIntegrationTests.java
Normal file → Executable file
@@ -26,8 +26,7 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
@@ -41,17 +40,18 @@ public class MainControllerEnvIntegrationTests
|
||||
public void downloadCliWithCustomRepository() throws Exception {
|
||||
ResponseEntity<?> entity = getRestTemplate().getForEntity(createUrl("/spring"),
|
||||
String.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
String expected = "https://repo.spring.io/lib-release/org/springframework/boot/spring-boot-cli/1.1.4.RELEASE/spring-boot-cli-1.1.4.RELEASE-bin.zip";
|
||||
assertEquals(new URI(expected), entity.getHeaders().getLocation());
|
||||
assertThat(entity.getHeaders().getLocation()).isEqualTo(new URI(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void doNotForceSsl() {
|
||||
ResponseEntity<String> response = invokeHome("curl/1.2.4", "*/*");
|
||||
String body = response.getBody();
|
||||
assertTrue("Must not force https", body.contains("http://start.spring.io/"));
|
||||
assertFalse("Must not force https", body.contains("https://"));
|
||||
assertThat(body.contains("http://start.spring.io/")).as("Must not force https")
|
||||
.isTrue();
|
||||
assertThat(body.contains("https://")).as("Must not force https").isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
91
initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerIntegrationTests.java
Normal file → Executable file
91
initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerIntegrationTests.java
Normal file → Executable file
@@ -36,16 +36,8 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.allOf;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -87,7 +79,7 @@ public class MainControllerIntegrationTests
|
||||
(String[]) null);
|
||||
}
|
||||
catch (HttpClientErrorException ex) {
|
||||
assertEquals(HttpStatus.NOT_ACCEPTABLE, ex.getStatusCode());
|
||||
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,10 +146,10 @@ public class MainControllerIntegrationTests
|
||||
throws URISyntaxException {
|
||||
ResponseEntity<?> entity = getRestTemplate().getForEntity(createUrl(context),
|
||||
ResponseEntity.class);
|
||||
assertEquals(HttpStatus.FOUND, entity.getStatusCode());
|
||||
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
|
||||
String expected = "https://repo.spring.io/release/org/springframework/boot/spring-boot-cli/1.1.4.RELEASE/spring-boot-cli-1.1.4.RELEASE-bin."
|
||||
+ extension;
|
||||
assertEquals(new URI(expected), entity.getHeaders().getLocation());
|
||||
assertThat(entity.getHeaders().getLocation()).isEqualTo(new URI(expected));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,7 +183,7 @@ public class MainControllerIntegrationTests
|
||||
"bootVersion.values[0]", "language.values[0]");
|
||||
ResponseEntity<String> response = invokeHome(null,
|
||||
"application/vnd.initializr.v2.1+json");
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
|
||||
validateContentType(response,
|
||||
AbstractInitializrIntegrationTests.CURRENT_METADATA_MEDIA_TYPE);
|
||||
validateCurrentMetadata(response.getBody());
|
||||
@@ -210,7 +202,7 @@ public class MainControllerIntegrationTests
|
||||
@Test
|
||||
public void metadataWithHalAcceptHeader() {
|
||||
ResponseEntity<String> response = invokeHome(null, "application/hal+json");
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
|
||||
validateContentType(response, MainController.HAL_JSON_CONTENT_TYPE);
|
||||
validateCurrentMetadata(response.getBody());
|
||||
}
|
||||
@@ -221,7 +213,7 @@ public class MainControllerIntegrationTests
|
||||
invokeHome(null, "application/vnd.initializr.v5.4+json");
|
||||
}
|
||||
catch (HttpClientErrorException ex) {
|
||||
assertEquals(HttpStatus.NOT_ACCEPTABLE, ex.getStatusCode());
|
||||
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -315,33 +307,30 @@ public class MainControllerIntegrationTests
|
||||
|
||||
private void validateCurlHelpContent(ResponseEntity<String> response) {
|
||||
validateContentType(response, MediaType.TEXT_PLAIN);
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getBody(), allOf(containsString("Spring Initializr"),
|
||||
containsString("Examples:"), containsString("curl")));
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
|
||||
assertThat(response.getBody()).contains("Spring Initializr", "Examples:", "curl");
|
||||
}
|
||||
|
||||
private void validateHttpIeHelpContent(ResponseEntity<String> response) {
|
||||
validateContentType(response, MediaType.TEXT_PLAIN);
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getBody(),
|
||||
allOf(containsString("Spring Initializr"), containsString("Examples:"),
|
||||
not(containsString("curl")), containsString("http")));
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
|
||||
assertThat(response.getBody()).contains("Spring Initializr", "Examples:", "http")
|
||||
.doesNotContain("curl");
|
||||
}
|
||||
|
||||
private void validateGenericHelpContent(ResponseEntity<String> response) {
|
||||
validateContentType(response, MediaType.TEXT_PLAIN);
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getBody(), allOf(containsString("Spring Initializr"),
|
||||
not(containsString("Examples:")), not(containsString("curl"))));
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
|
||||
assertThat(response.getBody()).contains("Spring Initializr")
|
||||
.doesNotContain("Examples:", "curl");
|
||||
}
|
||||
|
||||
private void validateSpringBootHelpContent(ResponseEntity<String> response) {
|
||||
validateContentType(response, MediaType.TEXT_PLAIN);
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG), not(nullValue()));
|
||||
assertThat(response.getBody(),
|
||||
allOf(containsString("Service capabilities"),
|
||||
containsString("Supported dependencies"),
|
||||
not(containsString("Examples:")), not(containsString("curl"))));
|
||||
assertThat(response.getHeaders().getFirst(HttpHeaders.ETAG)).isNotNull();
|
||||
assertThat(response.getBody())
|
||||
.contains("Service capabilities", "Supported dependencies")
|
||||
.doesNotContain("Examples:", "curl");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -351,7 +340,7 @@ public class MainControllerIntegrationTests
|
||||
fail("Should have failed");
|
||||
}
|
||||
catch (HttpClientErrorException ex) {
|
||||
assertEquals(HttpStatus.BAD_REQUEST, ex.getStatusCode());
|
||||
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
||||
assertStandardErrorBody(ex.getResponseBodyAsString(),
|
||||
"Unknown dependency 'foo:bar' check project metadata");
|
||||
}
|
||||
@@ -364,7 +353,7 @@ public class MainControllerIntegrationTests
|
||||
fail("Should have failed");
|
||||
}
|
||||
catch (HttpClientErrorException ex) {
|
||||
assertEquals(HttpStatus.BAD_REQUEST, ex.getStatusCode());
|
||||
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
||||
assertStandardErrorBody(ex.getResponseBodyAsString(),
|
||||
"Unknown dependency 'foo' check project metadata");
|
||||
}
|
||||
@@ -373,67 +362,65 @@ public class MainControllerIntegrationTests
|
||||
@Test
|
||||
public void homeIsJson() {
|
||||
String body = invokeHome(null, (String[]) null).getBody();
|
||||
assertTrue("Wrong body:\n" + body, body.contains("\"dependencies\""));
|
||||
assertThat(body).contains("\"dependencies\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webIsAddedPom() {
|
||||
String body = getRestTemplate().getForObject(createUrl("/pom.xml?packaging=war"),
|
||||
String.class);
|
||||
assertTrue("Wrong body:\n" + body, body.contains("spring-boot-starter-web"));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("provided"));
|
||||
assertThat(body).contains("spring-boot-starter-web");
|
||||
assertThat(body).contains("provided");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void webIsAddedGradle() {
|
||||
String body = getRestTemplate()
|
||||
.getForObject(createUrl("/build.gradle?packaging=war"), String.class);
|
||||
assertTrue("Wrong body:\n" + body, body.contains("spring-boot-starter-web"));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("providedRuntime"));
|
||||
assertThat(body).contains("spring-boot-starter-web");
|
||||
assertThat(body).contains("providedRuntime");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void homeHasWebStyle() {
|
||||
String body = htmlHome();
|
||||
assertTrue("Wrong body:\n" + body, body.contains("name=\"style\" value=\"web\""));
|
||||
assertThat(body).contains("name=\"style\" value=\"web\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void homeHasBootVersion() {
|
||||
String body = htmlHome();
|
||||
assertTrue("Wrong body:\n" + body, body.contains("name=\"bootVersion\""));
|
||||
assertTrue("Wrong body:\n" + body, body.contains("1.2.0.BUILD-SNAPSHOT\""));
|
||||
assertThat(body).contains("name=\"bootVersion\"");
|
||||
assertThat(body).contains("1.2.0.BUILD-SNAPSHOT\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void homeHasOnlyProjectFormatTypes() {
|
||||
String body = htmlHome();
|
||||
assertTrue("maven project not found", body.contains("Maven Project"));
|
||||
assertFalse("maven pom type should have been filtered",
|
||||
body.contains("Maven POM"));
|
||||
assertThat(body).contains("Maven Project");
|
||||
assertThat(body).doesNotContain("Maven POM");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void downloadStarter() {
|
||||
byte[] body = getRestTemplate().getForObject(createUrl("starter.zip"),
|
||||
byte[].class);
|
||||
assertNotNull(body);
|
||||
assertTrue(body.length > 100);
|
||||
assertThat(body).isNotNull();
|
||||
assertThat(body.length > 100).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void installer() {
|
||||
ResponseEntity<String> response = getRestTemplate()
|
||||
.getForEntity(createUrl("install.sh"), String.class);
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertNotNull(response.getBody());
|
||||
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
assertThat(response.getBody()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void googleAnalyticsDisabledByDefault() {
|
||||
String body = htmlHome();
|
||||
assertFalse("google analytics should be disabled",
|
||||
body.contains("GoogleAnalyticsObject"));
|
||||
assertThat(body).doesNotContain("GoogleAnalyticsObject");
|
||||
}
|
||||
|
||||
private String getMetadataJson() {
|
||||
@@ -445,10 +432,10 @@ public class MainControllerIntegrationTests
|
||||
}
|
||||
|
||||
private static void assertStandardErrorBody(String body, String message) {
|
||||
assertNotNull("error body must be available", body);
|
||||
assertThat(body).as("error body must be available").isNotNull();
|
||||
try {
|
||||
JSONObject model = new JSONObject(body);
|
||||
assertEquals(message, model.get("message"));
|
||||
assertThat(model.get("message")).isEqualTo(message);
|
||||
}
|
||||
catch (JSONException ex) {
|
||||
throw new IllegalArgumentException(ex);
|
||||
|
28
initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerServiceMetadataIntegrationTests.java
Normal file → Executable file
28
initializr-web/src/test/java/io/spring/initializr/web/project/MainControllerServiceMetadataIntegrationTests.java
Normal file → Executable file
@@ -34,7 +34,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -53,18 +53,18 @@ public class MainControllerServiceMetadataIntegrationTests
|
||||
.withInitializrMetadata(new UrlResource(createUrl("/metadata/config")))
|
||||
.build();
|
||||
// Basic assertions
|
||||
assertEquals(localMetadata.getDependencies().getContent().size(),
|
||||
metadata.getDependencies().getContent().size());
|
||||
assertEquals(localMetadata.getTypes().getContent().size(),
|
||||
metadata.getTypes().getContent().size());
|
||||
assertEquals(localMetadata.getBootVersions().getContent().size(),
|
||||
metadata.getBootVersions().getContent().size());
|
||||
assertEquals(localMetadata.getPackagings().getContent().size(),
|
||||
metadata.getPackagings().getContent().size());
|
||||
assertEquals(localMetadata.getJavaVersions().getContent().size(),
|
||||
metadata.getJavaVersions().getContent().size());
|
||||
assertEquals(localMetadata.getLanguages().getContent().size(),
|
||||
metadata.getLanguages().getContent().size());
|
||||
assertThat(metadata.getDependencies().getContent())
|
||||
.hasSameSizeAs(localMetadata.getDependencies().getContent());
|
||||
assertThat(metadata.getTypes().getContent())
|
||||
.hasSameSizeAs(localMetadata.getTypes().getContent());
|
||||
assertThat(metadata.getBootVersions().getContent())
|
||||
.hasSameSizeAs(localMetadata.getBootVersions().getContent());
|
||||
assertThat(metadata.getPackagings().getContent())
|
||||
.hasSameSizeAs(localMetadata.getPackagings().getContent());
|
||||
assertThat(metadata.getJavaVersions().getContent())
|
||||
.hasSameSizeAs(localMetadata.getJavaVersions().getContent());
|
||||
assertThat(metadata.getLanguages().getContent())
|
||||
.hasSameSizeAs(localMetadata.getLanguages().getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +73,7 @@ public class MainControllerServiceMetadataIntegrationTests
|
||||
execute("/metadata/config", String.class, null, "text/plain");
|
||||
}
|
||||
catch (HttpClientErrorException ex) {
|
||||
assertEquals(HttpStatus.NOT_ACCEPTABLE, ex.getStatusCode());
|
||||
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
0
initializr-web/src/test/java/io/spring/initializr/web/project/ProjectGenerationPostProcessorTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/project/ProjectGenerationPostProcessorTests.java
Normal file → Executable file
20
initializr-web/src/test/java/io/spring/initializr/web/project/ProjectGenerationSmokeTests.java
Normal file → Executable file
20
initializr-web/src/test/java/io/spring/initializr/web/project/ProjectGenerationSmokeTests.java
Normal file → Executable file
@@ -39,8 +39,6 @@ import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -313,8 +311,8 @@ public class ProjectGenerationSmokeTests
|
||||
@Test
|
||||
public void customizationShowsUpInDefaultView() throws Exception {
|
||||
HomePage page = toHome("/#!language=groovy&packageName=com.example.acme");
|
||||
assertEquals("groovy", page.value("language"));
|
||||
assertEquals("com.example.acme", page.value("packageName"));
|
||||
assertThat(page.value("language")).isEqualTo("groovy");
|
||||
assertThat(page.value("packageName")).isEqualTo("com.example.acme");
|
||||
page.submit();
|
||||
ProjectAssert projectAssert = zipProjectAssert(from("demo.zip"));
|
||||
projectAssert.hasBaseDir("demo").isMavenProject()
|
||||
@@ -328,14 +326,14 @@ public class ProjectGenerationSmokeTests
|
||||
@Test
|
||||
public void customizationsShowsUpWhenViewIsSwitched() throws Exception {
|
||||
HomePage page = toHome("/#!packaging=war&javaVersion=1.7");
|
||||
assertEquals("war", page.value("packaging"));
|
||||
assertEquals("1.7", page.value("javaVersion"));
|
||||
assertThat(page.value("packaging")).isEqualTo("war");
|
||||
assertThat(page.value("javaVersion")).isEqualTo("1.7");
|
||||
page.advanced();
|
||||
assertEquals("war", page.value("packaging"));
|
||||
assertEquals("1.7", page.value("javaVersion"));
|
||||
assertThat(page.value("packaging")).isEqualTo("war");
|
||||
assertThat(page.value("javaVersion")).isEqualTo("1.7");
|
||||
page.simple();
|
||||
assertEquals("war", page.value("packaging"));
|
||||
assertEquals("1.7", page.value("javaVersion"));
|
||||
assertThat(page.value("packaging")).isEqualTo("war");
|
||||
assertThat(page.value("javaVersion")).isEqualTo("1.7");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -376,7 +374,7 @@ public class ProjectGenerationSmokeTests
|
||||
|
||||
private File getArchive(String fileName) {
|
||||
File archive = new File(this.downloadDir, fileName);
|
||||
assertTrue("Expected content with name " + fileName, archive.exists());
|
||||
assertThat(archive.exists()).isTrue();
|
||||
return archive;
|
||||
}
|
||||
|
||||
|
117
initializr-web/src/test/java/io/spring/initializr/web/support/DefaultDependencyMetadataProviderTests.java
Normal file → Executable file
117
initializr-web/src/test/java/io/spring/initializr/web/support/DefaultDependencyMetadataProviderTests.java
Normal file → Executable file
@@ -25,7 +25,7 @@ import io.spring.initializr.test.metadata.InitializrMetadataTestBuilder;
|
||||
import io.spring.initializr.util.Version;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertSame;
|
||||
|
||||
/**
|
||||
@@ -46,11 +46,11 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
.addDependencyGroup("test", first, second, third).build();
|
||||
DependencyMetadata dependencyMetadata = this.provider.get(metadata,
|
||||
Version.parse("1.1.5.RELEASE"));
|
||||
assertEquals(2, dependencyMetadata.getDependencies().size());
|
||||
assertEquals(0, dependencyMetadata.getRepositories().size());
|
||||
assertEquals(0, dependencyMetadata.getBoms().size());
|
||||
assertSame(first, dependencyMetadata.getDependencies().get("first"));
|
||||
assertSame(second, dependencyMetadata.getDependencies().get("second"));
|
||||
assertThat(dependencyMetadata.getDependencies()).hasSize(2);
|
||||
assertThat(dependencyMetadata.getRepositories()).isEmpty();
|
||||
assertThat(dependencyMetadata.getBoms()).isEmpty();
|
||||
assertThat(dependencyMetadata.getDependencies().get("first")).isSameAs(first);
|
||||
assertThat(dependencyMetadata.getDependencies().get("second")).isSameAs(second);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,23 +66,24 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
|
||||
DependencyMetadata dependencyMetadata = this.provider.get(metadata,
|
||||
Version.parse("1.0.5.RELEASE"));
|
||||
assertEquals(2, dependencyMetadata.getDependencies().size());
|
||||
assertEquals("org.bar",
|
||||
dependencyMetadata.getDependencies().get("first").getGroupId());
|
||||
assertEquals("second",
|
||||
dependencyMetadata.getDependencies().get("first").getArtifactId());
|
||||
assertEquals("0.1.0.RELEASE",
|
||||
dependencyMetadata.getDependencies().get("first").getVersion());
|
||||
assertThat(dependencyMetadata.getDependencies()).hasSize(2);
|
||||
assertThat(dependencyMetadata.getDependencies().get("first").getGroupId())
|
||||
.isEqualTo("org.bar");
|
||||
assertThat(dependencyMetadata.getDependencies().get("first").getArtifactId())
|
||||
.isEqualTo("second");
|
||||
assertThat(dependencyMetadata.getDependencies().get("first").getVersion())
|
||||
.isEqualTo("0.1.0.RELEASE");
|
||||
|
||||
DependencyMetadata anotherDependencyMetadata = this.provider.get(metadata,
|
||||
Version.parse("1.1.0.RELEASE"));
|
||||
assertEquals(2, anotherDependencyMetadata.getDependencies().size());
|
||||
assertEquals("org.biz",
|
||||
anotherDependencyMetadata.getDependencies().get("first").getGroupId());
|
||||
assertEquals("third",
|
||||
anotherDependencyMetadata.getDependencies().get("first").getArtifactId());
|
||||
assertEquals("0.2.0.RELEASE",
|
||||
anotherDependencyMetadata.getDependencies().get("first").getVersion());
|
||||
assertThat(anotherDependencyMetadata.getDependencies()).hasSize(2);
|
||||
assertThat(anotherDependencyMetadata.getDependencies().get("first").getGroupId())
|
||||
.isEqualTo("org.biz");
|
||||
assertThat(
|
||||
anotherDependencyMetadata.getDependencies().get("first").getArtifactId())
|
||||
.isEqualTo("third");
|
||||
assertThat(anotherDependencyMetadata.getDependencies().get("first").getVersion())
|
||||
.isEqualTo("0.2.0.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,9 +98,9 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
.addDependencyGroup("test", first, second, third).build();
|
||||
DependencyMetadata dependencyMetadata = this.provider.get(metadata,
|
||||
Version.parse("1.1.5.RELEASE"));
|
||||
assertEquals(3, dependencyMetadata.getDependencies().size());
|
||||
assertEquals(1, dependencyMetadata.getRepositories().size());
|
||||
assertEquals(0, dependencyMetadata.getBoms().size());
|
||||
assertThat(dependencyMetadata.getDependencies()).hasSize(3);
|
||||
assertThat(dependencyMetadata.getRepositories()).hasSize(1);
|
||||
assertThat(dependencyMetadata.getBoms()).isEmpty();
|
||||
assertSame(metadata.getConfiguration().getEnv().getRepositories().get("repo-foo"),
|
||||
dependencyMetadata.getRepositories().get("repo-foo"));
|
||||
}
|
||||
@@ -122,49 +123,57 @@ public class DefaultDependencyMetadataProviderTests {
|
||||
.build();
|
||||
DependencyMetadata dependencyMetadata = this.provider.get(metadata,
|
||||
Version.parse("1.1.5.RELEASE"));
|
||||
assertEquals(3, dependencyMetadata.getDependencies().size());
|
||||
assertEquals(0, dependencyMetadata.getRepositories().size());
|
||||
assertEquals(1, dependencyMetadata.getBoms().size());
|
||||
assertEquals("org.foo", dependencyMetadata.getBoms().get("bom-foo").getGroupId());
|
||||
assertEquals("bom", dependencyMetadata.getBoms().get("bom-foo").getArtifactId());
|
||||
assertEquals("1.0.0.RELEASE",
|
||||
dependencyMetadata.getBoms().get("bom-foo").getVersion());
|
||||
assertThat(dependencyMetadata.getDependencies()).hasSize(3);
|
||||
assertThat(dependencyMetadata.getRepositories()).isEmpty();
|
||||
assertThat(dependencyMetadata.getBoms()).hasSize(1);
|
||||
assertThat(dependencyMetadata.getBoms().get("bom-foo").getGroupId())
|
||||
.isEqualTo("org.foo");
|
||||
assertThat(dependencyMetadata.getBoms().get("bom-foo").getArtifactId())
|
||||
.isEqualTo("bom");
|
||||
assertThat(dependencyMetadata.getBoms().get("bom-foo").getVersion())
|
||||
.isEqualTo("1.0.0.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repoFromBomAccordingToVersion() {
|
||||
DependencyMetadata dependencyMetadata = testRepoFromBomAccordingToVersion(
|
||||
"1.0.9.RELEASE");
|
||||
assertEquals(Version.parse("1.0.9.RELEASE"), dependencyMetadata.getBootVersion());
|
||||
assertEquals(3, dependencyMetadata.getDependencies().size());
|
||||
assertEquals(2, dependencyMetadata.getRepositories().size());
|
||||
assertEquals(1, dependencyMetadata.getBoms().size());
|
||||
assertEquals("foo",
|
||||
dependencyMetadata.getRepositories().get("repo-foo").getName());
|
||||
assertEquals("bar",
|
||||
dependencyMetadata.getRepositories().get("repo-bar").getName());
|
||||
assertEquals("org.foo", dependencyMetadata.getBoms().get("bom-foo").getGroupId());
|
||||
assertEquals("bom", dependencyMetadata.getBoms().get("bom-foo").getArtifactId());
|
||||
assertEquals("2.0.0.RELEASE",
|
||||
dependencyMetadata.getBoms().get("bom-foo").getVersion());
|
||||
assertThat(dependencyMetadata.getBootVersion())
|
||||
.isEqualTo(Version.parse("1.0.9.RELEASE"));
|
||||
assertThat(dependencyMetadata.getDependencies()).hasSize(3);
|
||||
assertThat(dependencyMetadata.getRepositories()).hasSize(2);
|
||||
assertThat(dependencyMetadata.getBoms()).hasSize(1);
|
||||
assertThat(dependencyMetadata.getRepositories().get("repo-foo").getName())
|
||||
.isEqualTo("foo");
|
||||
assertThat(dependencyMetadata.getRepositories().get("repo-bar").getName())
|
||||
.isEqualTo("bar");
|
||||
assertThat(dependencyMetadata.getBoms().get("bom-foo").getGroupId())
|
||||
.isEqualTo("org.foo");
|
||||
assertThat(dependencyMetadata.getBoms().get("bom-foo").getArtifactId())
|
||||
.isEqualTo("bom");
|
||||
assertThat(dependencyMetadata.getBoms().get("bom-foo").getVersion())
|
||||
.isEqualTo("2.0.0.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void repoFromBomAccordingToAnotherVersion() {
|
||||
DependencyMetadata dependencyMetadata = testRepoFromBomAccordingToVersion(
|
||||
"1.1.5.RELEASE");
|
||||
assertEquals(Version.parse("1.1.5.RELEASE"), dependencyMetadata.getBootVersion());
|
||||
assertEquals(3, dependencyMetadata.getDependencies().size());
|
||||
assertEquals(2, dependencyMetadata.getRepositories().size());
|
||||
assertEquals(1, dependencyMetadata.getBoms().size());
|
||||
assertEquals("foo",
|
||||
dependencyMetadata.getRepositories().get("repo-foo").getName());
|
||||
assertEquals("biz",
|
||||
dependencyMetadata.getRepositories().get("repo-biz").getName());
|
||||
assertEquals("org.foo", dependencyMetadata.getBoms().get("bom-foo").getGroupId());
|
||||
assertEquals("bom", dependencyMetadata.getBoms().get("bom-foo").getArtifactId());
|
||||
assertEquals("3.0.0.RELEASE",
|
||||
dependencyMetadata.getBoms().get("bom-foo").getVersion());
|
||||
assertThat(dependencyMetadata.getBootVersion())
|
||||
.isEqualTo(Version.parse("1.1.5.RELEASE"));
|
||||
assertThat(dependencyMetadata.getDependencies()).hasSize(3);
|
||||
assertThat(dependencyMetadata.getRepositories()).hasSize(2);
|
||||
assertThat(dependencyMetadata.getBoms()).hasSize(1);
|
||||
assertThat(dependencyMetadata.getRepositories().get("repo-foo").getName())
|
||||
.isEqualTo("foo");
|
||||
assertThat(dependencyMetadata.getRepositories().get("repo-biz").getName())
|
||||
.isEqualTo("biz");
|
||||
assertThat(dependencyMetadata.getBoms().get("bom-foo").getGroupId())
|
||||
.isEqualTo("org.foo");
|
||||
assertThat(dependencyMetadata.getBoms().get("bom-foo").getArtifactId())
|
||||
.isEqualTo("bom");
|
||||
assertThat(dependencyMetadata.getBoms().get("bom-foo").getVersion())
|
||||
.isEqualTo("3.0.0.RELEASE");
|
||||
}
|
||||
|
||||
private DependencyMetadata testRepoFromBomAccordingToVersion(String bootVersion) {
|
||||
|
21
initializr-web/src/test/java/io/spring/initializr/web/support/DefaultInitializrMetadataProviderTests.java
Normal file → Executable file
21
initializr-web/src/test/java/io/spring/initializr/web/support/DefaultInitializrMetadataProviderTests.java
Normal file → Executable file
@@ -33,8 +33,7 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus;
|
||||
@@ -61,17 +60,18 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
|
||||
.addBootVersion("0.0.9.RELEASE", true)
|
||||
.addBootVersion("0.0.8.RELEASE", false).build();
|
||||
assertEquals("0.0.9.RELEASE", metadata.getBootVersions().getDefault().getId());
|
||||
assertThat(metadata.getBootVersions().getDefault().getId())
|
||||
.isEqualTo("0.0.9.RELEASE");
|
||||
DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider(
|
||||
metadata, objectMapper, this.restTemplate);
|
||||
expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(),
|
||||
"metadata/sagan/spring-boot.json");
|
||||
|
||||
InitializrMetadata updatedMetadata = provider.get();
|
||||
assertNotNull(updatedMetadata.getBootVersions());
|
||||
assertThat(updatedMetadata.getBootVersions()).isNotNull();
|
||||
List<DefaultMetadataElement> updatedBootVersions = updatedMetadata
|
||||
.getBootVersions().getContent();
|
||||
assertEquals(4, updatedBootVersions.size());
|
||||
assertThat(updatedBootVersions).hasSize(4);
|
||||
assertBootVersion(updatedBootVersions.get(0), "1.4.1 (SNAPSHOT)", false);
|
||||
assertBootVersion(updatedBootVersions.get(1), "1.4.0", true);
|
||||
assertBootVersion(updatedBootVersions.get(2), "1.3.8 (SNAPSHOT)", false);
|
||||
@@ -83,17 +83,18 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
InitializrMetadata metadata = new InitializrMetadataTestBuilder()
|
||||
.addBootVersion("0.0.9.RELEASE", true)
|
||||
.addBootVersion("0.0.8.RELEASE", false).build();
|
||||
assertEquals("0.0.9.RELEASE", metadata.getBootVersions().getDefault().getId());
|
||||
assertThat(metadata.getBootVersions().getDefault().getId())
|
||||
.isEqualTo("0.0.9.RELEASE");
|
||||
DefaultInitializrMetadataProvider provider = new DefaultInitializrMetadataProvider(
|
||||
metadata, objectMapper, this.restTemplate);
|
||||
expectJson(metadata.getConfiguration().getEnv().getSpringBootMetadataUrl(),
|
||||
"metadata/sagan/spring-boot-no-default.json");
|
||||
|
||||
InitializrMetadata updatedMetadata = provider.get();
|
||||
assertNotNull(updatedMetadata.getBootVersions());
|
||||
assertThat(updatedMetadata.getBootVersions()).isNotNull();
|
||||
List<DefaultMetadataElement> updatedBootVersions = updatedMetadata
|
||||
.getBootVersions().getContent();
|
||||
assertEquals(4, updatedBootVersions.size());
|
||||
assertThat(updatedBootVersions).hasSize(4);
|
||||
assertBootVersion(updatedBootVersions.get(0), "1.3.1 (SNAPSHOT)", true);
|
||||
assertBootVersion(updatedBootVersions.get(1), "1.3.0", false);
|
||||
assertBootVersion(updatedBootVersions.get(2), "1.2.6 (SNAPSHOT)", false);
|
||||
@@ -102,8 +103,8 @@ public class DefaultInitializrMetadataProviderTests {
|
||||
|
||||
private static void assertBootVersion(DefaultMetadataElement actual, String name,
|
||||
boolean defaultVersion) {
|
||||
assertEquals(name, actual.getName());
|
||||
assertEquals(defaultVersion, actual.isDefault());
|
||||
assertThat(actual.getName()).isEqualTo(name);
|
||||
assertThat(actual.isDefault()).isEqualTo(defaultVersion);
|
||||
}
|
||||
|
||||
private void expectJson(String url, String bodyPath) {
|
||||
|
10
initializr-web/src/test/java/io/spring/initializr/web/support/SpringBootMetadataReaderTests.java
Normal file → Executable file
10
initializr-web/src/test/java/io/spring/initializr/web/support/SpringBootMetadataReaderTests.java
Normal file → Executable file
@@ -31,8 +31,8 @@ import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
|
||||
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;
|
||||
|
||||
@@ -62,11 +62,11 @@ public class SpringBootMetadataReaderTests {
|
||||
this.objectMapper, this.restTemplate,
|
||||
this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl())
|
||||
.getBootVersions();
|
||||
assertNotNull("spring boot versions should not be null", versions);
|
||||
assertThat(versions).as("spring boot versions should not be null").isNotNull();
|
||||
AtomicBoolean defaultFound = new AtomicBoolean(false);
|
||||
versions.forEach(it -> {
|
||||
assertNotNull("Id must be set", it.getId());
|
||||
assertNotNull("Name must be set", it.getName());
|
||||
assertThat(it.getId()).as("Id must be set").isNotNull();
|
||||
assertThat(it.getName()).as("Name must be set").isNotNull();
|
||||
if (it.isDefault()) {
|
||||
if (defaultFound.get()) {
|
||||
fail("One default version was already found " + it.getId());
|
||||
|
0
initializr-web/src/test/java/io/spring/initializr/web/ui/UiControllerIntegrationTests.java
Normal file → Executable file
0
initializr-web/src/test/java/io/spring/initializr/web/ui/UiControllerIntegrationTests.java
Normal file → Executable file
Reference in New Issue
Block a user