Skip to content

Commit

Permalink
Merge pull request #95 from MicroFocus/dmoldoveanu_defect_1077071_wro…
Browse files Browse the repository at this point in the history
…ng_script_name

defect #1077071: Fix wrong BDD scenario file name
  • Loading branch information
pikachugb authored Sep 10, 2020
2 parents cbdb6be + 5952acd commit 3459c6b
Showing 1 changed file with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.charset.StandardCharsets;
import java.util.Collections;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
Expand Down Expand Up @@ -34,23 +35,38 @@
import org.eclipse.ui.internal.registry.EditorDescriptor;
import org.eclipse.ui.internal.registry.EditorRegistry;
import org.eclipse.ui.internal.registry.FileEditorMapping;
import org.jsoup.Jsoup;

import com.hpe.adm.nga.sdk.model.EntityModel;
import com.hpe.adm.octane.ideplugins.services.EntityService;
import com.hpe.adm.octane.ideplugins.services.filtering.Entity;
import com.hpe.adm.octane.ideplugins.services.nonentity.DownloadScriptService;
import com.hpe.adm.octane.ideplugins.services.util.Util;
import com.hpe.octane.ideplugins.eclipse.Activator;

public class DownloadScriptUtil {

private static DownloadScriptService scriptService = Activator.getInstance(DownloadScriptService.class);
private static EntityService entityService = Activator.getInstance(EntityService.class);

public void downloadScriptForTest(EntityModel entityModel, Menu menu) {
File parentFolder = chooseParentFolder();

if (parentFolder != null) {
long testId = Long.parseLong(entityModel.getValue("id").getValue().toString());
String testName = entityModel.getValue("name").getValue().toString();
String scriptFileName = testName + "-" +
testId + ".feature";
long testId = Long.parseLong(entityModel.getValue("id").getValue().toString());
String testName, scriptFileName;

if(Entity.getEntityType(entityModel) == Entity.BDD_SCENARIO) {
EntityModel bddScenario = entityService.findEntity(Entity.BDD_SCENARIO, testId, Collections.singleton("bdd_spec"));
testName = Util.getUiDataFromModel(bddScenario.getValue("bdd_spec"));
String bddSpecId = Util.getUiDataFromModel(bddScenario.getValue("bdd_spec"), "id");
scriptFileName = testName + "_" + bddSpecId + ".feature";
} else {
testName = entityModel.getValue("name").getValue().toString();
testName = removeHtmlTags(testName);
scriptFileName = testName + "_" + testId + ".feature";
}

File scriptFile = new File(parentFolder.getPath() + File.separator +
scriptFileName);
boolean shouldDownloadScript = true;
Expand Down Expand Up @@ -152,4 +168,8 @@ private File createTestScriptFile(String path, String fileName, String script) {
}
return f;
}

private String removeHtmlTags(String testName) {
return Jsoup.parse(testName).text();
}
}

0 comments on commit 3459c6b

Please sign in to comment.