Add parsing of LiveBeanModel to actuator client
This commit is contained in:
@@ -84,7 +84,7 @@
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
<version>${commons-io-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -25,6 +25,8 @@ import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.HoverProvider;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
@@ -54,8 +56,8 @@ public class AutowiredHoverProvider implements HoverProvider {
|
||||
|
||||
for (SpringBootAppProvider bootApp : runningApps) {
|
||||
try {
|
||||
String liveBeans = bootApp.getBeans();
|
||||
if (liveBeans != null && liveBeans.length() > 0) {
|
||||
LiveBeansModel liveBeans = bootApp.getBeans();
|
||||
if (liveBeans != null && !liveBeans.isEmpty()) {
|
||||
addLiveHoverContent(annotation, doc, liveBeans, bootApp, hoverContent);
|
||||
}
|
||||
}
|
||||
@@ -85,8 +87,8 @@ public class AutowiredHoverProvider implements HoverProvider {
|
||||
try {
|
||||
for (SpringBootApp bootApp : runningApps) {
|
||||
try {
|
||||
String liveBeans = bootApp.getBeans();
|
||||
if (liveBeans != null && liveBeans.length() > 0) {
|
||||
LiveBeansModel liveBeans = bootApp.getBeans();
|
||||
if (liveBeans != null && !liveBeans.isEmpty()) {
|
||||
Range range = getLiveHoverHint(annotation, doc, liveBeans);
|
||||
if (range != null) {
|
||||
return ImmutableList.of(range);
|
||||
@@ -105,14 +107,11 @@ public class AutowiredHoverProvider implements HoverProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Range getLiveHoverHint(Annotation annotation, TextDocument doc, String liveBeansJSON) {
|
||||
public Range getLiveHoverHint(Annotation annotation, TextDocument doc, LiveBeansModel beansModel) {
|
||||
try {
|
||||
String type = findDeclaredType(annotation);
|
||||
if (type != null && liveBeansJSON != null) {
|
||||
|
||||
LiveBeansModel beansModel = LiveBeansModel.parse(liveBeansJSON);
|
||||
if (type != null && beansModel != null) {
|
||||
LiveBean[] beansOfType = beansModel.getBeansOfType(type);
|
||||
|
||||
if (beansOfType.length > 0) {
|
||||
Range hoverRange = doc.toRange(annotation.getStartPosition(), annotation.getLength());
|
||||
return hoverRange;
|
||||
@@ -126,11 +125,9 @@ public class AutowiredHoverProvider implements HoverProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void addLiveHoverContent(Annotation annotation, TextDocument doc, String liveBeansJSON, SpringBootAppProvider bootApp, List<Either<String, MarkedString>> hoverContent) {
|
||||
public void addLiveHoverContent(Annotation annotation, TextDocument doc, LiveBeansModel beansModel, SpringBootAppProvider bootApp, List<Either<String, MarkedString>> hoverContent) {
|
||||
String type = findDeclaredType(annotation);
|
||||
if (type != null && liveBeansJSON != null) {
|
||||
|
||||
LiveBeansModel beansModel = LiveBeansModel.parse(liveBeansJSON);
|
||||
if (type != null && beansModel != null) {
|
||||
LiveBean[] beansOfType = beansModel.getBeansOfType(type);
|
||||
|
||||
if (beansOfType.length > 0) {
|
||||
|
||||
@@ -10,12 +10,14 @@
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.autowired;
|
||||
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
*/
|
||||
public interface SpringBootAppProvider {
|
||||
|
||||
public String getBeans() throws Exception;
|
||||
public LiveBeansModel getBeans() throws Exception;
|
||||
public String getProcessID();
|
||||
public String getProcessName();
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
package org.springframework.ide.vscode.boot.java.autowired;
|
||||
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
@@ -24,7 +25,7 @@ public class SpringBootAppProviderImpl implements SpringBootAppProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBeans() throws Exception {
|
||||
public LiveBeansModel getBeans() throws Exception {
|
||||
return bootApp.getBeans();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ import org.eclipse.lsp4j.MarkedString;
|
||||
import org.eclipse.lsp4j.Range;
|
||||
import org.eclipse.lsp4j.jsonrpc.messages.Either;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.Constants;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.LiveBean;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.LiveBeansModel;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.SpringBootAppProvider;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.SpringBootAppProviderImpl;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.HoverProvider;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
import org.springframework.ide.vscode.commons.util.BadLocationException;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
import org.springframework.ide.vscode.commons.util.text.TextDocument;
|
||||
@@ -68,8 +68,8 @@ public class ComponentHoverProvider implements HoverProvider {
|
||||
List<Either<String, MarkedString>> hoverContent = new ArrayList<>();
|
||||
for (SpringBootAppProvider bootApp : runningApps) {
|
||||
try {
|
||||
String liveBeans = bootApp.getBeans();
|
||||
if (liveBeans != null && liveBeans.length() > 0) {
|
||||
LiveBeansModel liveBeans = bootApp.getBeans();
|
||||
if (liveBeans != null && !liveBeans.isEmpty()) {
|
||||
addLiveHoverContent(typeDecl, doc, liveBeans, bootApp, hoverContent);
|
||||
}
|
||||
}
|
||||
@@ -101,8 +101,8 @@ public class ComponentHoverProvider implements HoverProvider {
|
||||
try {
|
||||
for (SpringBootApp bootApp : runningApps) {
|
||||
try {
|
||||
String liveBeans = bootApp.getBeans();
|
||||
if (liveBeans != null && liveBeans.length() > 0) {
|
||||
LiveBeansModel liveBeans = bootApp.getBeans();
|
||||
if (liveBeans != null && !liveBeans.isEmpty()) {
|
||||
Range range = getLiveHoverHint(annotation, doc, liveBeans);
|
||||
if (range != null) {
|
||||
return ImmutableList.of(range);
|
||||
@@ -121,13 +121,11 @@ public class ComponentHoverProvider implements HoverProvider {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Range getLiveHoverHint(Annotation annotation, TextDocument doc, String liveBeansJSON) {
|
||||
public Range getLiveHoverHint(Annotation annotation, TextDocument doc, LiveBeansModel beansModel) {
|
||||
try {
|
||||
TypeDeclaration type = findDeclaredType(annotation);
|
||||
if (type != null && liveBeansJSON != null) {
|
||||
if (type != null && beansModel != null) {
|
||||
String typeName = type.resolveBinding().getQualifiedName();
|
||||
|
||||
LiveBeansModel beansModel = LiveBeansModel.parse(liveBeansJSON);
|
||||
LiveBean[] beansOfType = beansModel.getBeansOfType(typeName);
|
||||
|
||||
if (beansOfType.length > 0) {
|
||||
@@ -160,11 +158,9 @@ public class ComponentHoverProvider implements HoverProvider {
|
||||
}
|
||||
|
||||
|
||||
public void addLiveHoverContent(TypeDeclaration declaringType, TextDocument doc, String liveBeansJSON, SpringBootAppProvider bootApp, List<Either<String, MarkedString>> hoverContent) {
|
||||
public void addLiveHoverContent(TypeDeclaration declaringType, TextDocument doc, LiveBeansModel beansModel, SpringBootAppProvider bootApp, List<Either<String, MarkedString>> hoverContent) {
|
||||
String type = declaringType.resolveBinding().getQualifiedName();
|
||||
if (type != null && liveBeansJSON != null) {
|
||||
|
||||
LiveBeansModel beansModel = LiveBeansModel.parse(liveBeansJSON);
|
||||
if (type != null && beansModel != null) {
|
||||
LiveBean[] beansOfType = beansModel.getBeansOfType(type);
|
||||
|
||||
if (beansOfType.length > 0) {
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.AutowiredHoverProvider;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.SpringBootAppProvider;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
@@ -82,7 +83,7 @@ public class AutowiredHoverProviderTest {
|
||||
AutowiredHoverProvider provider = new AutowiredHoverProvider();
|
||||
String beansJSON = new String(Files.readAllBytes(new File(directory, "runtime-bean-information.json").toPath()));
|
||||
|
||||
Range hint = provider.getLiveHoverHint((Annotation)node, document, beansJSON);
|
||||
Range hint = provider.getLiveHoverHint((Annotation)node, document, LiveBeansModel.parse(beansJSON));
|
||||
assertNotNull(hint);
|
||||
|
||||
assertEquals(11, hint.getStart().getLine());
|
||||
@@ -106,7 +107,7 @@ public class AutowiredHoverProviderTest {
|
||||
ASTNode node = NodeFinder.perform(cu, offset, 0).getParent();
|
||||
|
||||
AutowiredHoverProvider provider = new AutowiredHoverProvider();
|
||||
Range hint = provider.getLiveHoverHint((Annotation)node, document, (String)null);
|
||||
Range hint = provider.getLiveHoverHint((Annotation)node, document, LiveBeansModel.parse(null));
|
||||
assertNull(hint);
|
||||
}
|
||||
|
||||
@@ -127,7 +128,7 @@ public class AutowiredHoverProviderTest {
|
||||
AutowiredHoverProvider provider = new AutowiredHoverProvider();
|
||||
String beansJSON = new String(Files.readAllBytes(new File(directory, "wrong-runtime-bean-information.json").toPath()));
|
||||
|
||||
Range hint = provider.getLiveHoverHint((Annotation)node, document, beansJSON);
|
||||
Range hint = provider.getLiveHoverHint((Annotation)node, document, LiveBeansModel.parse(beansJSON));
|
||||
assertNull(hint);
|
||||
}
|
||||
|
||||
@@ -146,7 +147,7 @@ public class AutowiredHoverProviderTest {
|
||||
ASTNode node = NodeFinder.perform(cu, offset, 0).getParent();
|
||||
|
||||
AutowiredHoverProvider provider = new AutowiredHoverProvider();
|
||||
String beansJSON = new String(Files.readAllBytes(new File(directory, "runtime-bean-information.json").toPath()));
|
||||
LiveBeansModel beansModel = LiveBeansModel.parse(new String(Files.readAllBytes(new File(directory, "runtime-bean-information.json").toPath())));
|
||||
|
||||
SpringBootAppProvider bootApp = new SpringBootAppProvider() {
|
||||
@Override
|
||||
@@ -160,8 +161,8 @@ public class AutowiredHoverProviderTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBeans() throws Exception {
|
||||
return beansJSON;
|
||||
public LiveBeansModel getBeans() throws Exception {
|
||||
return beansModel;
|
||||
}
|
||||
};
|
||||
CompletableFuture<Hover> hoverFuture = provider.provideHover(null, (Annotation)node, null, offset, document, new SpringBootAppProvider[] {bootApp});
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.SpringBootAppProvider;
|
||||
import org.springframework.ide.vscode.boot.java.beans.ComponentHoverProvider;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
import org.springframework.ide.vscode.commons.java.IClasspath;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
import org.springframework.ide.vscode.commons.languageserver.java.JavaProjectFinder;
|
||||
@@ -82,7 +83,7 @@ public class ComponentHoverProviderTest {
|
||||
ComponentHoverProvider provider = new ComponentHoverProvider();
|
||||
String beansJSON = new String(Files.readAllBytes(new File(directory, "runtime-bean-information-automatically-wired.json").toPath()));
|
||||
|
||||
Range hint = provider.getLiveHoverHint((Annotation)node, document, beansJSON);
|
||||
Range hint = provider.getLiveHoverHint((Annotation)node, document, LiveBeansModel.parse(beansJSON));
|
||||
assertNotNull(hint);
|
||||
|
||||
assertEquals(10, hint.getStart().getLine());
|
||||
@@ -108,7 +109,7 @@ public class ComponentHoverProviderTest {
|
||||
ComponentHoverProvider provider = new ComponentHoverProvider();
|
||||
String beansJSON = new String(Files.readAllBytes(new File(directory, "runtime-bean-information.json").toPath()));
|
||||
|
||||
Range hint = provider.getLiveHoverHint((Annotation)node, document, beansJSON);
|
||||
Range hint = provider.getLiveHoverHint((Annotation)node, document, LiveBeansModel.parse(beansJSON));
|
||||
assertNull(hint);
|
||||
}
|
||||
|
||||
@@ -127,7 +128,7 @@ public class ComponentHoverProviderTest {
|
||||
ASTNode node = NodeFinder.perform(cu, offset, 0).getParent();
|
||||
|
||||
ComponentHoverProvider provider = new ComponentHoverProvider();
|
||||
String beansJSON = new String(Files.readAllBytes(new File(directory, "runtime-bean-information-automatically-wired.json").toPath()));
|
||||
LiveBeansModel beansModel = LiveBeansModel.parse(new String(Files.readAllBytes(new File(directory, "runtime-bean-information-automatically-wired.json").toPath())));
|
||||
|
||||
SpringBootAppProvider bootApp = new SpringBootAppProvider() {
|
||||
@Override
|
||||
@@ -141,8 +142,8 @@ public class ComponentHoverProviderTest {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBeans() throws Exception {
|
||||
return beansJSON;
|
||||
public LiveBeansModel getBeans() throws Exception {
|
||||
return beansModel;
|
||||
}
|
||||
};
|
||||
CompletableFuture<Hover> hoverFuture = provider.provideHover(null, (Annotation) node, null, 0, document, new SpringBootAppProvider[] {bootApp});
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Collection;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.ide.vscode.boot.java.handlers.RunningAppProvider;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.SpringBootApp;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
|
||||
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness.Builder;
|
||||
|
||||
@@ -67,7 +68,7 @@ public class MockRunningAppProvider {
|
||||
}
|
||||
|
||||
public MockAppBuilder beans(String beans) throws Exception {
|
||||
when(app.getBeans()).thenReturn(beans);
|
||||
when(app.getBeans()).thenReturn(LiveBeansModel.parse(beans));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,11 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.8.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io-version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.sun</groupId>
|
||||
|
||||
@@ -30,7 +30,9 @@ import javax.management.remote.JMXServiceURL;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
import org.springframework.ide.vscode.commons.util.Log;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -170,7 +172,7 @@ public class SpringBootApp {
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getBeans() throws Exception {
|
||||
private String getBeansJson() throws Exception {
|
||||
Object result = getActuatorDataFromAttribute("org.springframework.boot:type=Endpoint,name=beansEndpoint", "Data");
|
||||
if (result != null) {
|
||||
String beans = new ObjectMapper().writeValueAsString(result);
|
||||
@@ -186,6 +188,14 @@ public class SpringBootApp {
|
||||
return null;
|
||||
}
|
||||
|
||||
public LiveBeansModel getBeans() throws Exception {
|
||||
String json = getBeansJson();
|
||||
if (StringUtil.hasText(json)) {
|
||||
return LiveBeansModel.parse(json);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getRequestMappings() throws Exception {
|
||||
Object result = getActuatorDataFromAttribute("org.springframework.boot:type=Endpoint,name=requestMappingEndpoint", "Data");
|
||||
if (result != null) {
|
||||
@@ -424,5 +434,4 @@ public class SpringBootApp {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.autowired;
|
||||
package org.springframework.ide.vscode.commons.boot.app.cli.livebean;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
@@ -8,16 +8,19 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.autowired;
|
||||
package org.springframework.ide.vscode.commons.boot.app.cli.livebean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.ide.vscode.commons.util.StringUtil;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
@@ -26,32 +29,32 @@ public class LiveBeansModel {
|
||||
|
||||
public static LiveBeansModel parse(String json) {
|
||||
LiveBeansModel model = new LiveBeansModel();
|
||||
if (StringUtil.hasText(json)) {
|
||||
try {
|
||||
JSONArray mainArray = new JSONArray(json);
|
||||
|
||||
try {
|
||||
JSONArray mainArray = new JSONArray(json);
|
||||
for (int i = 0; i < mainArray.length(); i++) {
|
||||
JSONObject appContext = mainArray.getJSONObject(i);
|
||||
if (appContext == null) continue;
|
||||
|
||||
for (int i = 0; i < mainArray.length(); i++) {
|
||||
JSONObject appContext = mainArray.getJSONObject(i);
|
||||
if (appContext == null) continue;
|
||||
JSONArray beansArray = appContext.optJSONArray("beans");
|
||||
if (beansArray == null) continue;
|
||||
|
||||
JSONArray beansArray = appContext.optJSONArray("beans");
|
||||
if (beansArray == null) continue;
|
||||
for (int j = 0; j < beansArray.length(); j++) {
|
||||
JSONObject beanObject = beansArray.getJSONObject(j);
|
||||
if (beanObject == null) continue;
|
||||
|
||||
for (int j = 0; j < beansArray.length(); j++) {
|
||||
JSONObject beanObject = beansArray.getJSONObject(j);
|
||||
if (beanObject == null) continue;
|
||||
|
||||
LiveBean bean = LiveBean.parse(beanObject);
|
||||
if (bean != null) {
|
||||
model.add(bean);
|
||||
LiveBean bean = LiveBean.parse(beanObject);
|
||||
if (bean != null) {
|
||||
model.add(bean);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
@@ -85,4 +88,12 @@ public class LiveBeansModel {
|
||||
}
|
||||
}
|
||||
|
||||
public Stream<LiveBean> getAllBeans() {
|
||||
return beansViaName.values().stream().flatMap(Collection::stream);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return !getAllBeans().findAny().isPresent();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,15 +8,16 @@
|
||||
* Contributors:
|
||||
* Pivotal, Inc. - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.springframework.ide.vscode.boot.java.autowired.test;
|
||||
package org.springframework.ide.vscode.commons.boot.app.cli;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.LiveBean;
|
||||
import org.springframework.ide.vscode.boot.java.autowired.LiveBeansModel;
|
||||
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBean;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
|
||||
/**
|
||||
* @author Martin Lippert
|
||||
@@ -25,7 +26,7 @@ public class LiveBeansModelTest {
|
||||
|
||||
@Test
|
||||
public void testSimpleModel() throws Exception {
|
||||
String json = IOUtils.toString(ProjectsHarness.class.getResourceAsStream("/live-beans-models/simple-live-beans-model.json"));
|
||||
String json = IOUtils.toString(getResourceAsStream("/live-beans-models/simple-live-beans-model.json"));
|
||||
LiveBeansModel model = LiveBeansModel.parse(json);
|
||||
|
||||
LiveBean[] bean = model.getBeansOfType("org.test.DependencyA");
|
||||
@@ -49,7 +50,7 @@ public class LiveBeansModelTest {
|
||||
|
||||
@Test
|
||||
public void testEmptyModel() throws Exception {
|
||||
String json = IOUtils.toString(ProjectsHarness.class.getResourceAsStream("/live-beans-models/empty-live-beans-model.json"));
|
||||
String json = IOUtils.toString(getResourceAsStream("/live-beans-models/empty-live-beans-model.json"));
|
||||
LiveBeansModel model = LiveBeansModel.parse(json);
|
||||
|
||||
LiveBean[] bean = model.getBeansOfType("org.test.DependencyA");
|
||||
@@ -58,11 +59,15 @@ public class LiveBeansModelTest {
|
||||
|
||||
@Test
|
||||
public void testTotallyEmptyModel() throws Exception {
|
||||
String json = IOUtils.toString(ProjectsHarness.class.getResourceAsStream("/live-beans-models/totally-empty-live-beans-model.json"));
|
||||
String json = IOUtils.toString(getResourceAsStream("/live-beans-models/totally-empty-live-beans-model.json"));
|
||||
LiveBeansModel model = LiveBeansModel.parse(json);
|
||||
|
||||
LiveBean[] bean = model.getBeansOfType("org.test.DependencyA");
|
||||
assertEquals(0, bean.length);
|
||||
}
|
||||
|
||||
private InputStream getResourceAsStream(String string) {
|
||||
return LiveBeansModelTest.class.getResourceAsStream(string);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,9 +26,11 @@ import java.util.stream.Collectors;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.ide.vscode.commons.boot.app.cli.livebean.LiveBeansModel;
|
||||
import org.springframework.ide.vscode.commons.util.AsyncProcess;
|
||||
import org.springframework.ide.vscode.commons.util.ExceptionUtil;
|
||||
import org.springframework.ide.vscode.commons.util.ExternalCommand;
|
||||
@@ -37,11 +39,8 @@ import org.springframework.ide.vscode.commons.util.test.ACondition;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
public class SpringBootAppTest {
|
||||
|
||||
// private static final String appName = "actuator-client-15-test-subject"; // Boot 1.5 test app
|
||||
private static final String[] appNames = {
|
||||
"actuator-client-20-test-subject", //Boot 2.0 test app
|
||||
"actuator-client-20-thin-test-subject", // Like the Boot 2.0 app, but packaged with thin launcher instead of fatjar
|
||||
@@ -59,7 +58,7 @@ public class SpringBootAppTest {
|
||||
public static void setupClass() throws Exception {
|
||||
testAppRunners = Arrays.asList(appNames).stream().map(appName -> {
|
||||
try {
|
||||
return startTestApplication(SpringBootAppTest.class.getResource("/"+appName+"-0.0.1-SNAPSHOT.jar"));
|
||||
return startTestApplication(SpringBootAppTest.class.getResource("/boot-apps/"+appName+"-0.0.1-SNAPSHOT.jar"));
|
||||
} catch (Exception e) {
|
||||
throw ExceptionUtil.unchecked(e);
|
||||
}
|
||||
@@ -141,6 +140,12 @@ public class SpringBootAppTest {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void ensureTestAppsAvailable() throws Exception {
|
||||
//To avoid race condition when JMX connector fails if trying to attach to quickly after starting apps
|
||||
ACondition.waitFor(TIMEOUT, () -> getTestApps());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHost() throws Exception {
|
||||
for (SpringBootApp testApp : getTestApps()) {
|
||||
@@ -169,8 +174,8 @@ public class SpringBootAppTest {
|
||||
for (SpringBootApp testApp : getTestApps()) {
|
||||
try {
|
||||
ACondition.waitFor(TIMEOUT, () -> {
|
||||
String beans = testApp.getBeans();
|
||||
assertNonEmptyJsonObject(beans);
|
||||
LiveBeansModel beansModel = testApp.getBeans();
|
||||
assertTrue(beansModel.getAllBeans().findAny().isPresent());
|
||||
// System.out.println("beans = "+beans);
|
||||
});
|
||||
} catch (Throwable e) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.eclipse.lsp4j.TextDocumentIdentifier;
|
||||
import org.springframework.ide.vscode.commons.java.IJavaProject;
|
||||
|
||||
/**
|
||||
* Composite project manager that acts a single project manager but consissts of many project managers
|
||||
* Composite project manager that acts a single project manager but consists of many project managers
|
||||
*
|
||||
* @author Alex Boyko
|
||||
*
|
||||
|
||||
@@ -85,6 +85,7 @@
|
||||
<reactor-version>3.0.5.RELEASE</reactor-version>
|
||||
<reactor-netty>0.6.0.RELEASE</reactor-netty>
|
||||
<cloudfoundry-client-version>2.4.0.RELEASE</cloudfoundry-client-version>
|
||||
<commons-io-version>2.4</commons-io-version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
|
||||
Reference in New Issue
Block a user