mockedApps = new ArrayList<>();
-
- public MockRunningAppProvider() {
- try {
- when(provider.getAllRunningSpringApps()).thenReturn(mockedApps);
- } catch (Exception e) {
- throw ExceptionUtil.unchecked(e);
- }
- }
-
- /**
- * Reset the mocks. Use this if the default's programmed into the mocks don't
- * suite your test case.
- *
- * Note: you may also choose to call {@link Mockito}.mock directly if you do not
- * want to reset all of the mocks.
- */
- public void reset() throws Exception {
- mockedApps.clear();
- Mockito.reset(provider);
- }
-
- public MockAppBuilder builder() throws Exception {
- return new MockAppBuilder(this);
- }
-
- public static class MockAppBuilder {
- public final SpringBootApp app = mock(SpringBootApp.class);
- private MockRunningAppProvider runningAppProvider;
- private String processId;
- private String processName;
-
- public MockAppBuilder(MockRunningAppProvider runningAppProvider) throws Exception {
- this.runningAppProvider = runningAppProvider;
- when(app.getUrlScheme()).thenReturn("http");
- }
-
- public MockAppBuilder beans(String beans) throws Exception {
- return beans(LiveBeansModel.parse(beans));
- }
-
- public MockAppBuilder beans(LiveBeansModel beans) {
- when(app.getBeans()).thenReturn(beans);
- return this;
- }
-
- public MockAppBuilder processId(String processId) {
- this.processId = processId;
- when(app.getProcessID()).thenReturn(processId);
- return this;
- }
-
- public MockAppBuilder processName(String name) throws Exception {
- this.processName = name;
- when(app.getProcessName()).thenReturn(name);
- return this;
- }
-
- public MockAppBuilder contextPath(String contextPath) throws Exception {
- when(app.getContextPath()).thenReturn(contextPath);
- return this;
- }
-
- public MockAppBuilder contextPathEnvJson(String bootVersion, String envJson) throws Exception {
- String contextPath = LiveContextPathUtil.getContextPath(bootVersion, envJson);
- when(app.getContextPath()).thenReturn(contextPath);
- return this;
- }
-
- public MockAppBuilder port(String port) throws Exception {
- when(app.getPort()).thenReturn(port);
- return this;
- }
-
- public MockAppBuilder host(String host) throws Exception {
- when(app.getHost()).thenReturn(host);
- return this;
- }
-
- public MockAppBuilder urlScheme(String urlScheme) throws Exception {
- when(app.getUrlScheme()).thenReturn(urlScheme);
- return this;
- }
-
- public MockAppBuilder isSpringBootApp(boolean isBoot) throws Exception {
- when(app.hasUsefulJmxBeans()).thenReturn(isBoot);
- return this;
- }
-
- public MockAppBuilder requestMappingsJson(String mappings) throws Exception {
- Collection requestMappings = LocalSpringBootApp.parseRequestMappingsJson(mappings, "1.x");
- when(app.getRequestMappings()).thenReturn(requestMappings);
- return this;
- }
-
- public MockAppBuilder requestMappings(Collection rms) throws Exception {
- when(app.getRequestMappings()).thenReturn(rms);
- return this;
- }
-
- public MockAppBuilder liveConditionalsJson(String rawJson) throws Exception{
- when(app.getLiveConditionals()).thenReturn(LocalSpringBootApp.getLiveConditionals(rawJson, processId, processName));
- return this;
- }
-
- public MockAppBuilder livePropertiesJson(String envJson) throws Exception{
- when(app.getLiveProperties()).thenReturn(LivePropertiesJsonParser.parseProperties(envJson));
- 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
- */
- public void build() {
- runningAppProvider.mockedApps.add(app);
- }
-
- }
-}
diff --git a/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/project/harness/SpringProcessLiveDataBuilder.java b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/project/harness/SpringProcessLiveDataBuilder.java
new file mode 100644
index 000000000..2480989f7
--- /dev/null
+++ b/headless-services/spring-boot-language-server/src/test/java/org/springframework/ide/vscode/project/harness/SpringProcessLiveDataBuilder.java
@@ -0,0 +1,129 @@
+/*******************************************************************************
+ * Copyright (c) 2019 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
+ * https://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Pivotal, Inc. - initial API and implementation
+ *******************************************************************************/
+package org.springframework.ide.vscode.project.harness;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.json.JSONObject;
+import org.springframework.ide.vscode.boot.java.livehover.v2.LiveBeansModel;
+import org.springframework.ide.vscode.boot.java.livehover.v2.LiveConditional;
+import org.springframework.ide.vscode.boot.java.livehover.v2.LiveConditionalParser;
+import org.springframework.ide.vscode.boot.java.livehover.v2.LiveContextPathUtil;
+import org.springframework.ide.vscode.boot.java.livehover.v2.LiveProperties;
+import org.springframework.ide.vscode.boot.java.livehover.v2.LiveRequestMapping;
+import org.springframework.ide.vscode.boot.java.livehover.v2.LiveRequestMappingBoot1xRequestMapping;
+import org.springframework.ide.vscode.boot.java.livehover.v2.SpringProcessLiveData;
+
+/**
+ * @author Martin Lippert
+ */
+public class SpringProcessLiveDataBuilder {
+
+ private String processName;
+ private String processID;
+
+ private String contextPath;
+ private String urlScheme;
+ private String port;
+ private String host;
+
+ private LiveBeansModel beansModel;
+ private String[] activeProfiles;
+ private LiveRequestMapping[] requestMappings;
+ private LiveConditional[] conditionals;
+ private LiveProperties properties;
+
+ public SpringProcessLiveDataBuilder processName(String processName) {
+ this.processName = processName;
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder processID(String processID) {
+ this.processID = processID;
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder contextPath(String contextPath) {
+ this.contextPath = contextPath;
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder contextPathEnvJson(String bootVersion, String envJson) {
+ this.contextPath = LiveContextPathUtil.getContextPath(bootVersion, envJson);
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder urlScheme(String urlScheme) {
+ this.urlScheme = urlScheme;
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder port(String port) {
+ this.port = port;
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder host(String host) {
+ this.host = host;
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder beans(LiveBeansModel beansModel) {
+ this.beansModel = beansModel;
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder activeProfiles(String... activeProfiles) {
+ this.activeProfiles = activeProfiles;
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder requestMappings(LiveRequestMapping... requestMappings) {
+ this.requestMappings = requestMappings;
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder requestMappingsJson(String json) {
+ JSONObject obj = new JSONObject(json);
+
+ List result = new ArrayList<>();
+ Iterator keys = obj.keys();
+ while (keys.hasNext()) {
+ String rawKey = keys.next();
+ JSONObject value = obj.getJSONObject(rawKey);
+ result.add(new LiveRequestMappingBoot1xRequestMapping(rawKey, value));
+ }
+ this.requestMappings = result.toArray(new LiveRequestMapping[result.size()]);
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder liveConditionals(LiveConditional[] conditionals) {
+ this.conditionals = conditionals;
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder liveConditionalsJson(String json) {
+ this.conditionals = LiveConditionalParser.parse(json, processID, processName);
+ return this;
+ }
+
+ public SpringProcessLiveDataBuilder getLiveProperties(LiveProperties properties) {
+ this.properties = properties;
+ return this;
+ }
+
+ public SpringProcessLiveData build() {
+ return new SpringProcessLiveData(processName, processID, contextPath, urlScheme, port, host, beansModel, activeProfiles, requestMappings, conditionals, properties);
+ }
+
+}