Skip to content

Commit dd6ad97

Browse files
authored
Merge pull request #90 from eharris369/89-updateProjectCreateInTests
Issue #89: Use new project create API for tests if available
2 parents 267a5e0 + 9af32d2 commit dd6ad97

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/console/ProjectTemplateInfo.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,9 @@ private String getString(String key) {
5959
return value;
6060
}
6161

62+
@Override
63+
public String toString() {
64+
return projectInfo.toString();
65+
}
66+
6267
}

dev/com.ibm.microclimate.core/src/com/ibm/microclimate/core/internal/constants/ProjectType.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2018 IBM Corporation and others.
2+
* Copyright (c) 2018, 2019 IBM Corporation and others.
33
* All rights reserved. This program and the accompanying materials
44
* are made available under the terms of the Eclipse Public License v2.0
55
* which accompanies this distribution, and is available at
@@ -47,4 +47,9 @@ public boolean isLanguage(String language) {
4747
return language != null && language.equals(this.language);
4848
}
4949

50+
@Override
51+
public String toString() {
52+
return ("Project type: " + type + ", project language: " + language);
53+
}
54+
5055
}

dev/com.ibm.microclimate.test/src/com/ibm/microclimate/test/BaseTest.java

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111

1212
package com.ibm.microclimate.test;
1313

14+
import java.io.IOException;
1415
import java.net.URI;
1516
import java.net.URL;
1617
import java.util.HashSet;
18+
import java.util.List;
1719
import java.util.Set;
1820

1921
import org.eclipse.core.resources.IMarker;
@@ -31,6 +33,7 @@
3133
import org.eclipse.ui.console.IConsoleManager;
3234
import org.eclipse.ui.console.TextConsole;
3335
import org.eclipse.ui.ide.IDE;
36+
import org.json.JSONException;
3437

3538
import com.ibm.microclimate.core.internal.HttpUtil;
3639
import com.ibm.microclimate.core.internal.MCEclipseApplication;
@@ -39,6 +42,7 @@
3942
import com.ibm.microclimate.core.internal.connection.MicroclimateConnection;
4043
import com.ibm.microclimate.core.internal.connection.MicroclimateConnectionManager;
4144
import com.ibm.microclimate.core.internal.console.MicroclimateConsoleFactory;
45+
import com.ibm.microclimate.core.internal.console.ProjectTemplateInfo;
4246
import com.ibm.microclimate.core.internal.constants.AppState;
4347
import com.ibm.microclimate.core.internal.constants.MCConstants;
4448
import com.ibm.microclimate.core.internal.constants.ProjectType;
@@ -76,7 +80,7 @@ public void doSetup() throws Exception {
7680
MicroclimateConnectionManager.add(connection);
7781

7882
// Create a new microprofile project
79-
connection.requestProjectCreate(projectType, projectName);
83+
createProject(projectType, projectName);
8084

8185
// Wait for the project to be created
8286
assertTrue("The application " + projectName + " should be created", MicroclimateUtil.waitForProject(connection, projectName, 300, 5));
@@ -238,5 +242,34 @@ public static Boolean setWorkspaceAutoBuild(boolean enabled) {
238242
}
239243
return null;
240244
}
245+
246+
protected void createProject(ProjectType type, String name) throws IOException, JSONException {
247+
if (connection.checkVersion(1905, "2019_M5_E")) {
248+
ProjectTemplateInfo templateInfo = null;
249+
List<ProjectTemplateInfo> templates = connection.requestProjectTemplates();
250+
for (ProjectTemplateInfo template : templates) {
251+
if (type.language.equals(template.getLanguage())) {
252+
if (type.isLanguage(ProjectType.LANGUAGE_JAVA)) {
253+
String extension = template.getExtension();
254+
if (type.isType(ProjectType.TYPE_LIBERTY) && extension.toLowerCase().contains("microprofile")) {
255+
templateInfo = template;
256+
break;
257+
}
258+
if (type.isType(ProjectType.TYPE_SPRING) && extension.toLowerCase().contains("spring")) {
259+
templateInfo = template;
260+
break;
261+
}
262+
} else {
263+
templateInfo = template;
264+
break;
265+
}
266+
}
267+
}
268+
assertNotNull("No template found that matches the project type: " + projectType, templateInfo);
269+
connection.requestProjectCreate(templateInfo, name);
270+
} else {
271+
connection.requestProjectCreate(projectType, projectName);
272+
}
273+
}
241274

242275
}

0 commit comments

Comments
 (0)