Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions step-ap-ide/src/main/java/step/ap_ide/StepUp.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.Properties;

Expand All @@ -40,7 +39,7 @@ public static void main(String[] args) throws Exception {
configuration.getUnderlyingPropertyObject().load(propsStream);
new ControllerServer(configuration).start();
initWorkdir();
FXApp.main(args); // this will never return
//FXApp.main(args); // this will never return*/
}

private static final JavaAutomationPackageReader READER;
Expand Down Expand Up @@ -79,18 +78,18 @@ static void useAutomationPackageDirectory(File apDir) throws Exception {
var fragmentManager = StepUp.READER.getAutomationPackageYamlFragmentManager(apDir);
Properties properties = new Properties();

int variant = 1;
// variant 1:
// parameters all go into parameters.yml, plans go into separate files in plans/$PLAN_NAME.yml
// Only works if the target files/directories already exist, so disabled for now
if (1 == 0) {
// this is because parameters do not have unique names by design.
if (variant == 1) {
properties.setProperty(String.format(AutomationPackageYamlFragmentManager.PROPERTY_NEW_OBJECT_FRAGMENT_MODE, Parameter.ENTITY_NAME), AutomationPackageYamlFragmentManager.NewObjectFragmentMode.FRAGMENT.name());
properties.setProperty(String.format(AutomationPackageYamlFragmentManager.PROPERTY_NEW_OBJECT_FRAGMENT_PATH, Parameter.ENTITY_NAME), "parameters.yml");
properties.setProperty(String.format(AutomationPackageYamlFragmentManager.PROPERTY_NEW_OBJECT_FRAGMENT_MODE, YamlPlan.PLANS_ENTITY_NAME), AutomationPackageYamlFragmentManager.NewObjectFragmentMode.PER_OBJECT.name());
// keywords seem to use PER_OBJECT by default?
// per default, PER_OBJECT is used on all objects?
}
// variant 2: simple, everything goes into main descriptor
if (1 == 1) {
String mainFile = Paths.get(fragmentManager.descriptorYaml.getFragmentUrl().toURI()).toFile().getName();
if (variant == 2) {
String mainFile = fragmentManager.descriptorYaml.getFragmentPath().toFile().getName();
properties.setProperty(String.format(AutomationPackageYamlFragmentManager.PROPERTY_NEW_OBJECT_FRAGMENT_MODE, Parameter.ENTITY_NAME), AutomationPackageYamlFragmentManager.NewObjectFragmentMode.FRAGMENT.name());
properties.setProperty(String.format(AutomationPackageYamlFragmentManager.PROPERTY_NEW_OBJECT_FRAGMENT_PATH, Parameter.ENTITY_NAME), mainFile);
properties.setProperty(String.format(AutomationPackageYamlFragmentManager.PROPERTY_NEW_OBJECT_FRAGMENT_MODE, YamlPlan.PLANS_ENTITY_NAME), AutomationPackageYamlFragmentManager.NewObjectFragmentMode.FRAGMENT.name());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" ?>
<jmeterTestPlan version="1.2" properties="5.0" jmeter="5.4.1">

</jmeterTestPlan>
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AutomationPackageFunctionCollection extends InMemoryCollection<Func
private final AutomationPackageYamlFragmentManager fragmentManager;

public AutomationPackageFunctionCollection(AutomationPackageYamlFragmentManager fragmentManager) {
super(true, YamlAutomationPackageKeyword.KEYWORDS_ENTITY_NAME);
super(false, YamlAutomationPackageKeyword.KEYWORDS_ENTITY_NAME);
this.fragmentManager = fragmentManager;
initialzeRecordsFromFragments(fragmentManager);
}
Expand All @@ -41,7 +41,7 @@ private void initialzeRecordsFromFragments(AutomationPackageYamlFragmentManager

@Override
public Function save(Function p) {
return super.save(fragmentManager.saveFunction(p));
return fragmentManager.saveFunction(super.save(p));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AutomationPackageParameterCollection extends InMemoryCollection<Par
private final AutomationPackageYamlFragmentManager fragmentManager;

public AutomationPackageParameterCollection(AutomationPackageYamlFragmentManager fragmentManager) {
super(true, Parameter.ENTITY_NAME);
super(false, Parameter.ENTITY_NAME);
this.fragmentManager = fragmentManager;
initialzeRecordsFromFragments(fragmentManager);
}
Expand All @@ -41,7 +41,7 @@ private void initialzeRecordsFromFragments(AutomationPackageYamlFragmentManager

@Override
public Parameter save(Parameter parameter) {
return super.save(fragmentManager.saveAdditionalFieldObject(parameter, context -> AutomationPackageParameter.forContext(context, parameter), Parameter.ENTITY_NAME));
return fragmentManager.saveAdditionalFieldObject(super.save(parameter), AutomationPackageParameter.fromParameter(parameter), Parameter.ENTITY_NAME);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AutomationPackagePlanCollection extends InMemoryCollection<Plan> im
private final AutomationPackageYamlFragmentManager fragmentManager;

public AutomationPackagePlanCollection(AutomationPackageYamlFragmentManager fragmentManager) {
super(true, YamlPlan.PLANS_ENTITY_NAME);
super(false, YamlPlan.PLANS_ENTITY_NAME);
this.fragmentManager = fragmentManager;
initialzeRecordsFromFragments(fragmentManager);
}
Expand All @@ -41,7 +41,7 @@ private void initialzeRecordsFromFragments(AutomationPackageYamlFragmentManager

@Override
public Plan save(Plan p) {
return super.save(fragmentManager.savePlan(p));
return fragmentManager.savePlan(super.save(p));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,13 @@ protected void assertFilesEqual(Path expected, Path actual) throws IOException {
}

protected void setPropertiesWriteToFragment(String entityName, String fragment) {
setPropertiesWriteMode(entityName, fragment, AutomationPackageYamlFragmentManager.NewObjectFragmentMode.FRAGMENT);
}

protected void setPropertiesWriteMode(String entityName, String path, AutomationPackageYamlFragmentManager.NewObjectFragmentMode mode) {
Properties properties = new Properties();
properties.setProperty(String.format(AutomationPackageYamlFragmentManager.PROPERTY_NEW_OBJECT_FRAGMENT_PATH, entityName), fragment);
properties.setProperty(String.format(AutomationPackageYamlFragmentManager.PROPERTY_NEW_OBJECT_FRAGMENT_MODE, entityName), AutomationPackageYamlFragmentManager.NewObjectFragmentMode.FRAGMENT.name());
properties.setProperty(String.format(AutomationPackageYamlFragmentManager.PROPERTY_NEW_OBJECT_FRAGMENT_PATH, entityName), path);
properties.setProperty(String.format(AutomationPackageYamlFragmentManager.PROPERTY_NEW_OBJECT_FRAGMENT_MODE, entityName), mode.name());

fragmentManager.setProperties(properties);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,259 @@
/*******************************************************************************
* Copyright (C) 2026, exense GmbH
*
* This file is part of STEP
*
* STEP is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* STEP is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with STEP. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package step.core.collections;

import org.junit.Before;
import org.junit.Test;
import step.artefacts.Echo;
import step.artefacts.Sequence;
import step.automation.packages.AutomationPackageReadingException;
import step.automation.packages.model.YamlAutomationPackageKeyword;
import step.automation.packages.yaml.AutomationPackageYamlFragmentManager;
import step.core.artefacts.AbstractArtefact;
import step.core.dynamicbeans.DynamicValue;
import step.core.plans.Plan;
import step.functions.Function;
import step.plans.parser.yaml.YamlPlan;
import step.plugins.functions.types.CompositeFunction;

import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import static org.junit.Assert.assertFalse;

public class AutomationPackageFragmentReferenceTest extends AutomationPackageCollectionTestBase {

private Collection<Function> functionCollection;
private Collection<Plan> planCollection;

public AutomationPackageFragmentReferenceTest() {
super();
}

@Before
public void setUp() throws IOException, AutomationPackageReadingException {
super.setUp();
AutomationPackageCollectionFactory collectionFactory = new AutomationPackageCollectionFactory(new Properties(), fragmentManager);
planCollection = collectionFactory.getCollection(YamlPlan.PLANS_ENTITY_NAME, Plan.class);
functionCollection = collectionFactory.getCollection(YamlAutomationPackageKeyword.KEYWORDS_ENTITY_NAME, Function.class);
}


@Test
public void testAddCompositeKeywordToNewFragmentAndRenameAndRemove() throws IOException {

Sequence sequence = new Sequence();
Echo echo = new Echo();
echo.setText(new DynamicValue<>("Hello World"));
sequence.addChild(echo);

Plan plan = new Plan(sequence);

CompositeFunction function = new CompositeFunction();
function.setPlan(plan);

Map<String, String> attributes = new HashMap<>();
attributes.put(AbstractArtefact.NAME, "Hello World Composite Function");
function.setAttributes(attributes);

setPropertiesWriteMode(YamlAutomationPackageKeyword.KEYWORDS_ENTITY_NAME, "newKeywordsPath", AutomationPackageYamlFragmentManager.NewObjectFragmentMode.PER_OBJECT);

functionCollection.save(function);

assertFilesEqual(
expectedFilesPath
.resolve("Hello World Composite Function.yml"),
destinationDirectory.toPath()
.resolve("newKeywordsPath")
.resolve("Hello World Composite Function.yml")
);
assertFilesEqual(
expectedFilesPath
.resolve("descriptorAfterNewKeywordsFragmentReference.yml"),
destinationDirectory.toPath()
.resolve("automation-package.yml")
);

attributes.put(AbstractArtefact.NAME, "This Keyword was renamed");

functionCollection.save(function);

assertFilesEqual(
expectedFilesPath
.resolve("This Keyword was renamed.yml"),
destinationDirectory.toPath()
.resolve("newKeywordsPath")
.resolve("This Keyword was renamed.yml")
);

assertFilesEqual(
expectedFilesPath
.resolve("descriptorAfterNewKeywordsFragmentReference.yml"),
destinationDirectory.toPath()
.resolve("automation-package.yml"));

functionCollection.remove(Filters.equals("attributes.name", "This Keyword was renamed"));

assertFalse(Files.exists(
destinationDirectory.toPath()
.resolve("newKeywordsPath")
.resolve("This Keyword was renamed.yml")
));

assertFilesEqual(
expectedFilesPath
.resolve("descriptorAfterNewKeywordsFragmentReference.yml"),
destinationDirectory.toPath()
.resolve("automation-package.yml"));
}

@Test
public void testAddPlanToNewFragmentAndRenameAndRemove() throws IOException {

Sequence sequence = new Sequence();
Echo echo = new Echo();
echo.setText(new DynamicValue<>("Hello World"));
sequence.addChild(echo);

Plan plan = new Plan(sequence);
Map<String, String> attributes = new HashMap<>();
attributes.put(AbstractArtefact.NAME, "Hello World Plan");
plan.setAttributes(attributes);

setPropertiesWriteMode(YamlPlan.PLANS_ENTITY_NAME, "newPlansPath", AutomationPackageYamlFragmentManager.NewObjectFragmentMode.PER_OBJECT);

planCollection.save(plan);

assertFilesEqual(
expectedFilesPath
.resolve("Hello World Plan.yml"),
destinationDirectory.toPath()
.resolve("newPlansPath")
.resolve("Hello World Plan.yml")
);
assertFilesEqual(
expectedFilesPath
.resolve("descriptorAfterNewPlansFragmentReference.yml"),
destinationDirectory.toPath()
.resolve("automation-package.yml")
);

attributes.put(AbstractArtefact.NAME, "This Plan was renamed");

planCollection.save(plan);

assertFilesEqual(
expectedFilesPath
.resolve("This Plan was renamed.yml"),
destinationDirectory.toPath()
.resolve("newPlansPath")
.resolve("This Plan was renamed.yml")
);

assertFilesEqual(
expectedFilesPath
.resolve("descriptorAfterNewPlansFragmentReference.yml"),
destinationDirectory.toPath()
.resolve("automation-package.yml"));

planCollection.remove(Filters.equals("attributes.name", "This Plan was renamed"));

assertFalse(Files.exists(
destinationDirectory.toPath()
.resolve("newPlansPath")
.resolve("This Plan was renamed.yml")
));

assertFilesEqual(
expectedFilesPath
.resolve("descriptorAfterNewPlansFragmentReference.yml"),
destinationDirectory.toPath()
.resolve("automation-package.yml"));
}

@Test
public void testAddTwoPlansToNewFragmentAndRemoveOne() throws IOException {

Sequence sequence = new Sequence();
Echo echo = new Echo();
echo.setText(new DynamicValue<>("Hello World"));
sequence.addChild(echo);

Plan plan = new Plan(sequence);
Map<String, String> attributes = new HashMap<>();
attributes.put(AbstractArtefact.NAME, "Hello World Plan");
plan.setAttributes(attributes);

setPropertiesWriteMode(YamlPlan.PLANS_ENTITY_NAME, "newPlansPath", AutomationPackageYamlFragmentManager.NewObjectFragmentMode.PER_OBJECT);

planCollection.save(plan);

assertFilesEqual(
expectedFilesPath
.resolve("Hello World Plan.yml"),
destinationDirectory.toPath()
.resolve("newPlansPath")
.resolve("Hello World Plan.yml")
);
assertFilesEqual(
expectedFilesPath
.resolve("descriptorAfterNewPlansFragmentReference.yml"),
destinationDirectory.toPath()
.resolve("automation-package.yml")
);

Plan plan2 = new Plan(sequence);
Map<String, String> attributes2 = new HashMap<>();
attributes2.put(AbstractArtefact.NAME, "This Plan was renamed");
plan2.setAttributes(attributes2);

planCollection.save(plan2);

assertFilesEqual(
expectedFilesPath
.resolve("This Plan was renamed.yml"),
destinationDirectory.toPath()
.resolve("newPlansPath")
.resolve("This Plan was renamed.yml")
);

assertFilesEqual(
expectedFilesPath
.resolve("descriptorAfterNewPlansFragmentReference.yml"),
destinationDirectory.toPath()
.resolve("automation-package.yml"));

planCollection.remove(Filters.equals("attributes.name", "Hello World Plan"));

assertFalse(Files.exists(
destinationDirectory.toPath()
.resolve("newPlansPath")
.resolve("Hello World Plan.yml")
));

assertFilesEqual(
expectedFilesPath
.resolve("descriptorAfterNewPlansFragmentReference.yml"),
destinationDirectory.toPath()
.resolve("automation-package.yml"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,18 @@ public void testModifyCompositeKeyword() throws IOException {
assertFilesEqual(expectedFilesPath.resolve("keywordsAfterCompositeModification.yml"), destinationDirectory.toPath().resolve("keywords.yml"));
}

@Test
public void testRenameCompositeKeyword() throws IOException {
Optional<Function> optionalFunction = functionCollection.find(Filters.equals("attributes.name", "Composite keyword from AP"), null, null, null, 100).findFirst();
assertTrue(optionalFunction.isPresent());

CompositeFunction compositeFunction = (CompositeFunction) optionalFunction.get();

compositeFunction.getAttributes().put(AbstractOrganizableObject.NAME, "Renamed Composite Keyword");

functionCollection.save(compositeFunction);

assertFilesEqual(expectedFilesPath.resolve("keywordsAfterCompositeRenamed.yml"), destinationDirectory.toPath().resolve("keywords.yml"));
}

}
Loading