Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 1 addition & 2 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 Down Expand Up @@ -90,7 +89,7 @@ static void useAutomationPackageDirectory(File apDir) throws Exception {
}
// variant 2: simple, everything goes into main descriptor
if (1 == 1) {
String mainFile = Paths.get(fragmentManager.descriptorYaml.getFragmentUrl().toURI()).toFile().getName();
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 @@ -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 super.save(fragmentManager.saveAdditionalFieldObject(parameter, AutomationPackageParameter.fromParameter(parameter), Parameter.ENTITY_NAME));
}

@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,84 @@
/*******************************************************************************
* 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.yaml.AutomationPackageYamlFragmentManager;
import step.core.artefacts.AbstractArtefact;
import step.core.dynamicbeans.DynamicValue;
import step.core.plans.Plan;
import step.core.yaml.deserialization.AutomationPackageConcurrentEditException;
import step.plans.parser.yaml.YamlPlan;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.*;
import java.util.stream.Collectors;

import static org.junit.Assert.*;

public class AutomationPackageFragmentReferenceTest extends AutomationPackageCollectionTestBase {

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);
}


@Test
public void testAddPlanToNewFragmentAndRename() 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("descriptorAfterNewFragmentReference.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("descriptorAfterNewFragmentReference.yml"), destinationDirectory.toPath().resolve("automation-package.yml"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public void testParameterModify() throws IOException {
Parameter parameter = optionalParameter.get();

parameter.getValue().setValue("myModifiedValue");

setPropertiesWriteToFragment(Parameter.ENTITY_NAME, "parameters.yml");

parameterCollection.save(parameter);

assertFilesEqual(expectedFilesPath.resolve("parametersAfterModification.yml"), destinationDirectory.toPath().resolve("parameters.yml"));
Expand All @@ -72,6 +75,7 @@ public void testParameterAddAndModify() throws IOException {


setPropertiesWriteToFragment(Parameter.ENTITY_NAME, "parameters.yml");
parameter.setPriority(1);
parameterCollection.save(parameter);

assertFilesEqual(expectedFilesPath.resolve("parametersAfterAdd.yml"), destinationDirectory.toPath().resolve("parameters.yml"));
Expand All @@ -80,6 +84,7 @@ public void testParameterAddAndModify() throws IOException {
parameterCollection.save(parameter);

parameter.setValue(new DynamicValue<>("foo"));
parameter.setPriority(null);
parameterCollection.save(parameter);

assertFilesEqual(expectedFilesPath.resolve("parametersAfterAddAndModification.yml"), destinationDirectory.toPath().resolve("parameters.yml"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
plans:
- name: "This Plan was renamed"
root:
sequence:
children:
- echo:
text: "Hello World"
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
schemaVersion: 1.0.0
name: "My package"
alertingRules:
- name: "Rule1"
description: "My test alerting rule"
eventClass: ExecutionEndedEvent
conditions:
- BindingCondition:
description: "condition 1"
bindingKey: "myKey"
negate: false
predicate:
BindingValueEqualsPredicate:
value: "myValue"
plans: []
parameters:
- key: "paramInMainAP"
value: "once"
fragments:
- "keywords.yml"
- "plans/*.yml"
- "schedules.yml"
- "parameters.yml"
- "parameters2.yml"
- "unknown.yml"
- "newPlansPath/*.yml"
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ parameters:
- key: "addedParameter"
value: "test"
description: "This is an added Parameter before modification"
priority: 1
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import step.automation.packages.yaml.model.AutomationPackageFragmentYaml;
import step.core.plans.Plan;
import step.core.yaml.deserialization.PatchableYamlList;
import step.core.yaml.deserialization.PatchableYamlPrimitive;
import step.functions.Function;
import step.plans.automation.YamlPlainTextPlan;
import step.plans.nl.RootArtefactType;
Expand All @@ -42,13 +43,10 @@
import java.io.InputStream;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -130,7 +128,7 @@ protected AutomationPackageContent buildAutomationPackage(AutomationPackageDescr

// apply imported fragments recursively
if (descriptor != null) {
fillAutomationPackageWithImportedFragments(res, descriptor, archive, new HashMap<>());
fillAutomationPackageWithImportedFragments(res, descriptor, archive, new HashSet<>());
}
return res;
}
Expand Down Expand Up @@ -183,32 +181,32 @@ protected AutomationPackageContent newContentInstance() {

public AutomationPackageYamlFragmentManager getAutomationPackageYamlFragmentManager(T archive) throws AutomationPackageReadingException {
AutomationPackageDescriptorReader reader = getOrCreateDescriptorReader();
URL descriptorURL = archive.getDescriptorYamlUrl();
try (InputStream inputStream = descriptorURL.openStream()) {
URL descriptorUrl = archive.getDescriptorYamlUrl();
try (InputStream inputStream = descriptorUrl.openStream()) {
AutomationPackageDescriptorYaml descriptor = reader.readAutomationPackageDescriptor(inputStream, archive.getOriginalFileName());
descriptor.setFragmentUrl(descriptorURL);
descriptor.setFragmentPath(Path.of(descriptorUrl.getPath()));
AutomationPackageContent content = newContentInstance();
Map<String, AutomationPackageFragmentYaml> fragmentMap = new ConcurrentHashMap<>();
fillAutomationPackageWithImportedFragments(content, descriptor, archive, fragmentMap);
StagingAutomationPackageContext stagingContext = new StagingAutomationPackageContext(null, AutomationPackageOperationMode.LOCAL, new LocalResourceManagerImpl(Path.of(descriptorURL.getPath()).getParent().toFile()), archive, content, null, null, new HashMap<>());
return new AutomationPackageYamlFragmentManager(descriptor, fragmentMap, getOrCreateDescriptorReader(), stagingContext);
Set<AutomationPackageFragmentYaml> fragments = new HashSet<>();
fillAutomationPackageWithImportedFragments(content, descriptor, archive, fragments);
StagingAutomationPackageContext stagingContext = new StagingAutomationPackageContext(null, AutomationPackageOperationMode.LOCAL, new LocalResourceManagerImpl(Path.of(descriptorUrl.getPath()).getParent().toFile()), archive, content, null, null, new HashMap<>());
return new AutomationPackageYamlFragmentManager(descriptor, fragments, getOrCreateDescriptorReader(), stagingContext);
} catch (IOException e) {
Comment thread
cmisev marked this conversation as resolved.
throw new AutomationPackageReadingException("Failed to read automation package for editing", e);
}
}

private void fillAutomationPackageWithImportedFragments(AutomationPackageContent targetPackage, AutomationPackageFragmentYaml fragment, T archive, Map<String, AutomationPackageFragmentYaml> fragmentYamlMap) throws AutomationPackageReadingException {
private void fillAutomationPackageWithImportedFragments(AutomationPackageContent targetPackage, AutomationPackageFragmentYaml fragment, T archive, Set<AutomationPackageFragmentYaml> fragments) throws AutomationPackageReadingException {
Comment thread
cmisev marked this conversation as resolved.
fillContentSections(targetPackage, fragment, archive);

if (!fragment.getFragments().isEmpty()) {
for (String importedFragmentReference : fragment.getFragments()) {
List<URL> resources = archive.getResourcesByPattern(importedFragmentReference);
for (PatchableYamlPrimitive<String> importedFragmentReference : fragment.getFragments()) {
List<URL> resources = archive.getResourcesByPattern(importedFragmentReference.toString());
for (URL resource : resources) {
try (InputStream fragmentYamlStream = resource.openStream()) {
fragment = getOrCreateDescriptorReader().readAutomationPackageFragment(fragmentYamlStream, resource.toString(), archive.getAutomationPackageName());
fragmentYamlMap.put(resource.toString(), fragment);
fragment.setFragmentUrl(resource);
fillAutomationPackageWithImportedFragments(targetPackage, fragment, archive, fragmentYamlMap);
AutomationPackageFragmentYaml referencedFragment = getOrCreateDescriptorReader().readAutomationPackageFragment(fragmentYamlStream, resource.toString(), archive.getAutomationPackageName());
fragments.add(referencedFragment);
referencedFragment.setFragmentPath(Path.of(resource.getPath()));
fillAutomationPackageWithImportedFragments(targetPackage, referencedFragment, archive, fragments);
} catch (IOException e) {
throw new AutomationPackageReadingException("Unable to read fragment in automation package: " + importedFragmentReference, e);
}
Comment thread
cmisev marked this conversation as resolved.
Expand Down
Loading