Skip to content

Commit

Permalink
devonfw#1454 made test functional
Browse files Browse the repository at this point in the history
added logic to testTemplateSetNameIsShownCorrectly
removed template set install status next to install button
added updateTemplateSetInstallStatus method to DetailsController
  • Loading branch information
jan-vcapgemini committed Mar 3, 2023
1 parent 81175fd commit a410cdc
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ public void loadDetails() throws IOException {
this.detailsController
.setTemplateSet(this.menuController.searchResultsView.getSelectionModel().getSelectedItem());

// updates the install button text
this.detailsController.updateTemplateSetInstallStatus();

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ public class DetailsController implements Initializable {
@FXML
Text descriptionText;

@FXML
Text installStatusText;

@FXML
Button installButton;

Expand All @@ -64,6 +61,20 @@ public void initialize(URL location, ResourceBundle resources) {

}

/**
* Sets text of install button to Installed
*/
public void updateTemplateSetInstallStatus() {

Path templateSetPath = retrieveJarPathFromTemplateSet();
if (Files.exists(templateSetPath)) {
this.installButton.setText("Installed");
} else {
this.installButton.setText("Install");
}

}

/**
* returns an instance of selected template Set to be operated on
*
Expand Down Expand Up @@ -116,6 +127,26 @@ public void showTreeView(TreeView<String> treeView) {
this.treeViewPane.getChildren().add(treeView);
}

/**
* Retrieves the jar file path from the selected template set
*
* @return Path to template set jar
*/
private Path retrieveJarPathFromTemplateSet() {

// Retrieve template set name information from trigger
String triggerName = this.templateSet.getTemplateSetConfiguration().getContextConfiguration().getTriggers().getId();
String mavenArtfifactId = triggerName.replace("_", "-");
String templateSetVersion = this.templateSet.getTemplateSetVersion();
Path templateSetsPath = CobiGenPaths.getTemplateSetsFolderPath();

// Adjust file name
String FileName = mavenArtfifactId + "-" + templateSetVersion + ".jar";
Path jarFilePath = templateSetsPath.resolve(ConfigurationConstants.DOWNLOADED_FOLDER).resolve(FileName);

return jarFilePath;
}

/**
* Installs a template set into the template-sets/downloaded folder
*
Expand All @@ -132,20 +163,22 @@ public void installTemplateSet(javafx.event.ActionEvent actionEvent) {
// Adjust file name
String FileName = mavenArtfifactId + "-" + templateSetVersion + ".jar";

Path templateSetsPath = CobiGenPaths.getTemplateSetsFolderPath();

// prepare MavenCoordinate list for download
MavenCoordinate mavenCoordinate = new MavenCoordinate(
ConfigurationConstants.CONFIG_PROPERTY_TEMPLATE_SETS_DEFAULT_GROUPID, mavenArtfifactId, templateSetVersion);
List<MavenCoordinate> mavenCoordinateList = new ArrayList<>();
mavenCoordinateList.add(mavenCoordinate);

Path templateSetsPath = CobiGenPaths.getTemplateSetsFolderPath();

Path destinationFilePath = templateSetsPath.resolve(ConfigurationConstants.DOWNLOADED_FOLDER).resolve(FileName);
Path expectedJarFilePath = templateSetsPath.resolve(ConfigurationConstants.DOWNLOADED_FOLDER).resolve(FileName);

if (!Files.exists(destinationFilePath.resolve(FileName))) {
if (!Files.exists(expectedJarFilePath)) {
// Download template set class file into downloaded folder
TemplatesJarUtil.downloadTemplatesByMavenCoordinates(
templateSetsPath.resolve(ConfigurationConstants.DOWNLOADED_FOLDER), mavenCoordinateList);
// TODO: update installButton title to Installed and save this state
updateTemplateSetInstallStatus();
} else {
// Alert window if the file is already installed
Alert alert = new Alert(AlertType.CONFIRMATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,7 @@
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="100.0" prefWidth="160.0" SplitPane.resizableWithParent="false">
<children>
<Label fx:id="titleLabel" text="Template Set Title" AnchorPane.leftAnchor="10.0" AnchorPane.topAnchor="10.0" />
<AnchorPane layoutX="256.0" layoutY="13.0" prefHeight="25.0" prefWidth="100.0" AnchorPane.rightAnchor="70.0" AnchorPane.topAnchor="10.0">
<children>
<Text fx:id="installStatusText" fill="#949494c7" layoutX="9.0" layoutY="17.0" strokeType="OUTSIDE" strokeWidth="0.0" text="UNINSTALLED" textAlignment="CENTER">
<font>
<Font size="12.0" />
</font>
</Text>
</children>
</AnchorPane>
<AnchorPane layoutX="256.0" layoutY="13.0" prefHeight="25.0" prefWidth="100.0" AnchorPane.rightAnchor="70.0" AnchorPane.topAnchor="10.0" />
<Button fx:id="installButton" layoutX="367.0" layoutY="13.0" mnemonicParsing="false" onAction="#installTemplateSet" styleClass="menuButtons" text="Install" textFill="WHITE" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0">
<font>
<Font size="12.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;

import javafx.collections.FXCollections;
import javafx.scene.text.Text;
import javafx.scene.control.Button;

/**
* TODO
Expand All @@ -43,12 +43,12 @@ public void testGetAllTemplateSetsAdapted() throws Exception {

/**
* Tests if a selected template set can be installed (template-set class jar file gets added to
* template-sets/downloaded folder) and UNINSTALLED text changes to INSTALLED
* template-sets/downloaded folder) and the text of the install button changed from Install to Installed
*
* @throws Exception Test fails
*/
@Test
public void testGetAllTemplateSetsDownloaded() throws Exception {
public void testInstallTemplateSet() throws Exception {

// preparation
File userHome = this.tmpFolder.newFolder("UserHome");
Expand All @@ -70,7 +70,8 @@ public void testGetAllTemplateSetsDownloaded() throws Exception {

this.searchResultsView.setItems(this.templateSetObservableList);

Text installStatustext = find("#installStatusText");
Button installButton = find("#installButton");
String installButtonText = installButton.getText();

sleep(1000);

Expand All @@ -88,11 +89,16 @@ public void testGetAllTemplateSetsDownloaded() throws Exception {

assertThat(downloaded.toPath().resolve("crud-java-server-app-2021.12.007.jar")).exists();

assertThat(installStatustext.getText()).isEqualTo("INSTALLED");
assertThat(installButtonText).isEqualTo("Installed");
});

}

@Test
public void testGetAllTemplateSetsDownloaded() throws Exception {

}

@Test
public void testGetAllTemplateSetsInstalled() throws Exception {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,25 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.Test;

import com.devonfw.cobigen.retriever.reader.TemplateSetArtifactReader;
import com.devonfw.cobigen.retriever.reader.to.model.TemplateSet;

import javafx.collections.FXCollections;

/**
* TODO
*
*/
public class TemplateSetDetailsTest extends TestFXBase {

/** Test data root path */
private static final String testdataRoot = "src/test/resources/testdata/unittests/TemplateSetDetailsTest";

/**
*
*/
Expand All @@ -31,13 +42,29 @@ public void testVisibilityAfterSearchAndSelect() {
}

/**
*
*/
* Tests if a loaded template set is displaying the correct name in the list view
*/
@Test
public void testTemplateSetNameIsShownCorrectly() {

// TODO
assertThat(false).isTrue();
Path templateSetXmlFile = Paths.get(testdataRoot).resolve("template-set.xml");

// TODO replace with template set reader
TemplateSetArtifactReader artifactReader = new TemplateSetArtifactReader();

TemplateSet templateSet = artifactReader.retrieveTemplateSet(templateSetXmlFile);

// adds template set to GUI
this.templateSetObservableList = FXCollections.observableArrayList();
this.templateSetObservableList.addAll(templateSet);

this.searchResultsView.setItems(this.templateSetObservableList);

String triggerName = templateSet.getTemplateSetConfiguration().getContextConfiguration().getTriggers().getId();
String templateSetNameInMenu = this.searchResultsView.getItems().get(0).getTemplateSetConfiguration()
.getContextConfiguration().getTriggers().getId();

assertThat(templateSetNameInMenu).isEqualTo(triggerName);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<templateSetConfiguration xmlns="http://capgemini.com/devonfw/cobigen/TemplateSetConfiguration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="6.0">
<contextConfiguration>
<trigger id="crud_java_server_app" type="java">
<matcher type="fqn" value="*">
</matcher>
</trigger>

<tags>
<tag name="Tag1"></tag>
<tag name="Tag2"></tag>
</tags>
<links>
<link
url="https://docs.spring.io/spring-data/data-commons/docs/1.6.1.RELEASE/reference/html/repositories.html"></link>
</links>
</contextConfiguration>

<templatesConfiguration>
<templates>
<templateExtension ref="${variables.entityName}Entity.java" mergeStrategy="javamerge"/>
<templateExtension ref="${variables.entityName}.java" mergeStrategy="javamerge"/>
</templates>

<templateScans>
<templateScan templatePath="templates" destinationPath="src/main"/>
</templateScans>

<increments>
<increment name="inrement1" description="Description of increment 1"
explanation="Explanation of increment 1">
<templateRef ref="${variables.entityName}Repository.java"/>
</increment>
<increment name="inrement2" description="Description of increment 2"
explanation="Explanation of increment 2">
<templateRef ref="${variables.entityName}Repository.java"/>
</increment>
</increments>
</templatesConfiguration>
</templateSetConfiguration>

0 comments on commit a410cdc

Please sign in to comment.