mirror of
https://gitee.com/dcren/initializr.git
synced 2025-11-28 09:22:41 +08:00
Migrate initializr-web to Java
This commit is contained in:
committed by
Stephane Nicoll
parent
1385e82eb5
commit
ec5a7da507
@@ -44,6 +44,11 @@
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.rauschig</groupId>
|
||||
<artifactId>jarchivelib</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.spring.initializr</groupId>
|
||||
<artifactId>initializr-web</artifactId>
|
||||
@@ -82,13 +87,4 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.gmavenplus</groupId>
|
||||
<artifactId>gmavenplus-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -19,13 +19,11 @@ package io.spring.initializr.actuate;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
|
||||
import groovy.json.JsonSlurper;
|
||||
import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
|
||||
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
|
||||
|
||||
/**
|
||||
* Tests for actuator specific features.
|
||||
@@ -34,9 +32,7 @@ import io.spring.initializr.web.AbstractInitializrControllerIntegrationTests;
|
||||
*/
|
||||
@ActiveProfiles("test-default")
|
||||
public class ActuatorIntegrationTests
|
||||
extends AbstractInitializrControllerIntegrationTests {
|
||||
|
||||
private final JsonSlurper slurper = new JsonSlurper();
|
||||
extends AbstractFullStackInitializrIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void infoHasExternalProperties() {
|
||||
@@ -49,36 +45,35 @@ public class ActuatorIntegrationTests
|
||||
@Test
|
||||
public void metricsAvailableByDefault() {
|
||||
downloadZip("/starter.zip?packaging=jar&javaVersion=1.8&style=web&style=jpa");
|
||||
Map<String, Integer> result = metricsEndpoint();
|
||||
Integer requests = result.get("counter.initializr.requests");
|
||||
Integer packaging = result.get("counter.initializr.packaging.jar");
|
||||
Integer javaVersion = result.get("counter.initializr.java_version.1_8");
|
||||
Integer webDependency = result.get("counter.initializr.dependency.web");
|
||||
Integer jpaDependency = result.get("counter.initializr.dependency.jpa");
|
||||
JSONObject result = metricsEndpoint();
|
||||
int requests = result.getInt("counter.initializr.requests");
|
||||
int packaging = result.getInt("counter.initializr.packaging.jar");
|
||||
int javaVersion = result.getInt("counter.initializr.java_version.1_8");
|
||||
int webDependency = result.getInt("counter.initializr.dependency.web");
|
||||
int jpaDependency = result.getInt("counter.initializr.dependency.data-jpa");
|
||||
|
||||
// No jpa dep this time
|
||||
downloadZip("/starter.zip?packaging=jar&javaVersion=1.8&style=web");
|
||||
|
||||
Map<String, Integer> updatedResult = metricsEndpoint();
|
||||
JSONObject updatedResult = metricsEndpoint();
|
||||
assertEquals("Number of request should have increased", requests + 1,
|
||||
updatedResult.get("counter.initializr.requests").intValue());
|
||||
updatedResult.getInt("counter.initializr.requests"));
|
||||
assertEquals("jar packaging metric should have increased", packaging + 1,
|
||||
updatedResult.get("counter.initializr.packaging.jar").intValue());
|
||||
updatedResult.getInt("counter.initializr.packaging.jar"));
|
||||
assertEquals("java version metric should have increased", javaVersion + 1,
|
||||
updatedResult.get("counter.initializr.java_version.1_8").intValue());
|
||||
updatedResult.getInt("counter.initializr.java_version.1_8"));
|
||||
assertEquals("web dependency metric should have increased", webDependency + 1,
|
||||
updatedResult.get("counter.initializr.dependency.web").intValue());
|
||||
assertEquals("jpa dependency metric should not have increased", jpaDependency,
|
||||
updatedResult.get("counter.initializr.dependency.jpa"));
|
||||
updatedResult.getInt("counter.initializr.dependency.web"));
|
||||
assertEquals("jpa dependency metric should not have increased", jpaDependency + 0,
|
||||
updatedResult.getInt("counter.initializr.dependency.data-jpa"));
|
||||
}
|
||||
|
||||
private Map<String, Integer> metricsEndpoint() {
|
||||
private JSONObject metricsEndpoint() {
|
||||
return parseJson(getRestTemplate().getForObject(createUrl("/metrics"), String.class));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Map<String, Integer> parseJson(String content) {
|
||||
return (Map<String, Integer>) slurper.parseText(content);
|
||||
private JSONObject parseJson(String content) {
|
||||
return new JSONObject(content);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,8 +25,9 @@ import static org.junit.Assert.fail;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -41,7 +42,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
|
||||
import groovy.json.JsonSlurper;
|
||||
import io.spring.initializr.actuate.stat.MainControllerStatsIntegrationTests.StatsMockController;
|
||||
import io.spring.initializr.actuate.stat.MainControllerStatsIntegrationTests.StatsMockController.Content;
|
||||
import io.spring.initializr.web.AbstractFullStackInitializrIntegrationTests;
|
||||
@@ -62,8 +62,6 @@ public class MainControllerStatsIntegrationTests
|
||||
@Autowired
|
||||
private StatsProperties statsProperties;
|
||||
|
||||
private final JsonSlurper slurper = new JsonSlurper();
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.statsMockController.stats.clear();
|
||||
@@ -77,13 +75,11 @@ public class MainControllerStatsIntegrationTests
|
||||
assertEquals("No stat got generated", 1, statsMockController.stats.size());
|
||||
Content content = statsMockController.stats.get(0);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,Object> json = (Map<String, Object>) slurper.parseText(content.json);
|
||||
JSONObject json = new JSONObject(content.json);
|
||||
assertEquals("com.foo", json.get("groupId"));
|
||||
assertEquals("bar", json.get("artifactId"));
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> list = (List<String>) json.get("dependencies");
|
||||
assertEquals(1, list.size());
|
||||
JSONArray list = json.getJSONArray("dependencies");
|
||||
assertEquals(1, list.length());
|
||||
assertEquals("web", list.get(0));
|
||||
}
|
||||
|
||||
@@ -108,9 +104,8 @@ public class MainControllerStatsIntegrationTests
|
||||
assertEquals("No stat got generated", 1, statsMockController.stats.size());
|
||||
Content content = statsMockController.stats.get(0);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,Object> json = (Map<String, Object>) slurper.parseText(content.json);
|
||||
assertFalse("requestIp property should not be set", json.containsKey("requestIp"));
|
||||
JSONObject json = new JSONObject(content.json);
|
||||
assertFalse("requestIp property should not be set", json.has("requestIp"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,8 +116,7 @@ public class MainControllerStatsIntegrationTests
|
||||
assertEquals("No stat got generated", 1, statsMockController.stats.size());
|
||||
Content content = statsMockController.stats.get(0);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,Object> json = (Map<String, Object>) slurper.parseText(content.json);
|
||||
JSONObject json = new JSONObject(content.json);
|
||||
assertEquals("Wrong requestIp", "10.0.0.123", json.get("requestIp"));
|
||||
}
|
||||
|
||||
@@ -134,10 +128,9 @@ public class MainControllerStatsIntegrationTests
|
||||
assertEquals("No stat got generated", 1, statsMockController.stats.size());
|
||||
Content content = statsMockController.stats.get(0);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,Object> json = (Map<String, Object>) slurper.parseText(content.json);
|
||||
JSONObject json = new JSONObject(content.json);
|
||||
assertFalse("requestIpv4 property should not be set if value is not a valid IPv4",
|
||||
json.containsKey("requestIpv4"));
|
||||
json.has("requestIpv4"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,10 +141,9 @@ public class MainControllerStatsIntegrationTests
|
||||
assertEquals("No stat got generated", 1, statsMockController.stats.size());
|
||||
Content content = statsMockController.stats.get(0);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,Object> json = (Map<String, Object>) slurper.parseText(content.json);
|
||||
JSONObject json = new JSONObject(content.json);
|
||||
assertFalse("requestCountry property should not be set if value is set to xx",
|
||||
json.containsKey("requestCountry"));
|
||||
json.has("requestCountry"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,8 +157,7 @@ public class MainControllerStatsIntegrationTests
|
||||
assertEquals("No stat got generated", 1, statsMockController.stats.size());
|
||||
Content content = statsMockController.stats.get(0);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String,Object> json = (Map<String, Object>) slurper.parseText(content.json);
|
||||
JSONObject json = new JSONObject(content.json);
|
||||
assertEquals("com.example", json.get("groupId"));
|
||||
assertEquals("demo", json.get("artifactId"));
|
||||
assertEquals(true, json.get("invalid"));
|
||||
|
||||
Reference in New Issue
Block a user