mirror of
https://gitee.com/dcren/initializr.git
synced 2025-12-02 11:24:04 +08:00
Migrate tests to AssertJ
Refactor all existing tests to use AssertJ assertions.
This commit is contained in:
31
initializr-actuator/src/test/java/io/spring/initializr/actuate/ActuatorIntegrationTests.java
Normal file → Executable file
31
initializr-actuator/src/test/java/io/spring/initializr/actuate/ActuatorIntegrationTests.java
Normal file → Executable file
@@ -28,8 +28,6 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
|
||||
|
||||
/**
|
||||
@@ -46,9 +44,8 @@ public class ActuatorIntegrationTests
|
||||
public void infoHasExternalProperties() {
|
||||
String body = getRestTemplate().getForObject(createUrl("/actuator/info"),
|
||||
String.class);
|
||||
assertTrue("Wrong body:\n" + body, body.contains("\"spring-boot\""));
|
||||
assertTrue("Wrong body:\n" + body,
|
||||
body.contains("\"version\":\"1.1.4.RELEASE\""));
|
||||
assertThat(body).contains("\"spring-boot\"");
|
||||
assertThat(body).contains("\"version\":\"1.1.4.RELEASE\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,16 +70,20 @@ public class ActuatorIntegrationTests
|
||||
// No jpa dep this time
|
||||
downloadZip("/starter.zip?packaging=jar&javaVersion=1.8&style=web");
|
||||
|
||||
assertEquals("Number of request should have increased", requests + 1,
|
||||
metricValue("initializr.requests"));
|
||||
assertEquals("jar packaging metric should have increased", packaging + 1,
|
||||
metricValue("initializr.packaging.jar"));
|
||||
assertEquals("java version metric should have increased", javaVersion + 1,
|
||||
metricValue("initializr.java_version.1_8"));
|
||||
assertEquals("web dependency metric should have increased", webDependency + 1,
|
||||
metricValue("initializr.dependency.web"));
|
||||
assertEquals("jpa dependency metric should not have increased", jpaDependency,
|
||||
metricValue("initializr.dependency.data-jpa"));
|
||||
assertThat(metricValue("initializr.requests"))
|
||||
.as("Number of request should have increased").isEqualTo(requests + 1);
|
||||
assertThat(metricValue("initializr.packaging.jar"))
|
||||
.as("jar packaging metric should have increased")
|
||||
.isEqualTo(packaging + 1);
|
||||
assertThat(metricValue("initializr.java_version.1_8"))
|
||||
.as("java version metric should have increased")
|
||||
.isEqualTo(javaVersion + 1);
|
||||
assertThat(metricValue("initializr.dependency.web"))
|
||||
.as("web dependency metric should have increased")
|
||||
.isEqualTo(webDependency + 1);
|
||||
assertThat(metricValue("initializr.dependency.data-jpa"))
|
||||
.as("jpa dependency metric should not have increased")
|
||||
.isEqualTo(jpaDependency);
|
||||
}
|
||||
|
||||
private JsonNode metricsEndpoint() {
|
||||
|
||||
2
initializr-actuator/src/test/java/io/spring/initializr/actuate/autoconfigure/InitializrStatsAutoConfigurationTests.java
Normal file → Executable file
2
initializr-actuator/src/test/java/io/spring/initializr/actuate/autoconfigure/InitializrStatsAutoConfigurationTests.java
Normal file → Executable file
@@ -84,4 +84,4 @@ public class InitializrStatsAutoConfigurationTests {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
0
initializr-actuator/src/test/java/io/spring/initializr/actuate/info/BomRangesInfoContributorTests.java
Normal file → Executable file
0
initializr-actuator/src/test/java/io/spring/initializr/actuate/info/BomRangesInfoContributorTests.java
Normal file → Executable file
0
initializr-actuator/src/test/java/io/spring/initializr/actuate/info/DependencyRangesInfoContributorTests.java
Normal file → Executable file
0
initializr-actuator/src/test/java/io/spring/initializr/actuate/info/DependencyRangesInfoContributorTests.java
Normal file → Executable file
0
initializr-actuator/src/test/java/io/spring/initializr/actuate/metric/ProjectGenerationMetricsListenerTests.java
Normal file → Executable file
0
initializr-actuator/src/test/java/io/spring/initializr/actuate/metric/ProjectGenerationMetricsListenerTests.java
Normal file → Executable file
0
initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/AbstractInitializrStatTests.java
Normal file → Executable file
0
initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/AbstractInitializrStatTests.java
Normal file → Executable file
58
initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/MainControllerStatsIntegrationTests.java
Normal file → Executable file
58
initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/MainControllerStatsIntegrationTests.java
Normal file → Executable file
@@ -37,11 +37,10 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* Integration tests for stats processing.
|
||||
@@ -70,41 +69,42 @@ public class MainControllerStatsIntegrationTests
|
||||
@Test
|
||||
public void simpleProject() {
|
||||
downloadArchive("/starter.zip?groupId=com.foo&artifactId=bar&dependencies=web");
|
||||
assertEquals("No stat got generated", 1, this.statsMockController.stats.size());
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
|
||||
JsonNode json = parseJson(content.json);
|
||||
assertEquals("com.foo", json.get("groupId").textValue());
|
||||
assertEquals("bar", json.get("artifactId").textValue());
|
||||
assertThat(json.get("groupId").textValue()).isEqualTo("com.foo");
|
||||
assertThat(json.get("artifactId").textValue()).isEqualTo("bar");
|
||||
JsonNode list = json.get("dependencies");
|
||||
assertEquals(1, list.size());
|
||||
assertEquals("web", list.get(0).textValue());
|
||||
assertThat(list).hasSize(1);
|
||||
assertThat(list.get(0).textValue()).isEqualTo("web");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void authorizationHeaderIsSet() {
|
||||
downloadArchive("/starter.zip");
|
||||
assertEquals("No stat got generated", 1, this.statsMockController.stats.size());
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
|
||||
String authorization = content.authorization;
|
||||
assertNotNull("Authorization header must be set", authorization);
|
||||
assertThat(authorization).as("Authorization header must be set").isNotNull();
|
||||
assertTrue("Wrong value for authorization header",
|
||||
authorization.startsWith("Basic "));
|
||||
String token = authorization.substring("Basic ".length(), authorization.length());
|
||||
String[] data = new String(Base64Utils.decodeFromString(token)).split(":");
|
||||
assertEquals("Wrong user from " + token, "test-user", data[0]);
|
||||
assertEquals("Wrong password " + token, "test-password", data[1]);
|
||||
assertThat(data[0]).as("Wrong user from " + token).isEqualTo("test-user");
|
||||
assertThat(data[1]).as("Wrong password " + token).isEqualTo("test-password");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestIpNotSetByDefault() {
|
||||
downloadArchive("/starter.zip?groupId=com.foo&artifactId=bar&dependencies=web");
|
||||
assertEquals("No stat got generated", 1, this.statsMockController.stats.size());
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
|
||||
JsonNode json = parseJson(content.json);
|
||||
assertFalse("requestIp property should not be set", json.has("requestIp"));
|
||||
assertThat(json.has("requestIp")).as("requestIp property should not be set")
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,11 +112,12 @@ public class MainControllerStatsIntegrationTests
|
||||
RequestEntity<?> request = RequestEntity.get(new URI(createUrl("/starter.zip")))
|
||||
.header("X-FORWARDED-FOR", "10.0.0.123").build();
|
||||
getRestTemplate().exchange(request, String.class);
|
||||
assertEquals("No stat got generated", 1, this.statsMockController.stats.size());
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
|
||||
JsonNode json = parseJson(content.json);
|
||||
assertEquals("Wrong requestIp", "10.0.0.123", json.get("requestIp").textValue());
|
||||
assertThat(json.get("requestIp").textValue()).as("Wrong requestIp")
|
||||
.isEqualTo("10.0.0.123");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,7 +125,7 @@ public class MainControllerStatsIntegrationTests
|
||||
RequestEntity<?> request = RequestEntity.get(new URI(createUrl("/starter.zip")))
|
||||
.header("x-forwarded-for", "foo-bar").build();
|
||||
getRestTemplate().exchange(request, String.class);
|
||||
assertEquals("No stat got generated", 1, this.statsMockController.stats.size());
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
|
||||
JsonNode json = parseJson(content.json);
|
||||
@@ -137,7 +138,7 @@ public class MainControllerStatsIntegrationTests
|
||||
RequestEntity<?> request = RequestEntity.get(new URI(createUrl("/starter.zip")))
|
||||
.header("cf-ipcountry", "XX").build();
|
||||
getRestTemplate().exchange(request, String.class);
|
||||
assertEquals("No stat got generated", 1, this.statsMockController.stats.size());
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
|
||||
JsonNode json = parseJson(content.json);
|
||||
@@ -152,18 +153,19 @@ public class MainControllerStatsIntegrationTests
|
||||
fail("Should have failed to generate project with invalid type");
|
||||
}
|
||||
catch (HttpClientErrorException ex) {
|
||||
assertEquals(HttpStatus.BAD_REQUEST, ex.getStatusCode());
|
||||
assertThat(ex.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
assertEquals("No stat got generated", 1, this.statsMockController.stats.size());
|
||||
assertThat(this.statsMockController.stats).as("No stat got generated").hasSize(1);
|
||||
StatsMockController.Content content = this.statsMockController.stats.get(0);
|
||||
|
||||
JsonNode json = parseJson(content.json);
|
||||
assertEquals("com.example", json.get("groupId").textValue());
|
||||
assertEquals("demo", json.get("artifactId").textValue());
|
||||
assertEquals(true, json.get("invalid").booleanValue());
|
||||
assertEquals(true, json.get("invalidType").booleanValue());
|
||||
assertNotNull(json.get("errorMessage"));
|
||||
assertTrue(json.get("errorMessage").textValue().contains("invalid-type"));
|
||||
assertThat(json.get("groupId").textValue()).isEqualTo("com.example");
|
||||
assertThat(json.get("artifactId").textValue()).isEqualTo("demo");
|
||||
assertThat(json.get("invalid").booleanValue()).isEqualTo(true);
|
||||
assertThat(json.get("invalidType").booleanValue()).isEqualTo(true);
|
||||
assertThat(json.get("errorMessage")).isNotNull();
|
||||
assertThat(json.get("errorMessage").textValue().contains("invalid-type"))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -171,8 +173,8 @@ public class MainControllerStatsIntegrationTests
|
||||
this.statsProperties.getElastic()
|
||||
.setUri("http://localhost:" + this.port + "/elastic-error");
|
||||
downloadArchive("/starter.zip");
|
||||
assertEquals("No stat should be available", 0,
|
||||
this.statsMockController.stats.size());
|
||||
assertThat(this.statsMockController.stats).as("No stat should be available")
|
||||
.isEmpty();
|
||||
}
|
||||
|
||||
@RestController
|
||||
|
||||
0
initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/ProjectGenerationStatPublisherTests.java
Normal file → Executable file
0
initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/ProjectGenerationStatPublisherTests.java
Normal file → Executable file
119
initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/ProjectRequestDocumentFactoryTests.java
Normal file → Executable file
119
initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/ProjectRequestDocumentFactoryTests.java
Normal file → Executable file
@@ -23,10 +23,7 @@ import io.spring.initializr.generator.ProjectGeneratedEvent;
|
||||
import io.spring.initializr.generator.ProjectRequest;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -41,17 +38,17 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
ProjectRequest request = createProjectRequest();
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals(event.getTimestamp(), document.getGenerationTimestamp());
|
||||
assertEquals(null, document.getRequestIp());
|
||||
assertEquals("com.example", document.getGroupId());
|
||||
assertEquals("demo", document.getArtifactId());
|
||||
assertEquals("com.example.demo", document.getPackageName());
|
||||
assertEquals("1.2.3.RELEASE", document.getBootVersion());
|
||||
assertEquals("1.8", document.getJavaVersion());
|
||||
assertEquals("java", document.getLanguage());
|
||||
assertEquals("jar", document.getPackaging());
|
||||
assertEquals("maven-project", document.getType());
|
||||
assertEquals(0, document.getDependencies().size());
|
||||
assertThat(document.getGenerationTimestamp()).isEqualTo(event.getTimestamp());
|
||||
assertThat(document.getRequestIp()).isEqualTo(null);
|
||||
assertThat(document.getGroupId()).isEqualTo("com.example");
|
||||
assertThat(document.getArtifactId()).isEqualTo("demo");
|
||||
assertThat(document.getPackageName()).isEqualTo("com.example.demo");
|
||||
assertThat(document.getBootVersion()).isEqualTo("1.2.3.RELEASE");
|
||||
assertThat(document.getJavaVersion()).isEqualTo("1.8");
|
||||
assertThat(document.getLanguage()).isEqualTo("java");
|
||||
assertThat(document.getPackaging()).isEqualTo("jar");
|
||||
assertThat(document.getType()).isEqualTo("maven-project");
|
||||
assertThat(document.getDependencies()).isEmpty();
|
||||
assertValid(document);
|
||||
}
|
||||
|
||||
@@ -61,9 +58,9 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.getParameters().put("x-forwarded-for", "10.0.0.123");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("10.0.0.123", document.getRequestIp());
|
||||
assertEquals("10.0.0.123", document.getRequestIpv4());
|
||||
assertNull(document.getRequestCountry());
|
||||
assertThat(document.getRequestIp()).isEqualTo("10.0.0.123");
|
||||
assertThat(document.getRequestIpv4()).isEqualTo("10.0.0.123");
|
||||
assertThat(document.getRequestCountry()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,9 +69,9 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.getParameters().put("x-forwarded-for", "2001:db8:a0b:12f0::1");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("2001:db8:a0b:12f0::1", document.getRequestIp());
|
||||
assertNull(document.getRequestIpv4());
|
||||
assertNull(document.getRequestCountry());
|
||||
assertThat(document.getRequestIp()).isEqualTo("2001:db8:a0b:12f0::1");
|
||||
assertThat(document.getRequestIpv4()).isNull();
|
||||
assertThat(document.getRequestCountry()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,9 +81,9 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.getParameters().put("cf-ipcountry", "BE");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("10.0.0.123", document.getRequestIp());
|
||||
assertEquals("10.0.0.123", document.getRequestIpv4());
|
||||
assertEquals("BE", document.getRequestCountry());
|
||||
assertThat(document.getRequestIp()).isEqualTo("10.0.0.123");
|
||||
assertThat(document.getRequestIpv4()).isEqualTo("10.0.0.123");
|
||||
assertThat(document.getRequestCountry()).isEqualTo("BE");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,9 +92,9 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.getParameters().put("cf-connecting-ip", "2001:db8:a0b:12f0::1");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("2001:db8:a0b:12f0::1", document.getRequestIp());
|
||||
assertNull(document.getRequestIpv4());
|
||||
assertNull(document.getRequestCountry());
|
||||
assertThat(document.getRequestIp()).isEqualTo("2001:db8:a0b:12f0::1");
|
||||
assertThat(document.getRequestIpv4()).isNull();
|
||||
assertThat(document.getRequestCountry()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,9 +104,9 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.getParameters().put("x-forwarded-for", "192.168.1.101");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("10.0.0.123", document.getRequestIp());
|
||||
assertEquals("10.0.0.123", document.getRequestIpv4());
|
||||
assertNull(document.getRequestCountry());
|
||||
assertThat(document.getRequestIp()).isEqualTo("10.0.0.123");
|
||||
assertThat(document.getRequestIpv4()).isEqualTo("10.0.0.123");
|
||||
assertThat(document.getRequestCountry()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +115,7 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.getParameters().put("cf-connecting-ip", "Xx"); // case insensitive
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertNull(document.getRequestCountry());
|
||||
assertThat(document.getRequestCountry()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -127,8 +124,8 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.getParameters().put("user-agent", "HTTPie/0.8.0");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("httpie", document.getClientId());
|
||||
assertEquals("0.8.0", document.getClientVersion());
|
||||
assertThat(document.getClientId()).isEqualTo("httpie");
|
||||
assertThat(document.getClientVersion()).isEqualTo("0.8.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,8 +134,8 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.getParameters().put("user-agent", "IntelliJ IDEA");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("intellijidea", document.getClientId());
|
||||
assertEquals(null, document.getClientVersion());
|
||||
assertThat(document.getClientId()).isEqualTo("intellijidea");
|
||||
assertThat(document.getClientVersion()).isEqualTo(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,9 +144,9 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.setJavaVersion("1.2");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("1.2", document.getJavaVersion());
|
||||
assertTrue(document.isInvalid());
|
||||
assertTrue(document.isInvalidJavaVersion());
|
||||
assertThat(document.getJavaVersion()).isEqualTo("1.2");
|
||||
assertThat(document.isInvalid()).isTrue();
|
||||
assertThat(document.isInvalidJavaVersion()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,9 +155,9 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.setLanguage("c++");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("c++", document.getLanguage());
|
||||
assertTrue(document.isInvalid());
|
||||
assertTrue(document.isInvalidLanguage());
|
||||
assertThat(document.getLanguage()).isEqualTo("c++");
|
||||
assertThat(document.isInvalid()).isTrue();
|
||||
assertThat(document.isInvalidLanguage()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,9 +166,9 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.setPackaging("ear");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("ear", document.getPackaging());
|
||||
assertTrue(document.isInvalid());
|
||||
assertTrue(document.isInvalidPackaging());
|
||||
assertThat(document.getPackaging()).isEqualTo("ear");
|
||||
assertThat(document.isInvalid()).isTrue();
|
||||
assertThat(document.isInvalidPackaging()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,9 +177,9 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.setType("ant-project");
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("ant-project", document.getType());
|
||||
assertTrue(document.isInvalid());
|
||||
assertTrue(document.isInvalidType());
|
||||
assertThat(document.getType()).isEqualTo("ant-project");
|
||||
assertThat(document.isInvalid()).isTrue();
|
||||
assertThat(document.isInvalidType()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,13 +188,13 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
request.setDependencies(Arrays.asList("web", "invalid", "data-jpa", "invalid-2"));
|
||||
ProjectGeneratedEvent event = new ProjectGeneratedEvent(request);
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertEquals("web", document.getDependencies().get(0));
|
||||
assertEquals("data-jpa", document.getDependencies().get(1));
|
||||
assertEquals(2, document.getDependencies().size());
|
||||
assertTrue(document.isInvalid());
|
||||
assertEquals("invalid", document.getInvalidDependencies().get(0));
|
||||
assertEquals("invalid-2", document.getInvalidDependencies().get(1));
|
||||
assertEquals(2, document.getInvalidDependencies().size());
|
||||
assertThat(document.getDependencies().get(0)).isEqualTo("web");
|
||||
assertThat(document.getDependencies().get(1)).isEqualTo("data-jpa");
|
||||
assertThat(document.getDependencies()).hasSize(2);
|
||||
assertThat(document.isInvalid()).isTrue();
|
||||
assertThat(document.getInvalidDependencies().get(0)).isEqualTo("invalid");
|
||||
assertThat(document.getInvalidDependencies().get(1)).isEqualTo("invalid-2");
|
||||
assertThat(document.getInvalidDependencies()).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -206,16 +203,16 @@ public class ProjectRequestDocumentFactoryTests extends AbstractInitializrStatTe
|
||||
ProjectFailedEvent event = new ProjectFailedEvent(request,
|
||||
new IllegalStateException("my test message"));
|
||||
ProjectRequestDocument document = this.factory.createDocument(event);
|
||||
assertTrue(document.isInvalid());
|
||||
assertEquals("my test message", document.getErrorMessage());
|
||||
assertThat(document.isInvalid()).isTrue();
|
||||
assertThat(document.getErrorMessage()).isEqualTo("my test message");
|
||||
}
|
||||
|
||||
private static void assertValid(ProjectRequestDocument document) {
|
||||
assertFalse(document.isInvalid());
|
||||
assertFalse(document.isInvalidJavaVersion());
|
||||
assertFalse(document.isInvalidLanguage());
|
||||
assertFalse(document.isInvalidPackaging());
|
||||
assertEquals(0, document.getInvalidDependencies().size());
|
||||
assertThat(document.isInvalid()).isFalse();
|
||||
assertThat(document.isInvalidJavaVersion()).isFalse();
|
||||
assertThat(document.isInvalidLanguage()).isFalse();
|
||||
assertThat(document.isInvalidPackaging()).isFalse();
|
||||
assertThat(document.getInvalidDependencies()).isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
9
initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/StatsPropertiesTests.java
Normal file → Executable file
9
initializr-actuator/src/test/java/io/spring/initializr/actuate/stat/StatsPropertiesTests.java
Normal file → Executable file
@@ -18,8 +18,7 @@ package io.spring.initializr.actuate.stat;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -31,7 +30,7 @@ public class StatsPropertiesTests {
|
||||
@Test
|
||||
public void cleanTrailingSlash() {
|
||||
this.properties.getElastic().setUri("http://example.com/");
|
||||
assertThat(this.properties.getElastic().getUri(), is("http://example.com"));
|
||||
assertThat(this.properties.getElastic().getUri()).isEqualTo("http://example.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -39,8 +38,8 @@ public class StatsPropertiesTests {
|
||||
this.properties.getElastic().setUri("http://example.com/");
|
||||
this.properties.getElastic().setIndexName("my-index");
|
||||
this.properties.getElastic().setEntityName("foo");
|
||||
assertThat(this.properties.getElastic().getEntityUrl().toString(),
|
||||
is("http://example.com/my-index/foo"));
|
||||
assertThat(this.properties.getElastic().getEntityUrl().toString())
|
||||
.isEqualTo("http://example.com/my-index/foo");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
0
initializr-docs/src/test/java/io/spring/initializr/stub/ClientApplicationTests.java
Normal file → Executable file
0
initializr-docs/src/test/java/io/spring/initializr/stub/ClientApplicationTests.java
Normal file → Executable file
0
initializr-generator/src/test/java/io/spring/initializr/generator/AbstractProjectGeneratorTests.java
Normal file → Executable file
0
initializr-generator/src/test/java/io/spring/initializr/generator/AbstractProjectGeneratorTests.java
Normal file → Executable file
80
initializr-generator/src/test/java/io/spring/initializr/generator/CommandLineHelpGeneratorTests.java
Normal file → Executable file
80
initializr-generator/src/test/java/io/spring/initializr/generator/CommandLineHelpGeneratorTests.java
Normal file → Executable file
@@ -24,9 +24,7 @@ import io.spring.initializr.util.TemplateRenderer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -49,11 +47,11 @@ public class CommandLineHelpGeneratorTests {
|
||||
String content = this.generator.generateGenericCapabilities(metadata,
|
||||
"https://fake-service");
|
||||
assertCommandLineCapabilities(content);
|
||||
assertThat(content, containsString("id-a | and some description |"));
|
||||
assertThat(content, containsString("id-b | depB"));
|
||||
assertThat(content, containsString("https://fake-service"));
|
||||
assertThat(content, not(containsString("Examples:")));
|
||||
assertThat(content, not(containsString("curl")));
|
||||
assertThat(content).contains("id-a | and some description |");
|
||||
assertThat(content).contains("id-b | depB");
|
||||
assertThat(content).contains("https://fake-service");
|
||||
assertThat(content).doesNotContain("Examples:");
|
||||
assertThat(content).doesNotContain("curl");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,8 +65,8 @@ public class CommandLineHelpGeneratorTests {
|
||||
String content = this.generator.generateGenericCapabilities(metadata,
|
||||
"https://fake-service");
|
||||
assertCommandLineCapabilities(content);
|
||||
assertThat(content, containsString("| foo"));
|
||||
assertThat(content, containsString("| foo-desc"));
|
||||
assertThat(content).contains("| foo");
|
||||
assertThat(content).contains("| foo-desc");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,11 +78,11 @@ public class CommandLineHelpGeneratorTests {
|
||||
String content = this.generator.generateCurlCapabilities(metadata,
|
||||
"https://fake-service");
|
||||
assertCommandLineCapabilities(content);
|
||||
assertThat(content, containsString("id-a | and some description |"));
|
||||
assertThat(content, containsString("id-b | depB"));
|
||||
assertThat(content, containsString("https://fake-service"));
|
||||
assertThat(content, containsString("Examples:"));
|
||||
assertThat(content, containsString("curl https://fake-service"));
|
||||
assertThat(content).contains("id-a | and some description |");
|
||||
assertThat(content).contains("id-b | depB");
|
||||
assertThat(content).contains("https://fake-service");
|
||||
assertThat(content).contains("Examples:");
|
||||
assertThat(content).contains("curl https://fake-service");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,12 +94,12 @@ public class CommandLineHelpGeneratorTests {
|
||||
String content = this.generator.generateHttpieCapabilities(metadata,
|
||||
"https://fake-service");
|
||||
assertCommandLineCapabilities(content);
|
||||
assertThat(content, containsString("id-a | and some description |"));
|
||||
assertThat(content, containsString("id-b | depB"));
|
||||
assertThat(content, containsString("https://fake-service"));
|
||||
assertThat(content, containsString("Examples:"));
|
||||
assertThat(content, not(containsString("curl")));
|
||||
assertThat(content, containsString("http https://fake-service"));
|
||||
assertThat(content).contains("id-a | and some description |");
|
||||
assertThat(content).contains("id-b | depB");
|
||||
assertThat(content).contains("https://fake-service");
|
||||
assertThat(content).contains("Examples:");
|
||||
assertThat(content).doesNotContain("curl");
|
||||
assertThat(content).contains("http https://fake-service");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,17 +110,17 @@ public class CommandLineHelpGeneratorTests {
|
||||
.build();
|
||||
String content = this.generator.generateSpringBootCliCapabilities(metadata,
|
||||
"https://fake-service");
|
||||
assertThat(content, containsString("| Id"));
|
||||
assertThat(content, containsString("| Tags"));
|
||||
assertThat(content, containsString("id-a | and some description |"));
|
||||
assertThat(content, containsString("id-b | depB"));
|
||||
assertThat(content, containsString("https://fake-service"));
|
||||
assertThat(content, not(containsString("Examples:")));
|
||||
assertThat(content, not(containsString("curl")));
|
||||
assertThat(content, not(containsString("| Rel")));
|
||||
assertThat(content, not(containsString("| dependencies")));
|
||||
assertThat(content, not(containsString("| applicationName")));
|
||||
assertThat(content, not(containsString("| baseDir")));
|
||||
assertThat(content).contains("| Id");
|
||||
assertThat(content).contains("| Tags");
|
||||
assertThat(content).contains("id-a | and some description |");
|
||||
assertThat(content).contains("id-b | depB");
|
||||
assertThat(content).contains("https://fake-service");
|
||||
assertThat(content).doesNotContain("Examples:");
|
||||
assertThat(content).doesNotContain("curl");
|
||||
assertThat(content).doesNotContain("| Rel");
|
||||
assertThat(content).doesNotContain("| dependencies");
|
||||
assertThat(content).doesNotContain("| applicationName");
|
||||
assertThat(content).doesNotContain("| baseDir");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,18 +135,18 @@ public class CommandLineHelpGeneratorTests {
|
||||
.addDependencyGroup("test", first, second).build();
|
||||
String content = this.generator.generateSpringBootCliCapabilities(metadata,
|
||||
"https://fake-service");
|
||||
assertThat(content, containsString(
|
||||
"| first | first desc | >=1.2.0.RELEASE |"));
|
||||
assertThat(content, containsString(
|
||||
"| second | second desc | >=1.2.0.RELEASE and <1.3.0.M1 |"));
|
||||
assertThat(content)
|
||||
.contains("| first | first desc | >=1.2.0.RELEASE |");
|
||||
assertThat(content)
|
||||
.contains("| second | second desc | >=1.2.0.RELEASE and <1.3.0.M1 |");
|
||||
}
|
||||
|
||||
private static void assertCommandLineCapabilities(String content) {
|
||||
assertThat(content, containsString("| Rel"));
|
||||
assertThat(content, containsString("| dependencies"));
|
||||
assertThat(content, containsString("| applicationName"));
|
||||
assertThat(content, containsString("| baseDir"));
|
||||
assertThat(content, not(containsString("| Tags")));
|
||||
assertThat(content).contains("| Rel");
|
||||
assertThat(content).contains("| dependencies");
|
||||
assertThat(content).contains("| applicationName");
|
||||
assertThat(content).contains("| baseDir");
|
||||
assertThat(content).doesNotContain("| Tags");
|
||||
}
|
||||
|
||||
private static Dependency createDependency(String id, String name) {
|
||||
|
||||
0
initializr-generator/src/test/java/io/spring/initializr/generator/CustomProjectGeneratorTests.java
Normal file → Executable file
0
initializr-generator/src/test/java/io/spring/initializr/generator/CustomProjectGeneratorTests.java
Normal file → Executable file
0
initializr-generator/src/test/java/io/spring/initializr/generator/ProjectGeneratorBuildTests.java
Normal file → Executable file
0
initializr-generator/src/test/java/io/spring/initializr/generator/ProjectGeneratorBuildTests.java
Normal file → Executable file
0
initializr-generator/src/test/java/io/spring/initializr/generator/ProjectGeneratorLanguageTests.java
Normal file → Executable file
0
initializr-generator/src/test/java/io/spring/initializr/generator/ProjectGeneratorLanguageTests.java
Normal file → Executable file
2
initializr-generator/src/test/java/io/spring/initializr/generator/ProjectGeneratorTests.java
Normal file → Executable file
2
initializr-generator/src/test/java/io/spring/initializr/generator/ProjectGeneratorTests.java
Normal file → Executable file
@@ -35,7 +35,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link ProjectGenerator}
|
||||
|
||||
16
initializr-generator/src/test/java/io/spring/initializr/generator/ProjectRequestResolverTests.java
Normal file → Executable file
16
initializr-generator/src/test/java/io/spring/initializr/generator/ProjectRequestResolverTests.java
Normal file → Executable file
@@ -30,7 +30,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.BeanWrapperImpl;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ProjectRequestResolver}.
|
||||
@@ -39,6 +39,9 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
public class ProjectRequestResolverTests {
|
||||
|
||||
private static final VersionProperty VERSION_PROPERTY = new VersionProperty(
|
||||
"java.version");
|
||||
|
||||
private InitializrMetadata metadata = InitializrMetadataTestBuilder.withDefaults()
|
||||
.addDependencyGroup("test", "web", "security", "data-jpa").build();
|
||||
|
||||
@@ -56,9 +59,9 @@ public class ProjectRequestResolverTests {
|
||||
this.processor.before.put("javaVersion", "1.2");
|
||||
ProjectRequest request = resolve(createMavenProjectRequest(),
|
||||
this.postProcessors);
|
||||
assertEquals("1.2", request.getJavaVersion());
|
||||
assertEquals("1.2", request.getBuildProperties().getVersions()
|
||||
.get(new VersionProperty("java.version")).get());
|
||||
assertThat(request.getJavaVersion()).isEqualTo("1.2");
|
||||
assertThat(request.getBuildProperties().getVersions().get(VERSION_PROPERTY).get())
|
||||
.isEqualTo("1.2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,8 +76,9 @@ public class ProjectRequestResolverTests {
|
||||
});
|
||||
ProjectRequest request = resolve(createMavenProjectRequest(),
|
||||
this.postProcessors);
|
||||
assertEquals(1, request.getBuildProperties().getMaven().size());
|
||||
assertEquals("bar", request.getBuildProperties().getMaven().get("foo").get());
|
||||
assertThat(request.getBuildProperties().getMaven()).hasSize(1);
|
||||
assertThat(request.getBuildProperties().getMaven().get("foo").get())
|
||||
.isEqualTo("bar");
|
||||
}
|
||||
|
||||
ProjectRequest resolve(ProjectRequest request,
|
||||
|
||||
111
initializr-generator/src/test/java/io/spring/initializr/generator/ProjectRequestTests.java
Normal file → Executable file
111
initializr-generator/src/test/java/io/spring/initializr/generator/ProjectRequestTests.java
Normal file → Executable file
@@ -29,8 +29,6 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -49,24 +47,28 @@ public class ProjectRequestTests {
|
||||
this.metadata.getGroupId().setContent("org.acme");
|
||||
this.metadata.getArtifactId().setContent("my-project");
|
||||
ProjectRequest request = initProjectRequest();
|
||||
assertEquals("org.acme", request.getGroupId());
|
||||
assertEquals("my-project", request.getArtifactId());
|
||||
assertThat(request.getGroupId()).isEqualTo("org.acme");
|
||||
assertThat(request.getArtifactId()).isEqualTo("my-project");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initializeSetsMetadataDefaults() {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
assertEquals(this.metadata.getName().getContent(), request.getName());
|
||||
assertEquals(this.metadata.getTypes().getDefault().getId(), request.getType());
|
||||
assertEquals(this.metadata.getDescription().getContent(),
|
||||
request.getDescription());
|
||||
assertEquals(this.metadata.getGroupId().getContent(), request.getGroupId());
|
||||
assertEquals(this.metadata.getArtifactId().getContent(), request.getArtifactId());
|
||||
assertEquals(this.metadata.getVersion().getContent(), request.getVersion());
|
||||
assertEquals(this.metadata.getBootVersions().getDefault().getId(),
|
||||
request.getBootVersion());
|
||||
assertEquals(this.metadata.getPackagings().getDefault().getId(),
|
||||
request.getPackaging());
|
||||
assertThat(request.getName()).isEqualTo(this.metadata.getName().getContent());
|
||||
assertThat(request.getType())
|
||||
.isEqualTo(this.metadata.getTypes().getDefault().getId());
|
||||
assertThat(request.getDescription())
|
||||
.isEqualTo(this.metadata.getDescription().getContent());
|
||||
assertThat(request.getGroupId())
|
||||
.isEqualTo(this.metadata.getGroupId().getContent());
|
||||
assertThat(request.getArtifactId())
|
||||
.isEqualTo(this.metadata.getArtifactId().getContent());
|
||||
assertThat(request.getVersion())
|
||||
.isEqualTo(this.metadata.getVersion().getContent());
|
||||
assertThat(request.getBootVersion())
|
||||
.isEqualTo(this.metadata.getBootVersions().getDefault().getId());
|
||||
assertThat(request.getPackaging())
|
||||
.isEqualTo(this.metadata.getPackagings().getDefault().getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +79,7 @@ public class ProjectRequestTests {
|
||||
request.setType("maven-project");
|
||||
request.getStyle().addAll(Arrays.asList("web", "spring-data"));
|
||||
request.resolve(this.metadata);
|
||||
assertEquals("Build type not detected", "maven", request.getBuild());
|
||||
assertThat(request.getBuild()).as("Build type not detected").isEqualTo("maven");
|
||||
assertBootStarter(request.getResolvedDependencies().get(0), "web");
|
||||
assertBootStarter(request.getResolvedDependencies().get(1), "spring-data");
|
||||
}
|
||||
@@ -90,7 +92,7 @@ public class ProjectRequestTests {
|
||||
request.setType("maven-project");
|
||||
request.getDependencies().addAll(Arrays.asList("web", "spring-data"));
|
||||
request.resolve(this.metadata);
|
||||
assertEquals("Build type not detected", "maven", request.getBuild());
|
||||
assertThat(request.getBuild()).as("Build type not detected").isEqualTo("maven");
|
||||
assertBootStarter(request.getResolvedDependencies().get(0), "web");
|
||||
assertBootStarter(request.getResolvedDependencies().get(1), "spring-data");
|
||||
}
|
||||
@@ -117,7 +119,7 @@ public class ProjectRequestTests {
|
||||
this.thrown.expect(InvalidProjectRequestException.class);
|
||||
this.thrown.expectMessage("foo-bar");
|
||||
request.resolve(this.metadata);
|
||||
assertEquals(1, request.getResolvedDependencies().size());
|
||||
assertThat(request.getResolvedDependencies()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,7 +132,7 @@ public class ProjectRequestTests {
|
||||
this.thrown.expect(InvalidProjectRequestException.class);
|
||||
this.thrown.expectMessage("org.foo:acme");
|
||||
request.resolve(this.metadata);
|
||||
assertEquals(1, request.getResolvedDependencies().size());
|
||||
assertThat(request.getResolvedDependencies()).hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -191,7 +193,7 @@ public class ProjectRequestTests {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.setType("gradle-project");
|
||||
request.resolve(this.metadata);
|
||||
assertEquals("gradle", request.getBuild());
|
||||
assertThat(request.getBuild()).isEqualTo("gradle");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,7 +203,7 @@ public class ProjectRequestTests {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.setType("foo");
|
||||
request.resolve(this.metadata);
|
||||
assertNull(request.getBuild());
|
||||
assertThat(request.getBuild()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -219,9 +221,8 @@ public class ProjectRequestTests {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.setName(null);
|
||||
request.resolve(this.metadata);
|
||||
assertEquals(
|
||||
this.metadata.getConfiguration().getEnv().getFallbackApplicationName(),
|
||||
request.getApplicationName());
|
||||
assertThat(request.getApplicationName()).isEqualTo(
|
||||
this.metadata.getConfiguration().getEnv().getFallbackApplicationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,7 +230,7 @@ public class ProjectRequestTests {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.setName("Foo2");
|
||||
request.resolve(this.metadata);
|
||||
assertEquals("Foo2Application", request.getApplicationName());
|
||||
assertThat(request.getApplicationName()).isEqualTo("Foo2Application");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -239,7 +240,7 @@ public class ProjectRequestTests {
|
||||
request.setApplicationName("MyApplicationName");
|
||||
|
||||
request.resolve(this.metadata);
|
||||
assertEquals("MyApplicationName", request.getApplicationName());
|
||||
assertThat(request.getApplicationName()).isEqualTo("MyApplicationName");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -293,8 +294,8 @@ public class ProjectRequestTests {
|
||||
public void cleanPackageNameWithNoName() {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.resolve(this.metadata);
|
||||
assertEquals(this.metadata.getPackageName().getContent(),
|
||||
request.getPackageName());
|
||||
assertThat(request.getPackageName())
|
||||
.isEqualTo(this.metadata.getPackageName().getContent());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -302,7 +303,7 @@ public class ProjectRequestTests {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.setPackageName("com:foo bar");
|
||||
request.resolve(this.metadata);
|
||||
assertEquals("com.foo.bar", request.getPackageName());
|
||||
assertThat(request.getPackageName()).isEqualTo("com.foo.bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -319,10 +320,10 @@ public class ProjectRequestTests {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.getStyle().add("foo");
|
||||
request.resolve(this.metadata);
|
||||
assertEquals(1, (request.getResolvedDependencies().size()));
|
||||
assertEquals(2, request.getBoms().size());
|
||||
assertEquals(bom, request.getBoms().get("foo-bom"));
|
||||
assertEquals(additionalBom, request.getBoms().get("bar-bom"));
|
||||
assertThat(request.getResolvedDependencies()).hasSize(1);
|
||||
assertThat(request.getBoms()).hasSize(2);
|
||||
assertThat(request.getBoms().get("foo-bom")).isEqualTo(bom);
|
||||
assertThat(request.getBoms().get("bar-bom")).isEqualTo(additionalBom);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -341,10 +342,10 @@ public class ProjectRequestTests {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.getStyle().addAll(Arrays.asList("foo", "bar"));
|
||||
request.resolve(this.metadata);
|
||||
assertEquals(2, request.getResolvedDependencies().size());
|
||||
assertEquals(2, request.getBoms().size());
|
||||
assertEquals(bom, request.getBoms().get("foo-bom"));
|
||||
assertEquals(additionalBom, request.getBoms().get("bar-bom"));
|
||||
assertThat(request.getResolvedDependencies()).hasSize(2);
|
||||
assertThat(request.getBoms()).hasSize(2);
|
||||
assertThat(request.getBoms().get("foo-bom")).isEqualTo(bom);
|
||||
assertThat(request.getBoms().get("bar-bom")).isEqualTo(additionalBom);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -362,13 +363,13 @@ public class ProjectRequestTests {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.getStyle().add("foo");
|
||||
request.resolve(this.metadata);
|
||||
assertEquals(1, request.getResolvedDependencies().size());
|
||||
assertEquals(1, request.getBoms().size());
|
||||
assertEquals(2, request.getRepositories().size());
|
||||
assertEquals(this.metadata.getConfiguration().getEnv().getRepositories()
|
||||
.get("foo-repo"), request.getRepositories().get("foo-repo"));
|
||||
assertEquals(this.metadata.getConfiguration().getEnv().getRepositories()
|
||||
.get("bar-repo"), request.getRepositories().get("bar-repo"));
|
||||
assertThat(request.getResolvedDependencies()).hasSize(1);
|
||||
assertThat(request.getBoms()).hasSize(1);
|
||||
assertThat(request.getRepositories()).hasSize(2);
|
||||
assertThat(request.getRepositories().get("foo-repo")).isEqualTo(this.metadata
|
||||
.getConfiguration().getEnv().getRepositories().get("foo-repo"));
|
||||
assertThat(request.getRepositories().get("bar-repo")).isEqualTo(this.metadata
|
||||
.getConfiguration().getEnv().getRepositories().get("bar-repo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -388,13 +389,13 @@ public class ProjectRequestTests {
|
||||
ProjectRequest request = initProjectRequest();
|
||||
request.getStyle().addAll(Arrays.asList("foo", "bar"));
|
||||
request.resolve(this.metadata);
|
||||
assertEquals(2, request.getResolvedDependencies().size());
|
||||
assertEquals(1, request.getBoms().size());
|
||||
assertEquals(2, request.getRepositories().size());
|
||||
assertEquals(this.metadata.getConfiguration().getEnv().getRepositories()
|
||||
.get("foo-repo"), request.getRepositories().get("foo-repo"));
|
||||
assertEquals(this.metadata.getConfiguration().getEnv().getRepositories()
|
||||
.get("bar-repo"), request.getRepositories().get("bar-repo"));
|
||||
assertThat(request.getResolvedDependencies()).hasSize(2);
|
||||
assertThat(request.getBoms()).hasSize(1);
|
||||
assertThat(request.getRepositories()).hasSize(2);
|
||||
assertThat(request.getRepositories().get("foo-repo")).isEqualTo(this.metadata
|
||||
.getConfiguration().getEnv().getRepositories().get("foo-repo"));
|
||||
assertThat(request.getRepositories().get("bar-repo")).isEqualTo(this.metadata
|
||||
.getConfiguration().getEnv().getRepositories().get("bar-repo"));
|
||||
}
|
||||
|
||||
private ProjectRequest initProjectRequest() {
|
||||
@@ -408,7 +409,7 @@ public class ProjectRequestTests {
|
||||
expected.asSpringBootStarter(name);
|
||||
assertDependency(actual, expected.getGroupId(), expected.getArtifactId(),
|
||||
expected.getVersion());
|
||||
assertEquals(name, actual.getId());
|
||||
assertThat(actual.getId()).isEqualTo(name);
|
||||
}
|
||||
|
||||
private static Dependency createDependency(String groupId, String artifactId,
|
||||
@@ -418,9 +419,9 @@ public class ProjectRequestTests {
|
||||
|
||||
private static void assertDependency(Dependency actual, String groupId,
|
||||
String artifactId, String version) {
|
||||
assertEquals(groupId, actual.getGroupId());
|
||||
assertEquals(artifactId, actual.getArtifactId());
|
||||
assertEquals(version, actual.getVersion());
|
||||
assertThat(actual.getGroupId()).isEqualTo(groupId);
|
||||
assertThat(actual.getArtifactId()).isEqualTo(artifactId);
|
||||
assertThat(actual.getVersion()).isEqualTo(version);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
85
initializr-generator/src/test/java/io/spring/initializr/metadata/BillOfMaterialsTests.java
Normal file → Executable file
85
initializr-generator/src/test/java/io/spring/initializr/metadata/BillOfMaterialsTests.java
Normal file → Executable file
@@ -25,10 +25,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.CoreMatchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -43,7 +40,7 @@ public class BillOfMaterialsTests {
|
||||
BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
|
||||
bom.validate();
|
||||
BillOfMaterials resolved = bom.resolve(Version.parse("1.2.3.RELEASE"));
|
||||
assertThat(bom, sameInstance(resolved));
|
||||
assertThat(bom).isSameAs(resolved);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,19 +49,18 @@ public class BillOfMaterialsTests {
|
||||
bom.setVersionProperty("bom.version");
|
||||
bom.getRepositories().add("repo-main");
|
||||
bom.getAdditionalBoms().add("bom-main");
|
||||
bom.getMappings()
|
||||
.add(BillOfMaterials.Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.1.0"));
|
||||
bom.getMappings().add(Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.1.0"));
|
||||
bom.validate();
|
||||
BillOfMaterials resolved = bom.resolve(Version.parse("1.2.3.RELEASE"));
|
||||
assertThat(resolved.getGroupId(), equalTo("com.example"));
|
||||
assertThat(resolved.getArtifactId(), equalTo("bom"));
|
||||
assertThat(resolved.getVersion(), equalTo("1.1.0"));
|
||||
assertThat(resolved.getVersionProperty().toStandardFormat(),
|
||||
equalTo("bom.version"));
|
||||
assertThat(resolved.getRepositories().size(), equalTo(1));
|
||||
assertThat(resolved.getRepositories().get(0), equalTo("repo-main"));
|
||||
assertThat(resolved.getAdditionalBoms().size(), equalTo(1));
|
||||
assertThat(resolved.getAdditionalBoms().get(0), equalTo("bom-main"));
|
||||
assertThat(resolved.getGroupId()).isEqualTo("com.example");
|
||||
assertThat(resolved.getArtifactId()).isEqualTo("bom");
|
||||
assertThat(resolved.getVersion()).isEqualTo("1.1.0");
|
||||
assertThat(resolved.getVersionProperty().toStandardFormat())
|
||||
.isEqualTo("bom.version");
|
||||
assertThat(resolved.getRepositories()).hasSize(1);
|
||||
assertThat(resolved.getRepositories().get(0)).isEqualTo("repo-main");
|
||||
assertThat(resolved.getAdditionalBoms()).hasSize(1);
|
||||
assertThat(resolved.getAdditionalBoms().get(0)).isEqualTo("bom-main");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,44 +68,40 @@ public class BillOfMaterialsTests {
|
||||
BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
|
||||
bom.getRepositories().add("repo-main");
|
||||
bom.getAdditionalBoms().add("bom-main");
|
||||
Mapping mapping = BillOfMaterials.Mapping.create("[1.2.0.RELEASE,1.3.0.M1)",
|
||||
"1.1.0", "repo-foo");
|
||||
Mapping mapping = Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.1.0", "repo-foo");
|
||||
mapping.getAdditionalBoms().add("bom-foo");
|
||||
bom.getMappings().add(mapping);
|
||||
bom.validate();
|
||||
BillOfMaterials resolved = bom.resolve(Version.parse("1.2.3.RELEASE"));
|
||||
assertThat(resolved.getGroupId(), equalTo("com.example"));
|
||||
assertThat(resolved.getArtifactId(), equalTo("bom"));
|
||||
assertThat(resolved.getVersion(), equalTo("1.1.0"));
|
||||
assertThat(resolved.getVersionProperty(), nullValue());
|
||||
assertThat(resolved.getRepositories().size(), equalTo(1));
|
||||
assertThat(resolved.getRepositories().get(0), equalTo("repo-foo"));
|
||||
assertThat(resolved.getAdditionalBoms().size(), equalTo(1));
|
||||
assertThat(resolved.getAdditionalBoms().get(0), equalTo("bom-foo"));
|
||||
assertThat(resolved.getGroupId()).isEqualTo("com.example");
|
||||
assertThat(resolved.getArtifactId()).isEqualTo("bom");
|
||||
assertThat(resolved.getVersion()).isEqualTo("1.1.0");
|
||||
assertThat(resolved.getVersionProperty()).isNull();
|
||||
assertThat(resolved.getRepositories()).hasSize(1);
|
||||
assertThat(resolved.getRepositories().get(0)).isEqualTo("repo-foo");
|
||||
assertThat(resolved.getAdditionalBoms()).hasSize(1);
|
||||
assertThat(resolved.getAdditionalBoms().get(0)).isEqualTo("bom-foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRangeOverrideAndMapping() {
|
||||
BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
|
||||
bom.setVersionProperty("example.version");
|
||||
bom.getMappings()
|
||||
.add(BillOfMaterials.Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.1.0"));
|
||||
bom.getMappings().add(Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.1.0"));
|
||||
bom.validate();
|
||||
BillOfMaterials resolved = bom.resolve(Version.parse("1.2.3.RELEASE"));
|
||||
assertThat(resolved.getGroupId(), equalTo("com.example"));
|
||||
assertThat(resolved.getArtifactId(), equalTo("bom"));
|
||||
assertThat(resolved.getVersion(), equalTo("1.1.0"));
|
||||
assertThat(resolved.getVersionProperty().toStandardFormat(),
|
||||
equalTo("example.version"));
|
||||
assertThat(resolved.getGroupId()).isEqualTo("com.example");
|
||||
assertThat(resolved.getArtifactId()).isEqualTo("bom");
|
||||
assertThat(resolved.getVersion()).isEqualTo("1.1.0");
|
||||
assertThat(resolved.getVersionProperty().toStandardFormat())
|
||||
.isEqualTo("example.version");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noRangeAvailable() {
|
||||
BillOfMaterials bom = BillOfMaterials.create("com.example", "bom");
|
||||
bom.getMappings()
|
||||
.add(BillOfMaterials.Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.1.0"));
|
||||
bom.getMappings()
|
||||
.add(BillOfMaterials.Mapping.create("[1.3.0.M1, 1.4.0.M1)", "1.2.0"));
|
||||
bom.getMappings().add(Mapping.create("[1.2.0.RELEASE,1.3.0.M1)", "1.1.0"));
|
||||
bom.getMappings().add(Mapping.create("[1.3.0.M1, 1.4.0.M1)", "1.2.0"));
|
||||
bom.validate();
|
||||
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
@@ -120,25 +112,24 @@ public class BillOfMaterialsTests {
|
||||
@Test
|
||||
public void resolveRangeWithVariablePatch() {
|
||||
BillOfMaterials bom = BillOfMaterials.create("com.example", "bom", "1.0.0");
|
||||
bom.getMappings().add(
|
||||
BillOfMaterials.Mapping.create("[1.3.0.RELEASE,1.3.x.RELEASE]", "1.1.0"));
|
||||
bom.getMappings().add(Mapping.create("[1.3.0.RELEASE,1.3.x.RELEASE]", "1.1.0"));
|
||||
bom.getMappings().add(BillOfMaterials.Mapping
|
||||
.create("[1.3.x.BUILD-SNAPSHOT,1.4.0.RELEASE)", "1.1.1-SNAPSHOT"));
|
||||
bom.validate();
|
||||
|
||||
bom.updateVersionRange(new VersionParser(Arrays.asList(
|
||||
Version.parse("1.3.8.RELEASE"), Version.parse("1.3.9.BUILD-SNAPSHOT"))));
|
||||
assertThat(bom.resolve(Version.parse("1.3.8.RELEASE")).getVersion(),
|
||||
equalTo("1.1.0"));
|
||||
assertThat(bom.resolve(Version.parse("1.3.9.RELEASE")).getVersion(),
|
||||
equalTo("1.1.1-SNAPSHOT"));
|
||||
assertThat(bom.resolve(Version.parse("1.3.8.RELEASE")).getVersion())
|
||||
.isEqualTo("1.1.0");
|
||||
assertThat(bom.resolve(Version.parse("1.3.9.RELEASE")).getVersion())
|
||||
.isEqualTo("1.1.1-SNAPSHOT");
|
||||
|
||||
bom.updateVersionRange(new VersionParser(Arrays.asList(
|
||||
Version.parse("1.3.9.RELEASE"), Version.parse("1.3.10.BUILD-SNAPSHOT"))));
|
||||
assertThat(bom.resolve(Version.parse("1.3.8.RELEASE")).getVersion(),
|
||||
equalTo("1.1.0"));
|
||||
assertThat(bom.resolve(Version.parse("1.3.9.RELEASE")).getVersion(),
|
||||
equalTo("1.1.0"));
|
||||
assertThat(bom.resolve(Version.parse("1.3.8.RELEASE")).getVersion())
|
||||
.isEqualTo("1.1.0");
|
||||
assertThat(bom.resolve(Version.parse("1.3.9.RELEASE")).getVersion())
|
||||
.isEqualTo("1.1.0");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
37
initializr-generator/src/test/java/io/spring/initializr/metadata/DependenciesCapabilityTests.java
Normal file → Executable file
37
initializr-generator/src/test/java/io/spring/initializr/metadata/DependenciesCapabilityTests.java
Normal file → Executable file
@@ -20,10 +20,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link DependenciesCapability}.
|
||||
@@ -43,9 +40,9 @@ public class DependenciesCapabilityTests {
|
||||
dependency, dependency2);
|
||||
capability.validate();
|
||||
|
||||
assertSame(dependency, capability.get("first"));
|
||||
assertSame(dependency2, capability.get("second"));
|
||||
assertNull(capability.get("anotherId"));
|
||||
assertThat(capability.get("first")).isSameAs(dependency);
|
||||
assertThat(capability.get("second")).isSameAs(dependency2);
|
||||
assertThat(capability.get("anotherId")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,9 +66,9 @@ public class DependenciesCapabilityTests {
|
||||
dependency);
|
||||
capability.validate();
|
||||
|
||||
assertSame(dependency, capability.get("first"));
|
||||
assertSame(dependency, capability.get("alias1"));
|
||||
assertSame(dependency, capability.get("alias2"));
|
||||
assertThat(capability.get("first")).isSameAs(dependency);
|
||||
assertThat(capability.get("alias1")).isSameAs(dependency);
|
||||
assertThat(capability.get("alias2")).isSameAs(dependency);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,10 +98,10 @@ public class DependenciesCapabilityTests {
|
||||
.add(createDependencyGroup("bar", Dependency.withId("third")));
|
||||
|
||||
capability.merge(anotherCapability);
|
||||
assertEquals(2, capability.getContent().size());
|
||||
assertNotNull(capability.get("first"));
|
||||
assertNotNull(capability.get("second"));
|
||||
assertNotNull(capability.get("third"));
|
||||
assertThat(capability.getContent()).hasSize(2);
|
||||
assertThat(capability.get("first")).isNotNull();
|
||||
assertThat(capability.get("second")).isNotNull();
|
||||
assertThat(capability.get("third")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,8 +116,8 @@ public class DependenciesCapabilityTests {
|
||||
capability.getContent().add(group);
|
||||
capability.validate();
|
||||
|
||||
assertEquals("1.2.0.RELEASE", capability.get("first").getVersionRange());
|
||||
assertEquals("1.2.3.RELEASE", capability.get("second").getVersionRange());
|
||||
assertThat(capability.get("first").getVersionRange()).isEqualTo("1.2.0.RELEASE");
|
||||
assertThat(capability.get("second").getVersionRange()).isEqualTo("1.2.3.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,8 +132,8 @@ public class DependenciesCapabilityTests {
|
||||
capability.getContent().add(group);
|
||||
capability.validate();
|
||||
|
||||
assertEquals("test-bom", capability.get("first").getBom());
|
||||
assertEquals("da-bom", capability.get("second").getBom());
|
||||
assertThat(capability.get("first").getBom()).isEqualTo("test-bom");
|
||||
assertThat(capability.get("second").getBom()).isEqualTo("da-bom");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,8 +148,8 @@ public class DependenciesCapabilityTests {
|
||||
capability.getContent().add(group);
|
||||
capability.validate();
|
||||
|
||||
assertEquals("test-repo", capability.get("first").getRepository());
|
||||
assertEquals("da-repo", capability.get("second").getRepository());
|
||||
assertThat(capability.get("first").getRepository()).isEqualTo("test-repo");
|
||||
assertThat(capability.get("second").getRepository()).isEqualTo("da-repo");
|
||||
}
|
||||
|
||||
private static DependenciesCapability createDependenciesCapability(String groupName,
|
||||
|
||||
57
initializr-generator/src/test/java/io/spring/initializr/metadata/DependencyTests.java
Normal file → Executable file
57
initializr-generator/src/test/java/io/spring/initializr/metadata/DependencyTests.java
Normal file → Executable file
@@ -24,9 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link Dependency}.
|
||||
@@ -42,28 +40,28 @@ public class DependencyTests {
|
||||
public void createRootSpringBootStarter() {
|
||||
Dependency d = new Dependency();
|
||||
d.asSpringBootStarter("");
|
||||
assertEquals("org.springframework.boot", d.getGroupId());
|
||||
assertEquals("spring-boot-starter", d.getArtifactId());
|
||||
assertThat(d.getGroupId()).isEqualTo("org.springframework.boot");
|
||||
assertThat(d.getArtifactId()).isEqualTo("spring-boot-starter");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCoordinatesFromId() {
|
||||
Dependency dependency = Dependency.withId("org.foo:bar:1.2.3");
|
||||
dependency.resolve();
|
||||
assertEquals("org.foo", dependency.getGroupId());
|
||||
assertEquals("bar", dependency.getArtifactId());
|
||||
assertEquals("1.2.3", dependency.getVersion());
|
||||
assertEquals("org.foo:bar:1.2.3", dependency.getId());
|
||||
assertThat(dependency.getGroupId()).isEqualTo("org.foo");
|
||||
assertThat(dependency.getArtifactId()).isEqualTo("bar");
|
||||
assertThat(dependency.getVersion()).isEqualTo("1.2.3");
|
||||
assertThat(dependency.getId()).isEqualTo("org.foo:bar:1.2.3");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setCoordinatesFromIdNoVersion() {
|
||||
Dependency dependency = Dependency.withId("org.foo:bar");
|
||||
dependency.resolve();
|
||||
assertEquals("org.foo", dependency.getGroupId());
|
||||
assertEquals("bar", dependency.getArtifactId());
|
||||
assertNull(dependency.getVersion());
|
||||
assertEquals("org.foo:bar", dependency.getId());
|
||||
assertThat(dependency.getGroupId()).isEqualTo("org.foo");
|
||||
assertThat(dependency.getArtifactId()).isEqualTo("bar");
|
||||
assertThat(dependency.getVersion()).isNull();
|
||||
assertThat(dependency.getId()).isEqualTo("org.foo:bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,7 +71,7 @@ public class DependencyTests {
|
||||
dependency.setArtifactId("bar");
|
||||
dependency.setVersion("1.0");
|
||||
dependency.resolve();
|
||||
assertEquals("org.foo:bar", dependency.getId());
|
||||
assertThat(dependency.getId()).isEqualTo("org.foo:bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,17 +80,17 @@ public class DependencyTests {
|
||||
dependency.setGroupId("org.foo");
|
||||
dependency.setArtifactId("bar");
|
||||
dependency.resolve();
|
||||
assertEquals("org.foo:bar", dependency.getId());
|
||||
assertThat(dependency.getId()).isEqualTo("org.foo:bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setIdFromSimpleName() {
|
||||
Dependency dependency = Dependency.withId("web");
|
||||
dependency.resolve();
|
||||
assertEquals("org.springframework.boot", dependency.getGroupId());
|
||||
assertEquals("spring-boot-starter-web", dependency.getArtifactId());
|
||||
assertNull(dependency.getVersion());
|
||||
assertEquals("web", dependency.getId());
|
||||
assertThat(dependency.getGroupId()).isEqualTo("org.springframework.boot");
|
||||
assertThat(dependency.getArtifactId()).isEqualTo("spring-boot-starter-web");
|
||||
assertThat(dependency.getVersion()).isNull();
|
||||
assertThat(dependency.getId()).isEqualTo("web");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -156,7 +154,8 @@ public class DependencyTests {
|
||||
public void resolveNoMapping() {
|
||||
Dependency dependency = Dependency.withId("web");
|
||||
dependency.resolve();
|
||||
assertSame(dependency, dependency.resolve(Version.parse("1.2.0.RELEASE")));
|
||||
assertThat(dependency.resolve(Version.parse("1.2.0.RELEASE")))
|
||||
.isSameAs(dependency);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,8 +175,8 @@ public class DependencyTests {
|
||||
.create("[1.1.0.RELEASE, 1.2.0.RELEASE)", null, null, "0.1.0.RELEASE"));
|
||||
dependency.resolve();
|
||||
Dependency resolved = dependency.resolve(Version.parse("1.1.5.RELEASE"));
|
||||
assertEquals(">=1.1.0.RELEASE and <1.2.0.RELEASE",
|
||||
resolved.getVersionRequirement());
|
||||
assertThat(resolved.getVersionRequirement())
|
||||
.isEqualTo(">=1.1.0.RELEASE and <1.2.0.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -277,17 +276,17 @@ public class DependencyTests {
|
||||
String expectedGroupId, String expectedArtifactId, String expectedVersion) {
|
||||
validateResolvedDependency(dependency, "web", expectedGroupId, expectedArtifactId,
|
||||
expectedVersion);
|
||||
assertEquals(2, dependency.getKeywords().size());
|
||||
assertEquals(1, dependency.getAliases().size());
|
||||
assertEquals(1, dependency.getFacets().size());
|
||||
assertThat(dependency.getKeywords()).hasSize(2);
|
||||
assertThat(dependency.getAliases()).hasSize(1);
|
||||
assertThat(dependency.getFacets()).hasSize(1);
|
||||
}
|
||||
|
||||
private static void validateResolvedDependency(Dependency dependency, String id,
|
||||
String expectedGroupId, String expectedArtifactId, String expectedVersion) {
|
||||
assertEquals(id, dependency.getId());
|
||||
assertEquals(expectedGroupId, dependency.getGroupId());
|
||||
assertEquals(expectedArtifactId, dependency.getArtifactId());
|
||||
assertEquals(expectedVersion, dependency.getVersion());
|
||||
assertThat(dependency.getId()).isEqualTo(id);
|
||||
assertThat(dependency.getGroupId()).isEqualTo(expectedGroupId);
|
||||
assertThat(dependency.getArtifactId()).isEqualTo(expectedArtifactId);
|
||||
assertThat(dependency.getVersion()).isEqualTo(expectedVersion);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
103
initializr-generator/src/test/java/io/spring/initializr/metadata/InitializrConfigurationTests.java
Normal file → Executable file
103
initializr-generator/src/test/java/io/spring/initializr/metadata/InitializrConfigurationTests.java
Normal file → Executable file
@@ -21,7 +21,6 @@ import io.spring.initializr.util.Version;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Tests for {@link InitializrConfiguration}.
|
||||
@@ -34,157 +33,159 @@ public class InitializrConfigurationTests {
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameSimple() {
|
||||
assertEquals("DemoApplication", this.properties.generateApplicationName("demo"));
|
||||
assertThat(this.properties.generateApplicationName("demo"))
|
||||
.isEqualTo("DemoApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameSimpleApplication() {
|
||||
assertEquals("DemoApplication",
|
||||
this.properties.generateApplicationName("demoApplication"));
|
||||
assertThat(this.properties.generateApplicationName("demoApplication"))
|
||||
.isEqualTo("DemoApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameSimpleCamelCase() {
|
||||
assertEquals("MyDemoApplication",
|
||||
this.properties.generateApplicationName("myDemo"));
|
||||
assertThat(this.properties.generateApplicationName("myDemo"))
|
||||
.isEqualTo("MyDemoApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameSimpleUnderscore() {
|
||||
assertEquals("MyDemoApplication",
|
||||
this.properties.generateApplicationName("my_demo"));
|
||||
assertThat(this.properties.generateApplicationName("my_demo"))
|
||||
.isEqualTo("MyDemoApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameSimpleColon() {
|
||||
assertEquals("MyDemoApplication",
|
||||
this.properties.generateApplicationName("my:demo"));
|
||||
assertThat(this.properties.generateApplicationName("my:demo"))
|
||||
.isEqualTo("MyDemoApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameSimpleSpace() {
|
||||
assertEquals("MyDemoApplication",
|
||||
this.properties.generateApplicationName("my demo"));
|
||||
assertThat(this.properties.generateApplicationName("my demo"))
|
||||
.isEqualTo("MyDemoApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameSimpleDash() {
|
||||
assertEquals("MyDemoApplication",
|
||||
this.properties.generateApplicationName("my-demo"));
|
||||
assertThat(this.properties.generateApplicationName("my-demo"))
|
||||
.isEqualTo("MyDemoApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameUpperCaseUnderscore() {
|
||||
assertEquals("MyDemoApplication",
|
||||
this.properties.generateApplicationName("MY_DEMO"));
|
||||
assertThat(this.properties.generateApplicationName("MY_DEMO"))
|
||||
.isEqualTo("MyDemoApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameUpperCaseDash() {
|
||||
assertEquals("MyDemoApplication",
|
||||
this.properties.generateApplicationName("MY-DEMO"));
|
||||
assertThat(this.properties.generateApplicationName("MY-DEMO"))
|
||||
.isEqualTo("MyDemoApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameMultiSpaces() {
|
||||
assertEquals("MyDemoApplication",
|
||||
this.properties.generateApplicationName(" my demo "));
|
||||
assertThat(this.properties.generateApplicationName(" my demo "))
|
||||
.isEqualTo("MyDemoApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameMultiSpacesUpperCase() {
|
||||
assertEquals("MyDemoApplication",
|
||||
this.properties.generateApplicationName(" MY DEMO "));
|
||||
assertThat("MyDemoApplication")
|
||||
.isEqualTo(this.properties.generateApplicationName(" MY DEMO "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameNull() {
|
||||
assertEquals(this.properties.getEnv().getFallbackApplicationName(),
|
||||
this.properties.generateApplicationName(null));
|
||||
assertThat(this.properties.generateApplicationName(null))
|
||||
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameInvalidStartCharacter() {
|
||||
assertEquals(this.properties.getEnv().getFallbackApplicationName(),
|
||||
this.properties.generateApplicationName("1MyDemo"));
|
||||
assertThat(this.properties.generateApplicationName("1MyDemo"))
|
||||
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameInvalidPartCharacter() {
|
||||
assertEquals(this.properties.getEnv().getFallbackApplicationName(),
|
||||
this.properties.generateApplicationName("MyDe|mo"));
|
||||
assertThat(this.properties.generateApplicationName("MyDe|mo"))
|
||||
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameInvalidApplicationName() {
|
||||
assertEquals(this.properties.getEnv().getFallbackApplicationName(),
|
||||
this.properties.generateApplicationName("SpringBoot"));
|
||||
assertThat(this.properties.generateApplicationName("SpringBoot"))
|
||||
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateApplicationNameAnotherInvalidApplicationName() {
|
||||
assertEquals(this.properties.getEnv().getFallbackApplicationName(),
|
||||
this.properties.generateApplicationName("Spring"));
|
||||
assertThat(this.properties.generateApplicationName("Spring"))
|
||||
.isEqualTo(this.properties.getEnv().getFallbackApplicationName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePackageNameSimple() {
|
||||
assertEquals("com.foo",
|
||||
this.properties.cleanPackageName("com.foo", "com.example"));
|
||||
assertThat(this.properties.cleanPackageName("com.foo", "com.example"))
|
||||
.isEqualTo("com.foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePackageNameSimpleUnderscore() {
|
||||
assertEquals("com.my_foo",
|
||||
this.properties.cleanPackageName("com.my_foo", "com.example"));
|
||||
assertThat(this.properties.cleanPackageName("com.my_foo", "com.example"))
|
||||
.isEqualTo("com.my_foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePackageNameSimpleColon() {
|
||||
assertEquals("com.foo",
|
||||
this.properties.cleanPackageName("com:foo", "com.example"));
|
||||
assertThat(this.properties.cleanPackageName("com:foo", "com.example"))
|
||||
.isEqualTo("com.foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePackageNameMultipleDashers() {
|
||||
assertEquals("com.foobar",
|
||||
this.properties.cleanPackageName("com.foo--bar", "com.example"));
|
||||
assertThat(this.properties.cleanPackageName("com.foo--bar", "com.example"))
|
||||
.isEqualTo("com.foobar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePackageNameMultipleSpaces() {
|
||||
assertEquals("com.foo",
|
||||
this.properties.cleanPackageName(" com foo ", "com.example"));
|
||||
assertThat(this.properties.cleanPackageName(" com foo ", "com.example"))
|
||||
.isEqualTo("com.foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePackageNameNull() {
|
||||
assertEquals("com.example",
|
||||
this.properties.cleanPackageName(null, "com.example"));
|
||||
assertThat(this.properties.cleanPackageName(null, "com.example"))
|
||||
.isEqualTo("com.example");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePackageNameInvalidStartCharacter() {
|
||||
assertEquals("com.foo",
|
||||
this.properties.cleanPackageName("0com.foo", "com.example"));
|
||||
assertThat(this.properties.cleanPackageName("0com.foo", "com.example"))
|
||||
.isEqualTo("com.foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePackageNameVersion() {
|
||||
assertEquals("com.foo.test145",
|
||||
this.properties.cleanPackageName("com.foo.test-1.4.5", "com.example"));
|
||||
assertThat(this.properties.cleanPackageName("com.foo.test-1.4.5", "com.example"))
|
||||
.isEqualTo("com.foo.test145");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generatePackageNameInvalidPackageName() {
|
||||
assertEquals("com.example",
|
||||
this.properties.cleanPackageName("org.springframework", "com.example"));
|
||||
assertThat(this.properties.cleanPackageName("org.springframework", "com.example"))
|
||||
.isEqualTo("com.example");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateArtifactRepository() {
|
||||
this.properties.getEnv().setArtifactRepository("http://foo/bar");
|
||||
assertEquals("http://foo/bar/", this.properties.getEnv().getArtifactRepository());
|
||||
assertThat(this.properties.getEnv().getArtifactRepository())
|
||||
.isEqualTo("http://foo/bar/");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
126
initializr-generator/src/test/java/io/spring/initializr/metadata/InitializrMetadataBuilderTests.java
Normal file → Executable file
126
initializr-generator/src/test/java/io/spring/initializr/metadata/InitializrMetadataBuilderTests.java
Normal file → Executable file
@@ -29,8 +29,7 @@ import org.springframework.boot.context.properties.source.MapConfigurationProper
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link InitializrMetadataBuilder}.
|
||||
@@ -68,12 +67,12 @@ public class InitializrMetadataBuilderTests {
|
||||
.fromInitializrProperties(config)
|
||||
.withInitializrProperties(customDefaultsConfig).build();
|
||||
assertDefaultConfig(metadata);
|
||||
assertEquals("org.foo", metadata.getGroupId().getContent());
|
||||
assertEquals("foo-bar", metadata.getArtifactId().getContent());
|
||||
assertEquals("1.2.4-SNAPSHOT", metadata.getVersion().getContent());
|
||||
assertEquals("FooBar", metadata.getName().getContent());
|
||||
assertEquals("FooBar Project", metadata.getDescription().getContent());
|
||||
assertEquals("org.foo.demo", metadata.getPackageName().getContent());
|
||||
assertThat(metadata.getGroupId().getContent()).isEqualTo("org.foo");
|
||||
assertThat(metadata.getArtifactId().getContent()).isEqualTo("foo-bar");
|
||||
assertThat(metadata.getVersion().getContent()).isEqualTo("1.2.4-SNAPSHOT");
|
||||
assertThat(metadata.getName().getContent()).isEqualTo("FooBar");
|
||||
assertThat(metadata.getDescription().getContent()).isEqualTo("FooBar Project");
|
||||
assertThat(metadata.getPackageName().getContent()).isEqualTo("org.foo.demo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,23 +81,23 @@ public class InitializrMetadataBuilderTests {
|
||||
.withInitializrMetadata(
|
||||
new ClassPathResource("metadata/config/test-min.json"))
|
||||
.build();
|
||||
assertEquals(false, metadata.getConfiguration().getEnv().isForceSsl());
|
||||
assertEquals(1, metadata.getDependencies().getContent().size());
|
||||
assertThat(metadata.getConfiguration().getEnv().isForceSsl()).isEqualTo(false);
|
||||
assertThat(metadata.getDependencies().getContent()).hasSize(1);
|
||||
Dependency dependency = metadata.getDependencies().get("test");
|
||||
assertNotNull(dependency);
|
||||
assertEquals("org.springframework.boot", dependency.getGroupId());
|
||||
assertEquals(1, metadata.getTypes().getContent().size());
|
||||
assertEquals(2, metadata.getBootVersions().getContent().size());
|
||||
assertEquals(2, metadata.getPackagings().getContent().size());
|
||||
assertEquals(1, metadata.getJavaVersions().getContent().size());
|
||||
assertEquals(3, metadata.getLanguages().getContent().size());
|
||||
assertEquals("metadata-merge", metadata.getName().getContent());
|
||||
assertEquals("Demo project for metadata merge",
|
||||
metadata.getDescription().getContent());
|
||||
assertEquals("org.acme", metadata.getGroupId().getContent());
|
||||
assertEquals("metadata", metadata.getArtifactId().getContent());
|
||||
assertEquals("1.0.0-SNAPSHOT", metadata.getVersion().getContent());
|
||||
assertEquals("org.acme.demo", metadata.getPackageName().getContent());
|
||||
assertThat(dependency).isNotNull();
|
||||
assertThat(dependency.getGroupId()).isEqualTo("org.springframework.boot");
|
||||
assertThat(metadata.getTypes().getContent()).hasSize(1);
|
||||
assertThat(metadata.getBootVersions().getContent()).hasSize(2);
|
||||
assertThat(metadata.getPackagings().getContent()).hasSize(2);
|
||||
assertThat(metadata.getJavaVersions().getContent()).hasSize(1);
|
||||
assertThat(metadata.getLanguages().getContent()).hasSize(3);
|
||||
assertThat(metadata.getName().getContent()).isEqualTo("metadata-merge");
|
||||
assertThat(metadata.getDescription().getContent())
|
||||
.isEqualTo("Demo project for metadata merge");
|
||||
assertThat(metadata.getGroupId().getContent()).isEqualTo("org.acme");
|
||||
assertThat(metadata.getArtifactId().getContent()).isEqualTo("metadata");
|
||||
assertThat(metadata.getVersion().getContent()).isEqualTo("1.0.0-SNAPSHOT");
|
||||
assertThat(metadata.getPackageName().getContent()).isEqualTo("org.acme.demo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,18 +109,18 @@ public class InitializrMetadataBuilderTests {
|
||||
|
||||
Map<String, BillOfMaterials> boms = metadata.getConfiguration().getEnv()
|
||||
.getBoms();
|
||||
assertEquals(2, boms.size());
|
||||
assertThat(boms).hasSize(2);
|
||||
BillOfMaterials myBom = boms.get("my-bom");
|
||||
assertNotNull(myBom);
|
||||
assertEquals("org.acme", myBom.getGroupId());
|
||||
assertEquals("my-bom", myBom.getArtifactId());
|
||||
assertEquals("1.2.3.RELEASE", myBom.getVersion());
|
||||
assertThat(myBom).isNotNull();
|
||||
assertThat(myBom.getGroupId()).isEqualTo("org.acme");
|
||||
assertThat(myBom.getArtifactId()).isEqualTo("my-bom");
|
||||
assertThat(myBom.getVersion()).isEqualTo("1.2.3.RELEASE");
|
||||
|
||||
BillOfMaterials anotherBom = boms.get("another-bom");
|
||||
assertNotNull(anotherBom);
|
||||
assertEquals("org.acme", anotherBom.getGroupId());
|
||||
assertEquals("another-bom", anotherBom.getArtifactId());
|
||||
assertEquals("4.5.6.RELEASE", anotherBom.getVersion());
|
||||
assertThat(anotherBom).isNotNull();
|
||||
assertThat(anotherBom.getGroupId()).isEqualTo("org.acme");
|
||||
assertThat(anotherBom.getArtifactId()).isEqualTo("another-bom");
|
||||
assertThat(anotherBom.getVersion()).isEqualTo("4.5.6.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,18 +132,18 @@ public class InitializrMetadataBuilderTests {
|
||||
|
||||
Map<String, Repository> repositories = metadata.getConfiguration().getEnv()
|
||||
.getRepositories();
|
||||
assertEquals(4, repositories.size()); // 2 standard repos
|
||||
assertThat(repositories).hasSize(4); // 2 standard repos
|
||||
Repository myRepo = repositories.get("my-repo");
|
||||
assertNotNull(myRepo);
|
||||
assertEquals("my repo", myRepo.getName());
|
||||
assertEquals(new URL("http://example.com/my"), myRepo.getUrl());
|
||||
assertEquals(true, myRepo.isSnapshotsEnabled());
|
||||
assertThat(myRepo).isNotNull();
|
||||
assertThat(myRepo.getName()).isEqualTo("my repo");
|
||||
assertThat(myRepo.getUrl()).isEqualTo(new URL("http://example.com/my"));
|
||||
assertThat(myRepo.isSnapshotsEnabled()).isEqualTo(true);
|
||||
|
||||
Repository anotherRepo = repositories.get("another-repo");
|
||||
assertNotNull(anotherRepo);
|
||||
assertEquals("another repo", anotherRepo.getName());
|
||||
assertEquals(new URL("http://example.com/another"), anotherRepo.getUrl());
|
||||
assertEquals(false, anotherRepo.isSnapshotsEnabled());
|
||||
assertThat(anotherRepo).isNotNull();
|
||||
assertThat(anotherRepo.getName()).isEqualTo("another repo");
|
||||
assertThat(anotherRepo.getUrl()).isEqualTo(new URL("http://example.com/another"));
|
||||
assertThat(anotherRepo.isSnapshotsEnabled()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,13 +157,13 @@ public class InitializrMetadataBuilderTests {
|
||||
.withInitializrProperties(customDefaultsConfig).build();
|
||||
InitializrConfiguration.Env defaultEnv = new InitializrConfiguration().getEnv();
|
||||
InitializrConfiguration.Env actualEnv = metadata.getConfiguration().getEnv();
|
||||
assertEquals(defaultEnv.getArtifactRepository(),
|
||||
actualEnv.getArtifactRepository());
|
||||
assertEquals(defaultEnv.getSpringBootMetadataUrl(),
|
||||
actualEnv.getSpringBootMetadataUrl());
|
||||
assertEquals(defaultEnv.getFallbackApplicationName(),
|
||||
actualEnv.getFallbackApplicationName());
|
||||
assertEquals(defaultEnv.isForceSsl(), actualEnv.isForceSsl());
|
||||
assertThat(actualEnv.getArtifactRepository())
|
||||
.isEqualTo(defaultEnv.getArtifactRepository());
|
||||
assertThat(actualEnv.getSpringBootMetadataUrl())
|
||||
.isEqualTo(defaultEnv.getSpringBootMetadataUrl());
|
||||
assertThat(actualEnv.getFallbackApplicationName())
|
||||
.isEqualTo(defaultEnv.getFallbackApplicationName());
|
||||
assertThat(actualEnv.isForceSsl()).isEqualTo(defaultEnv.isForceSsl());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -178,13 +177,14 @@ public class InitializrMetadataBuilderTests {
|
||||
.withInitializrProperties(customDefaultsConfig, true).build();
|
||||
InitializrConfiguration.Env defaultEnv = new InitializrConfiguration().getEnv();
|
||||
InitializrConfiguration.Env actualEnv = metadata.getConfiguration().getEnv();
|
||||
assertEquals("https://repo.spring.io/lib-release/",
|
||||
actualEnv.getArtifactRepository());
|
||||
assertEquals(defaultEnv.getSpringBootMetadataUrl(),
|
||||
actualEnv.getSpringBootMetadataUrl());
|
||||
assertEquals("FooBarApplication", actualEnv.getFallbackApplicationName());
|
||||
assertEquals(false, actualEnv.isForceSsl());
|
||||
assertEquals("1.0.0-beta-2423", actualEnv.getKotlin().getDefaultVersion());
|
||||
assertThat(actualEnv.getArtifactRepository())
|
||||
.isEqualTo("https://repo.spring.io/lib-release/");
|
||||
assertThat(actualEnv.getSpringBootMetadataUrl())
|
||||
.isEqualTo(defaultEnv.getSpringBootMetadataUrl());
|
||||
assertThat(actualEnv.getFallbackApplicationName()).isEqualTo("FooBarApplication");
|
||||
assertThat(actualEnv.isForceSsl()).isEqualTo(false);
|
||||
assertThat(actualEnv.getKotlin().getDefaultVersion())
|
||||
.isEqualTo("1.0.0-beta-2423");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -194,17 +194,15 @@ public class InitializrMetadataBuilderTests {
|
||||
group.getContent().add(dependency);
|
||||
InitializrMetadata metadata = InitializrMetadataBuilder.create()
|
||||
.withCustomizer(m -> m.getDependencies().getContent().add(group)).build();
|
||||
assertEquals(1, metadata.getDependencies().getContent().size());
|
||||
assertEquals(group, metadata.getDependencies().getContent().get(0));
|
||||
assertThat(metadata.getDependencies().getContent()).hasSize(1);
|
||||
assertThat(metadata.getDependencies().getContent().get(0)).isEqualTo(group);
|
||||
}
|
||||
|
||||
private static void assertDefaultConfig(InitializrMetadata metadata) {
|
||||
assertNotNull(metadata);
|
||||
assertEquals("Wrong number of dependencies", 9,
|
||||
metadata.getDependencies().getAll().size());
|
||||
assertEquals("Wrong number of dependency group", 2,
|
||||
metadata.getDependencies().getContent().size());
|
||||
assertEquals("Wrong number of types", 4, metadata.getTypes().getContent().size());
|
||||
assertThat(metadata).isNotNull();
|
||||
assertThat(metadata.getDependencies().getAll()).hasSize(9);
|
||||
assertThat(metadata.getDependencies().getContent()).hasSize(2);
|
||||
assertThat(metadata.getTypes().getContent()).hasSize(4);
|
||||
}
|
||||
|
||||
private static InitializrProperties load(Resource resource) {
|
||||
|
||||
0
initializr-generator/src/test/java/io/spring/initializr/metadata/InitializrMetadataTests.java
Normal file → Executable file
0
initializr-generator/src/test/java/io/spring/initializr/metadata/InitializrMetadataTests.java
Normal file → Executable file
22
initializr-generator/src/test/java/io/spring/initializr/metadata/LinkTests.java
Normal file → Executable file
22
initializr-generator/src/test/java/io/spring/initializr/metadata/LinkTests.java
Normal file → Executable file
@@ -25,9 +25,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link Link}.
|
||||
@@ -58,18 +56,18 @@ public class LinkTests {
|
||||
public void resolveLinkNoVariables() {
|
||||
Link link = Link.create("reference", "https://example.com/2");
|
||||
link.resolve();
|
||||
assertFalse(link.isTemplated());
|
||||
assertEquals(0, link.getTemplateVariables().size());
|
||||
assertThat(link.isTemplated()).isFalse();
|
||||
assertThat(link.getTemplateVariables()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveLinkWithVariables() {
|
||||
Link link = Link.create("reference", "https://example.com/{a}/2/{b}");
|
||||
link.resolve();
|
||||
assertTrue(link.isTemplated());
|
||||
assertEquals(2, link.getTemplateVariables().size());
|
||||
assertTrue(link.getTemplateVariables().contains("a"));
|
||||
assertTrue(link.getTemplateVariables().contains("b"));
|
||||
assertThat(link.isTemplated()).isTrue();
|
||||
assertThat(link.getTemplateVariables()).hasSize(2);
|
||||
assertThat(link.getTemplateVariables().contains("a")).isTrue();
|
||||
assertThat(link.getTemplateVariables().contains("b")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +77,8 @@ public class LinkTests {
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("a", "test");
|
||||
map.put("b", "another");
|
||||
assertEquals(new URI("https://example.com/test/2/another"), link.expand(map));
|
||||
assertThat(link.expand(map))
|
||||
.isEqualTo(new URI("https://example.com/test/2/another"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,7 +88,8 @@ public class LinkTests {
|
||||
Map<String, String> map = new LinkedHashMap<>();
|
||||
map.put("a", "test");
|
||||
map.put("b", "another");
|
||||
assertEquals(new URI("https://example.com/test/2/test"), link.expand(map));
|
||||
assertThat(link.expand(map))
|
||||
.isEqualTo(new URI("https://example.com/test/2/test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
15
initializr-generator/src/test/java/io/spring/initializr/metadata/SingleSelectCapabilityTests.java
Normal file → Executable file
15
initializr-generator/src/test/java/io/spring/initializr/metadata/SingleSelectCapabilityTests.java
Normal file → Executable file
@@ -18,8 +18,7 @@ package io.spring.initializr.metadata;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -29,7 +28,7 @@ public class SingleSelectCapabilityTests {
|
||||
@Test
|
||||
public void defaultEmpty() {
|
||||
SingleSelectCapability capability = new SingleSelectCapability("test");
|
||||
assertNull(capability.getDefault());
|
||||
assertThat(capability.getDefault()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -37,7 +36,7 @@ public class SingleSelectCapabilityTests {
|
||||
SingleSelectCapability capability = new SingleSelectCapability("test");
|
||||
capability.getContent().add(DefaultMetadataElement.create("foo", false));
|
||||
capability.getContent().add(DefaultMetadataElement.create("bar", false));
|
||||
assertNull(capability.getDefault());
|
||||
assertThat(capability.getDefault()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -46,7 +45,7 @@ public class SingleSelectCapabilityTests {
|
||||
capability.getContent().add(DefaultMetadataElement.create("foo", false));
|
||||
DefaultMetadataElement second = DefaultMetadataElement.create("bar", true);
|
||||
capability.getContent().add(second);
|
||||
assertEquals(second, capability.getDefault());
|
||||
assertThat(capability.getDefault()).isEqualTo(second);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,9 +59,9 @@ public class SingleSelectCapabilityTests {
|
||||
anotherCapability.getContent().add(bar);
|
||||
|
||||
capability.merge(anotherCapability);
|
||||
assertEquals(2, capability.getContent().size());
|
||||
assertEquals(foo, capability.get("foo"));
|
||||
assertEquals(bar, capability.get("bar"));
|
||||
assertThat(capability.getContent()).hasSize(2);
|
||||
assertThat(capability.get("foo")).isEqualTo(foo);
|
||||
assertThat(capability.get("bar")).isEqualTo(bar);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
24
initializr-generator/src/test/java/io/spring/initializr/metadata/TextCapabilityTests.java
Normal file → Executable file
24
initializr-generator/src/test/java/io/spring/initializr/metadata/TextCapabilityTests.java
Normal file → Executable file
@@ -18,7 +18,7 @@ package io.spring.initializr.metadata;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -32,29 +32,29 @@ public class TextCapabilityTests {
|
||||
TextCapability another = new TextCapability("foo");
|
||||
another.setContent("4567");
|
||||
capability.merge(another);
|
||||
assertEquals("foo", capability.getId());
|
||||
assertEquals(ServiceCapabilityType.TEXT, capability.getType());
|
||||
assertEquals("4567", capability.getContent());
|
||||
assertThat(capability.getId()).isEqualTo("foo");
|
||||
assertThat(capability.getType()).isEqualTo(ServiceCapabilityType.TEXT);
|
||||
assertThat(capability.getContent()).isEqualTo("4567");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeTitle() {
|
||||
TextCapability capability = new TextCapability("foo", "Foo", "my desc");
|
||||
capability.merge(new TextCapability("foo", "AnotherFoo", ""));
|
||||
assertEquals("foo", capability.getId());
|
||||
assertEquals(ServiceCapabilityType.TEXT, capability.getType());
|
||||
assertEquals("AnotherFoo", capability.getTitle());
|
||||
assertEquals("my desc", capability.getDescription());
|
||||
assertThat(capability.getId()).isEqualTo("foo");
|
||||
assertThat(capability.getType()).isEqualTo(ServiceCapabilityType.TEXT);
|
||||
assertThat(capability.getTitle()).isEqualTo("AnotherFoo");
|
||||
assertThat(capability.getDescription()).isEqualTo("my desc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeDescription() {
|
||||
TextCapability capability = new TextCapability("foo", "Foo", "my desc");
|
||||
capability.merge(new TextCapability("foo", "", "another desc"));
|
||||
assertEquals("foo", capability.getId());
|
||||
assertEquals(ServiceCapabilityType.TEXT, capability.getType());
|
||||
assertEquals("Foo", capability.getTitle());
|
||||
assertEquals("another desc", capability.getDescription());
|
||||
assertThat(capability.getId()).isEqualTo("foo");
|
||||
assertThat(capability.getType()).isEqualTo(ServiceCapabilityType.TEXT);
|
||||
assertThat(capability.getTitle()).isEqualTo("Foo");
|
||||
assertThat(capability.getDescription()).isEqualTo("another desc");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
17
initializr-generator/src/test/java/io/spring/initializr/metadata/TypeCapabilityTests.java
Normal file → Executable file
17
initializr-generator/src/test/java/io/spring/initializr/metadata/TypeCapabilityTests.java
Normal file → Executable file
@@ -18,8 +18,7 @@ package io.spring.initializr.metadata;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -29,7 +28,7 @@ public class TypeCapabilityTests {
|
||||
@Test
|
||||
public void defaultEmpty() {
|
||||
TypeCapability capability = new TypeCapability();
|
||||
assertNull(capability.getDefault());
|
||||
assertThat(capability.getDefault()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -43,7 +42,7 @@ public class TypeCapabilityTests {
|
||||
second.setDefault(false);
|
||||
capability.getContent().add(first);
|
||||
capability.getContent().add(second);
|
||||
assertNull(capability.getDefault());
|
||||
assertThat(capability.getDefault()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -57,7 +56,7 @@ public class TypeCapabilityTests {
|
||||
second.setDefault(true);
|
||||
capability.getContent().add(first);
|
||||
capability.getContent().add(second);
|
||||
assertEquals(second, capability.getDefault());
|
||||
assertThat(capability.getDefault()).isEqualTo(second);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,10 +78,10 @@ public class TypeCapabilityTests {
|
||||
anotherCapability.getContent().add(second);
|
||||
|
||||
capability.merge(anotherCapability);
|
||||
assertEquals(2, capability.getContent().size());
|
||||
assertEquals(first, capability.get("foo"));
|
||||
assertEquals(second, capability.get("bar"));
|
||||
assertEquals(second, capability.getDefault());
|
||||
assertThat(capability.getContent()).hasSize(2);
|
||||
assertThat(capability.get("foo")).isEqualTo(first);
|
||||
assertThat(capability.get("bar")).isEqualTo(second);
|
||||
assertThat(capability.getDefault()).isEqualTo(second);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
4
initializr-generator/src/test/java/io/spring/initializr/metadata/TypeTests.java
Normal file → Executable file
4
initializr-generator/src/test/java/io/spring/initializr/metadata/TypeTests.java
Normal file → Executable file
@@ -18,7 +18,7 @@ package io.spring.initializr.metadata;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -30,7 +30,7 @@ public class TypeTests {
|
||||
Type type = new Type();
|
||||
type.setId("foo");
|
||||
type.setAction("my-action.zip");
|
||||
assertEquals("/my-action.zip", type.getAction());
|
||||
assertThat(type.getAction()).isEqualTo("/my-action.zip");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
47
initializr-generator/src/test/java/io/spring/initializr/util/AgentTests.java
Normal file → Executable file
47
initializr-generator/src/test/java/io/spring/initializr/util/AgentTests.java
Normal file → Executable file
@@ -18,10 +18,7 @@ package io.spring.initializr.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link Agent}.
|
||||
@@ -33,79 +30,79 @@ public class AgentTests {
|
||||
@Test
|
||||
public void checkCurl() {
|
||||
Agent agent = Agent.fromUserAgent("curl/1.2.4");
|
||||
assertThat(agent.getId(), equalTo(Agent.AgentId.CURL));
|
||||
assertThat(agent.getVersion(), equalTo("1.2.4"));
|
||||
assertThat(agent.getId()).isEqualTo(Agent.AgentId.CURL);
|
||||
assertThat(agent.getVersion()).isEqualTo("1.2.4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkHttpie() {
|
||||
Agent agent = Agent.fromUserAgent("HTTPie/0.8.0");
|
||||
assertThat(agent.getId(), equalTo(Agent.AgentId.HTTPIE));
|
||||
assertThat(agent.getVersion(), equalTo("0.8.0"));
|
||||
assertThat(agent.getId()).isEqualTo(Agent.AgentId.HTTPIE);
|
||||
assertThat(agent.getVersion()).isEqualTo("0.8.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkJBossForge() {
|
||||
Agent agent = Agent.fromUserAgent("SpringBootForgeCli/1.0.0.Alpha4");
|
||||
assertThat(agent.getId(), equalTo(Agent.AgentId.JBOSS_FORGE));
|
||||
assertThat(agent.getVersion(), equalTo("1.0.0.Alpha4"));
|
||||
assertThat(agent.getId()).isEqualTo(Agent.AgentId.JBOSS_FORGE);
|
||||
assertThat(agent.getVersion()).isEqualTo("1.0.0.Alpha4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkSpringBootCli() {
|
||||
Agent agent = Agent.fromUserAgent("SpringBootCli/1.3.1.RELEASE");
|
||||
assertThat(agent.getId(), equalTo(Agent.AgentId.SPRING_BOOT_CLI));
|
||||
assertThat(agent.getVersion(), equalTo("1.3.1.RELEASE"));
|
||||
assertThat(agent.getId()).isEqualTo(Agent.AgentId.SPRING_BOOT_CLI);
|
||||
assertThat(agent.getVersion()).isEqualTo("1.3.1.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkSts() {
|
||||
Agent agent = Agent.fromUserAgent("STS 3.7.0.201506251244-RELEASE");
|
||||
assertThat(agent.getId(), equalTo(Agent.AgentId.STS));
|
||||
assertThat(agent.getVersion(), equalTo("3.7.0.201506251244-RELEASE"));
|
||||
assertThat(agent.getId()).isEqualTo(Agent.AgentId.STS);
|
||||
assertThat(agent.getVersion()).isEqualTo("3.7.0.201506251244-RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkIntelliJIDEA() {
|
||||
Agent agent = Agent.fromUserAgent("IntelliJ IDEA");
|
||||
assertThat(agent.getId(), equalTo(Agent.AgentId.INTELLIJ_IDEA));
|
||||
assertThat(agent.getVersion(), is(nullValue()));
|
||||
assertThat(agent.getId()).isEqualTo(Agent.AgentId.INTELLIJ_IDEA);
|
||||
assertThat(agent.getVersion()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkIntelliJIDEAWithVersion() {
|
||||
Agent agent = Agent
|
||||
.fromUserAgent("IntelliJ IDEA/144.2 (Community edition; en-us)");
|
||||
assertThat(agent.getId(), equalTo(Agent.AgentId.INTELLIJ_IDEA));
|
||||
assertThat(agent.getVersion(), is("144.2"));
|
||||
assertThat(agent.getId()).isEqualTo(Agent.AgentId.INTELLIJ_IDEA);
|
||||
assertThat(agent.getVersion()).isEqualTo("144.2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkNetBeans() {
|
||||
Agent agent = Agent.fromUserAgent("nb-springboot-plugin/0.1");
|
||||
assertThat(agent.getId(), equalTo(Agent.AgentId.NETBEANS));
|
||||
assertThat(agent.getVersion(), is("0.1"));
|
||||
assertThat(agent.getId()).isEqualTo(Agent.AgentId.NETBEANS);
|
||||
assertThat(agent.getVersion()).isEqualTo("0.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkVsCode() {
|
||||
Agent agent = Agent.fromUserAgent("vscode/0.2.0");
|
||||
assertThat(agent.getId(), equalTo(Agent.AgentId.VSCODE));
|
||||
assertThat(agent.getVersion(), is("0.2.0"));
|
||||
assertThat(agent.getId()).isEqualTo(Agent.AgentId.VSCODE);
|
||||
assertThat(agent.getVersion()).isEqualTo("0.2.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkGenericBrowser() {
|
||||
Agent agent = Agent.fromUserAgent(
|
||||
"Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5 Build/MMB29K) ");
|
||||
assertThat(agent.getId(), equalTo(Agent.AgentId.BROWSER));
|
||||
assertThat(agent.getVersion(), is(nullValue()));
|
||||
assertThat(agent.getId()).isEqualTo(Agent.AgentId.BROWSER);
|
||||
assertThat(agent.getVersion()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkRobot() {
|
||||
Agent agent = Agent.fromUserAgent("Googlebot-Mobile");
|
||||
assertThat(agent, is(nullValue()));
|
||||
assertThat(agent).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
39
initializr-generator/src/test/java/io/spring/initializr/util/VersionParserTests.java
Normal file → Executable file
39
initializr-generator/src/test/java/io/spring/initializr/util/VersionParserTests.java
Normal file → Executable file
@@ -24,10 +24,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link VersionParser}.
|
||||
@@ -44,19 +41,19 @@ public class VersionParserTests {
|
||||
@Test
|
||||
public void noQualifierString() {
|
||||
Version version = this.parser.parse("1.2.0");
|
||||
assertThat(version.toString(), equalTo("1.2.0"));
|
||||
assertThat(version.toString()).isEqualTo("1.2.0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withQualifierString() {
|
||||
Version version = this.parser.parse("1.2.0.RELEASE");
|
||||
assertThat(version.toString(), equalTo("1.2.0.RELEASE"));
|
||||
assertThat(version.toString()).isEqualTo("1.2.0.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void withQualifierAndVersionString() {
|
||||
Version version = this.parser.parse("1.2.0.RC2");
|
||||
assertThat(version.toString(), equalTo("1.2.0.RC2"));
|
||||
assertThat(version.toString()).isEqualTo("1.2.0.RC2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,13 +64,13 @@ public class VersionParserTests {
|
||||
|
||||
@Test
|
||||
public void safeParseInvalidVersion() {
|
||||
assertNull(this.parser.safeParse("foo"));
|
||||
assertThat(this.parser.safeParse("foo")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseVersionWithSpaces() {
|
||||
assertThat(this.parser.parse(" 1.2.0.RC3 "),
|
||||
lessThan(this.parser.parse("1.3.0.RELEASE")));
|
||||
assertThat(this.parser.parse(" 1.2.0.RC3 "))
|
||||
.isLessThan(this.parser.parse("1.3.0.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,8 +78,8 @@ public class VersionParserTests {
|
||||
List<Version> currentVersions = Arrays.asList(this.parser.parse("1.3.8.RELEASE"),
|
||||
this.parser.parse("1.3.9.BUILD-SNAPSHOT"));
|
||||
this.parser = new VersionParser(currentVersions);
|
||||
assertThat(this.parser.parse("1.3.x.BUILD-SNAPSHOT").toString(),
|
||||
equalTo("1.3.9.BUILD-SNAPSHOT"));
|
||||
assertThat(this.parser.parse("1.3.x.BUILD-SNAPSHOT").toString())
|
||||
.isEqualTo("1.3.9.BUILD-SNAPSHOT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,8 +87,8 @@ public class VersionParserTests {
|
||||
List<Version> currentVersions = Arrays.asList(this.parser.parse("1.3.8.RELEASE"),
|
||||
this.parser.parse("1.3.9.BUILD-SNAPSHOT"));
|
||||
this.parser = new VersionParser(currentVersions);
|
||||
assertThat(this.parser.parse("1.x.x.RELEASE").toString(),
|
||||
equalTo("1.3.8.RELEASE"));
|
||||
assertThat(this.parser.parse("1.x.x.RELEASE").toString())
|
||||
.isEqualTo("1.3.8.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -99,8 +96,8 @@ public class VersionParserTests {
|
||||
List<Version> currentVersions = Arrays.asList(this.parser.parse("1.3.8.RELEASE"),
|
||||
this.parser.parse("1.4.0.BUILD-SNAPSHOT"));
|
||||
this.parser = new VersionParser(currentVersions);
|
||||
assertThat(this.parser.parse("1.4.x").toString(),
|
||||
equalTo("1.4.0.BUILD-SNAPSHOT"));
|
||||
assertThat(this.parser.parse("1.4.x").toString())
|
||||
.isEqualTo("1.4.0.BUILD-SNAPSHOT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,8 +105,8 @@ public class VersionParserTests {
|
||||
List<Version> currentVersions = Arrays.asList(this.parser.parse("1.3.8.RELEASE"),
|
||||
this.parser.parse("1.3.9.BUILD-SNAPSHOT"));
|
||||
this.parser = new VersionParser(currentVersions);
|
||||
assertThat(this.parser.parse("1.4.x.BUILD-SNAPSHOT").toString(),
|
||||
equalTo("1.4.999.BUILD-SNAPSHOT"));
|
||||
assertThat(this.parser.parse("1.4.x.BUILD-SNAPSHOT").toString())
|
||||
.isEqualTo("1.4.999.BUILD-SNAPSHOT");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,8 +114,8 @@ public class VersionParserTests {
|
||||
List<Version> currentVersions = Arrays.asList(this.parser.parse("1.3.8.RELEASE"),
|
||||
this.parser.parse("1.3.9.BUILD-SNAPSHOT"));
|
||||
this.parser = new VersionParser(currentVersions);
|
||||
assertThat(this.parser.parse("2.x.x.RELEASE").toString(),
|
||||
equalTo("2.999.999.RELEASE"));
|
||||
assertThat(this.parser.parse("2.x.x.RELEASE").toString())
|
||||
.isEqualTo("2.999.999.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -126,7 +123,7 @@ public class VersionParserTests {
|
||||
List<Version> currentVersions = Arrays.asList(this.parser.parse("1.3.8.RELEASE"),
|
||||
this.parser.parse("1.4.0.BUILD-SNAPSHOT"));
|
||||
this.parser = new VersionParser(currentVersions);
|
||||
assertThat(this.parser.parse("1.2.x").toString(), equalTo("1.2.999"));
|
||||
assertThat(this.parser.parse("1.2.x").toString()).isEqualTo("1.2.999");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
0
initializr-generator/src/test/java/io/spring/initializr/util/VersionPropertyTests.java
Normal file → Executable file
0
initializr-generator/src/test/java/io/spring/initializr/util/VersionPropertyTests.java
Normal file → Executable file
86
initializr-generator/src/test/java/io/spring/initializr/util/VersionRangeTests.java
Normal file → Executable file
86
initializr-generator/src/test/java/io/spring/initializr/util/VersionRangeTests.java
Normal file → Executable file
@@ -19,15 +19,12 @@ package io.spring.initializr.util;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -39,127 +36,116 @@ public class VersionRangeTests {
|
||||
|
||||
@Test
|
||||
public void simpleStartingRange() {
|
||||
assertThat(new VersionRange(Version.parse("1.3.0.RELEASE")).toString(),
|
||||
equalTo(">=1.3.0.RELEASE"));
|
||||
assertThat(new VersionRange(Version.parse("1.3.0.RELEASE")).toString())
|
||||
.isEqualTo(">=1.3.0.RELEASE");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchSimpleRange() {
|
||||
assertThat("1.2.0.RC3", match("[1.2.0.RC1,1.2.0.RC5]"));
|
||||
assertThat("1.2.0.RC3").is(match("[1.2.0.RC1,1.2.0.RC5]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchSimpleRangeBefore() {
|
||||
assertThat("1.1.9.RC3", not(match("[1.2.0.RC1,1.2.0.RC5]")));
|
||||
assertThat("1.1.9.RC3").isNot(match("[1.2.0.RC1,1.2.0.RC5]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchSimpleRangeAfter() {
|
||||
assertThat("1.2.0.RC6", not(match("[1.2.0.RC1,1.2.0.RC5]")));
|
||||
assertThat("1.2.0.RC6").isNot(match("[1.2.0.RC1,1.2.0.RC5]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchInclusiveLowerRange() {
|
||||
assertThat("1.2.0.RC1", match("[1.2.0.RC1,1.2.0.RC5]"));
|
||||
assertThat("1.2.0.RC1").is(match("[1.2.0.RC1,1.2.0.RC5]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchInclusiveHigherRange() {
|
||||
assertThat("1.2.0.RC5", match("[1.2.0.RC1,1.2.0.RC5]"));
|
||||
assertThat("1.2.0.RC5").is(match("[1.2.0.RC1,1.2.0.RC5]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchExclusiveLowerRange() {
|
||||
assertThat("1.2.0.RC1", not(match("(1.2.0.RC1,1.2.0.RC5)")));
|
||||
assertThat("1.2.0.RC1").isNot(match("(1.2.0.RC1,1.2.0.RC5)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchExclusiveHigherRange() {
|
||||
assertThat("1.2.0.RC5", not(match("[1.2.0.RC1,1.2.0.RC5)")));
|
||||
assertThat("1.2.0.RC5").isNot(match("[1.2.0.RC1,1.2.0.RC5)"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchUnboundedRangeEqual() {
|
||||
assertThat("1.2.0.RELEASE", match("1.2.0.RELEASE"));
|
||||
assertThat("1.2.0.RELEASE").is(match("1.2.0.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchUnboundedRangeAfter() {
|
||||
assertThat("2.2.0.RELEASE", match("1.2.0.RELEASE"));
|
||||
assertThat("2.2.0.RELEASE").is(match("1.2.0.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchUnboundedRangeBefore() {
|
||||
assertThat("1.1.9.RELEASE", not(match("1.2.0.RELEASE")));
|
||||
assertThat("1.1.9.RELEASE").isNot(match("1.2.0.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void rangeWithSpaces() {
|
||||
assertThat("1.2.0.RC3", match("[ 1.2.0.RC1 , 1.2.0.RC5]"));
|
||||
assertThat("1.2.0.RC3").is(match("[ 1.2.0.RC1 , 1.2.0.RC5]"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchLatestVersion() {
|
||||
assertThat("1.2.8.RELEASE",
|
||||
match("[1.2.0.RELEASE,1.2.x.BUILD-SNAPSHOT]",
|
||||
new VersionParser(Collections
|
||||
.singletonList(Version.parse("1.2.9.BUILD-SNAPSHOT")))));
|
||||
assertThat("1.2.8.RELEASE").is(match("[1.2.0.RELEASE,1.2.x.BUILD-SNAPSHOT]",
|
||||
new VersionParser(Collections
|
||||
.singletonList(Version.parse("1.2.9.BUILD-SNAPSHOT")))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchOverLatestVersion() {
|
||||
assertThat("1.2.10.RELEASE",
|
||||
not(match("[1.2.0.RELEASE,1.2.x.BUILD-SNAPSHOT]",
|
||||
new VersionParser(Collections
|
||||
.singletonList(Version.parse("1.2.9.BUILD-SNAPSHOT"))))));
|
||||
assertThat("1.2.10.RELEASE").isNot(match("[1.2.0.RELEASE,1.2.x.BUILD-SNAPSHOT]",
|
||||
new VersionParser(Collections
|
||||
.singletonList(Version.parse("1.2.9.BUILD-SNAPSHOT")))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchAsOfCurrentVersion() {
|
||||
assertThat("1.3.5.RELEASE",
|
||||
match("[1.3.x.RELEASE,1.3.x.BUILD-SNAPSHOT]",
|
||||
new VersionParser(Arrays.asList(Version.parse("1.3.4.RELEASE"),
|
||||
Version.parse("1.3.6.BUILD-SNAPSHOT")))));
|
||||
assertThat("1.3.5.RELEASE").is(match("[1.3.x.RELEASE,1.3.x.BUILD-SNAPSHOT]",
|
||||
new VersionParser(Arrays.asList(Version.parse("1.3.4.RELEASE"),
|
||||
Version.parse("1.3.6.BUILD-SNAPSHOT")))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchOverAsOfCurrentVersion() {
|
||||
assertThat("1.3.5.RELEASE",
|
||||
not(match("[1.3.x.RELEASE,1.3.x.BUILD-SNAPSHOT]",
|
||||
new VersionParser(Arrays.asList(Version.parse("1.3.7.RELEASE"),
|
||||
Version.parse("1.3.6.BUILD-SNAPSHOT"))))));
|
||||
assertThat("1.3.5.RELEASE").isNot(match("[1.3.x.RELEASE,1.3.x.BUILD-SNAPSHOT]",
|
||||
new VersionParser(Arrays.asList(Version.parse("1.3.7.RELEASE"),
|
||||
Version.parse("1.3.6.BUILD-SNAPSHOT")))));
|
||||
}
|
||||
|
||||
private static VersionRangeMatcher match(String range) {
|
||||
return new VersionRangeMatcher(range, new VersionParser(Collections.emptyList()));
|
||||
private static Condition<String> match(String range) {
|
||||
return match(range, new VersionParser(Collections.emptyList()));
|
||||
}
|
||||
|
||||
private static VersionRangeMatcher match(String range, VersionParser parser) {
|
||||
return new VersionRangeMatcher(range, parser);
|
||||
private static Condition<String> match(String range, VersionParser parser) {
|
||||
return new VersionRangeCondition(range, parser);
|
||||
}
|
||||
|
||||
static class VersionRangeMatcher extends BaseMatcher<String> {
|
||||
static class VersionRangeCondition extends Condition<String> {
|
||||
|
||||
private final VersionRange range;
|
||||
|
||||
private final VersionParser parser;
|
||||
|
||||
VersionRangeMatcher(String text, VersionParser parser) {
|
||||
VersionRangeCondition(String text, VersionParser parser) {
|
||||
this.parser = parser;
|
||||
this.range = parser.parseRange(text);
|
||||
as(this.range.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Object item) {
|
||||
if (!(item instanceof String)) {
|
||||
return false;
|
||||
}
|
||||
return this.range.match(this.parser.parse((String) item));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description description) {
|
||||
description.appendText(this.range.toString());
|
||||
public boolean matches(String value) {
|
||||
return this.range.match(this.parser.parse(value));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
53
initializr-generator/src/test/java/io/spring/initializr/util/VersionTests.java
Normal file → Executable file
53
initializr-generator/src/test/java/io/spring/initializr/util/VersionTests.java
Normal file → Executable file
@@ -20,116 +20,111 @@ import java.util.Collections;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.comparesEqualTo;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class VersionTests {
|
||||
|
||||
private static final VersionParser parser = new VersionParser(
|
||||
Collections.emptyList());
|
||||
private final VersionParser parser = new VersionParser(Collections.emptyList());
|
||||
|
||||
@Test
|
||||
public void equalNoQualifier() {
|
||||
Version first = parse("1.2.0");
|
||||
Version second = parse("1.2.0");
|
||||
assertThat(first, comparesEqualTo(second));
|
||||
assertThat(first, equalTo(second));
|
||||
assertThat(first).isEqualByComparingTo(second);
|
||||
assertThat(first).isEqualTo(second);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalQualifierNoVersion() {
|
||||
Version first = parse("1.2.0.RELEASE");
|
||||
Version second = parse("1.2.0.RELEASE");
|
||||
assertThat(first, comparesEqualTo(second));
|
||||
assertThat(first, equalTo(second));
|
||||
assertThat(first).isEqualByComparingTo(second);
|
||||
assertThat(first).isEqualTo(second);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalQualifierVersion() {
|
||||
Version first = parse("1.2.0.RC1");
|
||||
Version second = parse("1.2.0.RC1");
|
||||
assertThat(first, comparesEqualTo(second));
|
||||
assertThat(first, equalTo(second));
|
||||
assertThat(first).isEqualByComparingTo(second);
|
||||
assertThat(first).isEqualTo(second);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareMajorOnly() {
|
||||
assertThat(parse("2.2.0"), greaterThan(parse("1.8.0")));
|
||||
assertThat(parse("2.2.0")).isGreaterThan(parse("1.8.0"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareMinorOnly() {
|
||||
assertThat(parse("2.2.0"), greaterThan(parse("2.1.9")));
|
||||
assertThat(parse("2.2.0")).isGreaterThan(parse("2.1.9"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void comparePatchOnly() {
|
||||
assertThat(parse("2.2.4"), greaterThan(parse("2.2.3")));
|
||||
assertThat(parse("2.2.4")).isGreaterThan(parse("2.2.3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareHigherVersion() {
|
||||
assertThat(parse("1.2.0.RELEASE"), greaterThan(parse("1.1.9.RELEASE")));
|
||||
assertThat(parse("1.2.0.RELEASE")).isGreaterThan(parse("1.1.9.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareHigherQualifier() {
|
||||
assertThat(parse("1.2.0.RC1"), greaterThan(parse("1.2.0.M1")));
|
||||
assertThat(parse("1.2.0.RC1")).isGreaterThan(parse("1.2.0.M1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareHigherQualifierVersion() {
|
||||
assertThat(parse("1.2.0.RC2"), greaterThan(parse("1.2.0.RC1")));
|
||||
assertThat(parse("1.2.0.RC2")).isGreaterThan(parse("1.2.0.RC1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareLowerVersion() {
|
||||
assertThat(parse("1.0.5.RELEASE"), lessThan(parse("1.1.9.RELEASE")));
|
||||
assertThat(parse("1.0.5.RELEASE")).isLessThan(parse("1.1.9.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareLowerQualifier() {
|
||||
assertThat(parse("1.2.0.RC1"), lessThan(parse("1.2.0.RELEASE")));
|
||||
assertThat(parse("1.2.0.RC1")).isLessThan(parse("1.2.0.RELEASE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareLessQualifierVersion() {
|
||||
assertThat(parse("1.2.0.RC2"), lessThan(parse("1.2.0.RC3")));
|
||||
assertThat(parse("1.2.0.RC2")).isLessThan(parse("1.2.0.RC3"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareWithNull() {
|
||||
assertThat(parse("1.2.0.RC2"), greaterThan(null));
|
||||
assertThat(parse("1.2.0.RC2")).isGreaterThan(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareUnknownQualifier() {
|
||||
assertThat(parse("1.2.0.Beta"), lessThan(parse("1.2.0.CR")));
|
||||
assertThat(parse("1.2.0.Beta")).isLessThan(parse("1.2.0.CR"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compareUnknownQualifierVersion() {
|
||||
assertThat(parse("1.2.0.Beta1"), lessThan(parse("1.2.0.Beta2")));
|
||||
assertThat(parse("1.2.0.Beta1")).isLessThan(parse("1.2.0.Beta2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snapshotGreaterThanRC() {
|
||||
assertThat(parse("1.2.0.BUILD-SNAPSHOT"), greaterThan(parse("1.2.0.RC1")));
|
||||
assertThat(parse("1.2.0.BUILD-SNAPSHOT")).isGreaterThan(parse("1.2.0.RC1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snapshotLowerThanRelease() {
|
||||
assertThat(parse("1.2.0.BUILD-SNAPSHOT"), lessThan(parse("1.2.0.RELEASE")));
|
||||
assertThat(parse("1.2.0.BUILD-SNAPSHOT")).isLessThan(parse("1.2.0.RELEASE"));
|
||||
}
|
||||
|
||||
private static Version parse(String text) {
|
||||
return parser.parse(text);
|
||||
private Version parse(String text) {
|
||||
return this.parser.parse(text);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
0
initializr-service/src/test/java/io/spring/initializr/service/InitializrServiceSmokeTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/InitializrServiceSmokeTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/AbstractRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/AbstractRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/JacksonKotlinRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/JacksonKotlinRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/Java9RequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/Java9RequestPostProcessorTests.java
Normal file → Executable file
2
initializr-service/src/test/java/io/spring/initializr/service/extension/ReactorTestRequestPostProcessorTests.java
Normal file → Executable file
2
initializr-service/src/test/java/io/spring/initializr/service/extension/ReactorTestRequestPostProcessorTests.java
Normal file → Executable file
@@ -56,4 +56,4 @@ public class ReactorTestRequestPostProcessorTests
|
||||
.hasSpringBootStarterTest().hasDependenciesCount(2);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
0
initializr-service/src/test/java/io/spring/initializr/service/extension/SpringBatchTestRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/SpringBatchTestRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/SpringBoot2RequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/SpringBoot2RequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/SpringCloudStreamRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/SpringCloudStreamRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/SpringSecurityTestRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/SpringSecurityTestRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/SpringSessionRequestPostProcessorTests.java
Normal file → Executable file
0
initializr-service/src/test/java/io/spring/initializr/service/extension/SpringSessionRequestPostProcessorTests.java
Normal file → Executable file
2
initializr-service/src/test/java/io/spring/initializr/service/info/CloudFoundryInfoContributorTests.java
Normal file → Executable file
2
initializr-service/src/test/java/io/spring/initializr/service/info/CloudFoundryInfoContributorTests.java
Normal file → Executable file
@@ -58,4 +58,4 @@ public class CloudFoundryInfoContributorTests {
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
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