Rework 155c60b7 to structure the code consistently, in particular with a more
natural order of attributes. Update test to use non-default values to ensure
that the customization has been applied.

See gh-2793
This commit is contained in:
Stephane Nicoll
2015-05-13 14:06:46 +02:00
parent 0b8fd67507
commit b20d11fe9c
4 changed files with 193 additions and 183 deletions

View File

@@ -25,7 +25,6 @@ import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import joptsimple.OptionSet;
import org.apache.http.Header;
import org.apache.http.client.methods.HttpUriRequest;
import org.junit.Before;
@@ -35,6 +34,7 @@ import org.junit.rules.TemporaryFolder;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.cli.command.status.ExitStatus;
import static org.hamcrest.Matchers.startsWith;
@@ -262,6 +262,31 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
assertEquals("File should not have changed", fileLength, conflict.length());
}
@Test
public void parseProjectOptions() throws Exception {
this.handler.disableProjectGeneration();
this.command.run("-g=org.demo", "-a=acme", "-v=1.2.3-SNAPSHOT", "-n=acme-sample",
"--description=Acme sample project", "-p=war", "-t=ant-project",
"--build=grunt", "--format=web", "-j=1.9", "-l=groovy",
"-b=1.2.0.RELEASE", "-d=web,data-jpa");
assertEquals("org.demo", this.handler.lastRequest.getGroupId());
assertEquals("acme", this.handler.lastRequest.getArtifactId());
assertEquals("1.2.3-SNAPSHOT", this.handler.lastRequest.getVersion());
assertEquals("acme-sample", this.handler.lastRequest.getName());
assertEquals("Acme sample project", this.handler.lastRequest.getDescription());
assertEquals("war", this.handler.lastRequest.getPackaging());
assertEquals("ant-project", this.handler.lastRequest.getType());
assertEquals("grunt", this.handler.lastRequest.getBuild());
assertEquals("web", this.handler.lastRequest.getFormat());
assertEquals("1.9", this.handler.lastRequest.getJavaVersion());
assertEquals("groovy", this.handler.lastRequest.getLanguage());
assertEquals("1.2.0.RELEASE", this.handler.lastRequest.getBootVersion());
List<String> dependencies = this.handler.lastRequest.getDependencies();
assertEquals(2, dependencies.size());
assertTrue(dependencies.contains("web"));
assertTrue(dependencies.contains("data-jpa"));
}
@Test
public void overwriteFileInArchive() throws Exception {
File folder = this.temporaryFolder.newFolder();
@@ -278,30 +303,6 @@ public class InitCommandTests extends AbstractHttpClientMockTests {
assertTrue("File should have changed", fileLength != conflict.length());
}
@Test
public void parseProjectOptions() throws Exception {
this.handler.disableProjectGeneration();
this.command.run("-b=1.2.0.RELEASE", "-d=web,data-jpa", "-j=1.9", "-p=war", "--build=grunt",
"--format=web", "-t=ant-project", "-lang=groovy", "-g=org.test", "-a=demo", "-n=demo",
"-v=0.0.1-SNAPSHOT", "-des=Demo project for Spring Boot");
assertEquals("1.2.0.RELEASE", this.handler.lastRequest.getBootVersion());
List<String> dependencies = this.handler.lastRequest.getDependencies();
assertEquals(2, dependencies.size());
assertTrue(dependencies.contains("web"));
assertTrue(dependencies.contains("data-jpa"));
assertEquals("1.9", this.handler.lastRequest.getJavaVersion());
assertEquals("war", this.handler.lastRequest.getPackaging());
assertEquals("grunt", this.handler.lastRequest.getBuild());
assertEquals("web", this.handler.lastRequest.getFormat());
assertEquals("ant-project", this.handler.lastRequest.getType());
assertEquals("groovy", this.handler.lastRequest.getLanguage());
assertEquals("org.test", this.handler.lastRequest.getGroupId());
assertEquals("demo", this.handler.lastRequest.getArtifactId());
assertEquals("demo", this.handler.lastRequest.getName());
assertEquals("0.0.1-SNAPSHOT", this.handler.lastRequest.getVersion());
assertEquals("Demo project for Spring Boot", this.handler.lastRequest.getDescription());
}
@Test
public void parseTypeOnly() throws Exception {
this.handler.disableProjectGeneration();

View File

@@ -27,6 +27,7 @@ import org.json.JSONObject;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.util.StreamUtils;
@@ -68,7 +69,7 @@ public class ProjectGenerationRequestTests {
@Test
public void customBootVersion() {
this.request.setBootVersion("1.2.0.RELEASE");
assertEquals(createDefaultUrl("?bootVersion=1.2.0.RELEASE&type=test-type"),
assertEquals(createDefaultUrl("?type=test-type&bootVersion=1.2.0.RELEASE"),
this.request.generateUrl(createDefaultMetadata()));
}
@@ -90,7 +91,7 @@ public class ProjectGenerationRequestTests {
@Test
public void customJavaVersion() {
this.request.setJavaVersion("1.8");
assertEquals(createDefaultUrl("?javaVersion=1.8&type=test-type"),
assertEquals(createDefaultUrl("?type=test-type&javaVersion=1.8"),
this.request.generateUrl(createDefaultMetadata()));
}
@@ -115,20 +116,20 @@ public class ProjectGenerationRequestTests {
@Test
public void customLanguage() {
this.request.setLanguage("java");
assertEquals(createDefaultUrl("?language=java&type=test-type"),
this.request.setLanguage("groovy");
assertEquals(createDefaultUrl("?type=test-type&language=groovy"),
this.request.generateUrl(createDefaultMetadata()));
}
@Test
public void customProjectInfo() {
this.request.setGroupId("org.test");
this.request.setArtifactId("demo");
this.request.setVersion("0.0.1-SNAPSHOT");
this.request.setDescription("Spring Boot Demo");
assertEquals(createDefaultUrl("?artifactId=demo&description=Spring+Boot+Demo"
+ "&groupId=org.test&type=test-type&version=0.0.1-SNAPSHOT"),
this.request.generateUrl(createDefaultMetadata()));
this.request.setGroupId("org.acme");
this.request.setArtifactId("sample");
this.request.setVersion("1.0.1-SNAPSHOT");
this.request.setDescription("Spring Boot Test");
assertEquals(createDefaultUrl("?groupId=org.acme&artifactId=sample&version=1.0.1-SNAPSHOT" +
"&description=Spring+Boot+Test&type=test-type"),
this.request.generateUrl(createDefaultMetadata()));
}
@Test