Skip to content

Commit

Permalink
#1509 Ignore extractTemplatesWithOldCinfiguration (#1536)
Browse files Browse the repository at this point in the history
* #1509 Ignore extractTemplatesWithOldCinfiguration
Fixed CLI adaptTemplatesTest
Fixed Eclipse testAdaptTemplates
Deleted generation from Eclipse Test

* removed exception that was used to differenciate between test and production and added an argument instead.

* #1509 Enabled extractTemplatesWithOldConfiguration

* #1509 Implemented requested changes

* #1509 Implemented requested changes

Co-authored-by: LarsReinken <[email protected]>
  • Loading branch information
mdukhan and LarsReinken authored Jun 7, 2022
1 parent 6c61401 commit 882013e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.nio.file.Path;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import com.devonfw.cobigen.api.constants.ConfigurationConstants;
Expand Down Expand Up @@ -48,12 +47,12 @@ public void initAdaptTemplatesTest() throws URISyntaxException, IOException {
*
* @throws Exception test fails
*/
@Ignore
@Test
public void adaptTemplatesTest() throws Exception {

String args[] = new String[1];
String args[] = new String[2];
args[0] = "adapt-templates";
args[1] = "--all";

execute(args, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.devonfw.cobigen.impl.adapter.TemplateAdapterImpl;

import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

/**
* This class handles the user defined template directory e.g. determining and obtaining the latest templates jar,
Expand All @@ -30,6 +31,12 @@ public class AdaptTemplatesCommand extends CommandCommons {
*/
private static Logger LOG = LoggerFactory.getLogger(CobiGenCLI.class);

/**
* If this options is enabled, all templates are extracted.
*/
@Option(names = { "--all" }, description = MessagesConstants.ADAPT_ALL_DESCRIPTION)
boolean adaptAll;

@Override
public Integer doAction() throws Exception {

Expand Down Expand Up @@ -74,8 +81,13 @@ private List<Path> getJarsToAdapt(TemplateAdapter templateAdapter, List<Path> te
printJarsForSelection(templateAdapter, templateJars);

List<String> userSelection = new ArrayList<>();
for (String templateSelection : ValidationUtils.getUserInput().split(",")) {
userSelection.add(templateSelection);

if (this.adaptAll) {
userSelection.add("0");
} else {
for (String templateSelection : ValidationUtils.getUserInput().split(",")) {
userSelection.add(templateSelection);
}
}

if (userSelection.contains("0")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public class MessagesConstants {
*/
public static final String ADAPT_TEMPLATES_DESCRIPTION = "Generates a new templates folder next to the cobigen cli";

/**
* Message constant: description of the adapt-templates --all command
*/
public static final String ADAPT_ALL_DESCRIPTION = "If this option is enabled, all templates will get adapted.";

/**
* Message constant: description of the custom-location option
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.io.File;

import org.apache.commons.io.FileUtils;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
Expand All @@ -16,11 +15,11 @@
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;

import com.devonfw.cobigen.api.constants.ConfigurationConstants;
import com.devonfw.cobigen.eclipse.common.constants.external.ResourceConstants;
import com.devonfw.cobigen.eclipse.test.common.SystemTest;
import com.devonfw.cobigen.eclipse.test.common.swtbot.AllJobsAreFinished;
Expand Down Expand Up @@ -52,6 +51,7 @@ public class AdaptTemplatesTest extends SystemTest {
public static void setupClass() throws Exception {

EclipseUtils.cleanWorkspace(bot, true);

}

/**
Expand Down Expand Up @@ -80,31 +80,24 @@ public void testBasicOpenAPIGenerationWithAdaptTemplates() throws Exception {
SWTBotTreeItem javaClassItem = view.bot().tree().expandNode(testProjName, "adapt-templates.yml");
javaClassItem.select();

// execute CobiGen
EclipseCobiGenUtils.processCobiGen(bot, javaClassItem, 25000, "CRUD devon4j Server>CRUD REST services");
bot.waitUntil(new AllJobsAreFinished(), 10000);
// increase timeout as the openAPI parser is slow on initialization
EclipseCobiGenUtils.confirmSuccessfullGeneration(bot, 40000);

bot.waitUntil(new AllJobsAreFinished(), 10000);
IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(testProjName);
IFile generationResult = proj.getFile(
"src/main/java/com/devonfw/test/sampledatamanagement/service/impl/rest/SampledatamanagementRestServiceImpl.java");
String Cobigen_templates = ConfigurationConstants.COBIGEN_TEMPLATES;
IProject adaptedTemplatesProj = ResourcesPlugin.getWorkspace().getRoot().getProject(Cobigen_templates);

assertThat(generationResult.exists()).isTrue();
assertThat(adaptedTemplatesProj.exists()).isTrue();
}

/**
* Test of testBasicOpenAPIGenerationWithAdaptTemplates with custom COBIGEN_HOME environment variable
*
* @throws Exception test fails
*/
@Ignore
@Test
public void testAdaptTemplatesAndGenerate() throws Exception {
public void testAdaptTemplates() throws Exception {

File tmpProject = this.tempFolder.newFolder("playground", "project", "templates");

File tmpProject = this.tempFolder.newFolder("playground", "project");
withEnvironmentVariable("COBIGEN_HOME", tmpProject.toPath().toString())
withEnvironmentVariable(ConfigurationConstants.CONFIG_ENV_HOME, tmpProject.getParentFile().getAbsolutePath())
.execute(() -> testBasicOpenAPIGenerationWithAdaptTemplates());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ public static void runAndCaptureAdaptTemplates(SWTWorkbenchBot bot) throws Excep

takeScreenshot(bot, "Adapt Templates Warning!");
SWTBotShell warningDialog = bot.shell("Warning!");

warningDialog.bot().button("Ok").click();

takeScreenshot(bot, "Create new POM!");
SWTBotShell finishDialog = bot.shell("Create new POM");
finishDialog.bot().button("Finish").click();

SWTBotShell informationDialog = bot.shell("Information");
bot.waitUntil(new AnyShellIsActive("Information"), DEFAULT_TIMEOUT);
takeScreenshot(bot, "Adapt Templates Information");
Expand Down

0 comments on commit 882013e

Please sign in to comment.