First, simple implementation of active profiles hover

This commit is contained in:
Kris De Volder
2017-10-24 10:48:02 -07:00
parent b8aa5e484c
commit 5652e8402e
6 changed files with 264 additions and 11 deletions

View File

@@ -0,0 +1,109 @@
/*******************************************************************************
* Copyright (c) 2017 Pivotal, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Pivotal, Inc. - initial API and implementation
*******************************************************************************/
package org.springframework.ide.vscode.boot.java.profile;
import org.junit.Before;
import org.junit.Test;
import org.springframework.ide.vscode.commons.util.text.LanguageId;
import org.springframework.ide.vscode.languageserver.testharness.Editor;
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness;
import org.springframework.ide.vscode.project.harness.MockRunningAppProvider;
import org.springframework.ide.vscode.project.harness.ProjectsHarness;
public class ActiveProfilesHoverTest {
private BootLanguageServerHarness harness;
private ProjectsHarness projects = ProjectsHarness.INSTANCE;
private MockRunningAppProvider mockAppProvider;
@Before
public void setup() throws Exception {
mockAppProvider = new MockRunningAppProvider();
harness = BootLanguageServerHarness.builder()
.mockDefaults()
.runningAppProvider(mockAppProvider.provider)
.build();
harness.useProject(projects.mavenProject("empty-boot-15-web-app"));
harness.intialize(null);
}
@Test
public void testActiveProfileHover() throws Exception {
mockAppProvider.builder()
.isSpringBootApp(true)
.processId("22022")
.processName("foo.bar.RunningApp")
.profiles("testing-profile", "local-profile")
.build();
Editor editor = harness.newEditor(LanguageId.JAVA,
"package hello;\n" +
"\n" +
"import org.springframework.context.annotation.Configuration;\n" +
"import org.springframework.context.annotation.Profile;\n" +
"\n" +
"@Configuration\n" +
"@Profile(\"local\")\n" +
"public class LocalConfig {\n" +
"}"
);
editor.assertHoverContains("@Profile", "testing-profile");
editor.assertHoverContains("@Profile", "local-profile");
editor.assertHoverContains("@Profile", "foo.bar.RunningApp");
editor.assertHoverContains("@Profile", "22022");
}
@Test
public void testActiveProfileHover_Unknown() throws Exception {
//Sometimes its not possible to determine active profiles for an app (e.g. no actuator dependency).
//Make sure we show something sensible
mockAppProvider.builder()
.isSpringBootApp(true)
.processId("22022")
.processName("foo.bar.RunningApp")
.profilesUnknown()
.build();
Editor editor = harness.newEditor(LanguageId.JAVA,
"package hello;\n" +
"\n" +
"import org.springframework.context.annotation.Configuration;\n" +
"import org.springframework.context.annotation.Profile;\n" +
"\n" +
"@Configuration\n" +
"@Profile(\"local\")\n" +
"public class LocalConfig {\n" +
"\n" +
"}"
);
editor.assertHoverContains("@Profile", "Process [PID=22022, name=`foo.bar.RunningApp`] : _Unknown_");
}
@Test
public void testNoRunningApps() throws Exception {
Editor editor = harness.newEditor(LanguageId.JAVA,
"package hello;\n" +
"\n" +
"import org.springframework.context.annotation.Configuration;\n" +
"import org.springframework.context.annotation.Profile;\n" +
"\n" +
"@Configuration\n" +
"@Profile(\"local\")\n" +
"public class LocalConfig {\n" +
"\n" +
"}"
);
editor.assertNoHover("@Profile");
}
}

View File

@@ -20,6 +20,9 @@ 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.util.ExceptionUtil;
import org.springframework.ide.vscode.project.harness.BootLanguageServerHarness.Builder;
import com.google.common.collect.ImmutableList;
public class MockRunningAppProvider {
@@ -103,6 +106,20 @@ public class MockRunningAppProvider {
return this;
}
public MockAppBuilder profiles(String... names) {
when(app.getActiveProfiles()).thenReturn(ImmutableList.copyOf(names));
return this;
}
public MockAppBuilder profilesUnknown() {
//Note, technically, we don't have to program the mock for this case as it will return
// null by default. But it makes test code more readable. Also... how we represent the
// 'unknown' case may change in the future and having this method will help fix the tests.
when(app.getActiveProfiles()).thenReturn(null);
return this;
}
/**
* Builds the mock app and adds it to the app provider
*/