Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automation: apply object to object in order #5978

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions addOns/automation/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Method to allow the user to set the exit code via a script.

### Changed
- Maintenance changes.
- Updated automation framework documentation and templates for `activeScan` job to reflect changes to the default value of threadPerHost parameter
- Update help for the "requestor" job.
- Update help to indicate that job order is important (Issue 8675).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.EnumUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
Expand Down Expand Up @@ -352,7 +354,10 @@ public static void applyObjectToObject(
}

try {
Method[] methods = srcObject.getClass().getMethods();
Method[] methods =
Stream.of(srcObject.getClass().getMethods())
.sorted(Comparator.comparing(Method::getName))
.toArray(Method[]::new);
for (Method m : methods) {
String getterName = m.getName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import static org.hamcrest.Matchers.sameInstance;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
Expand All @@ -44,6 +45,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.InOrder;
import org.mockito.quality.Strictness;
import org.parosproxy.paros.Constant;
import org.parosproxy.paros.control.Control;
Expand Down Expand Up @@ -130,6 +132,22 @@ void shouldApplyObjectToObjectWhileIgnoringSpecifiedPropertyNames() {
assertThat(dest.isBool(), is(nullValue()));
}

@Test
void shouldApplyObjectToObjectInExpectedOrder() {
// Given
Data source = new Data("A", Boolean.TRUE);
Data dest = mock(Data.class);
InOrder inOrder = inOrder(dest);
AutomationProgress progress = mock(AutomationProgress.class);
AutomationEnvironment env = mock(AutomationEnvironment.class);
given(env.replaceVars(any())).willAnswer(invocation -> invocation.getArgument(0));
// When
JobUtils.applyObjectToObject(source, dest, "name", new String[] {}, progress, env);
// Then
inOrder.verify(dest).setValueString("A");
inOrder.verify(dest).setBool(Boolean.TRUE);
}

@Test
void shouldGetJobPrivateOptions() {
// Given
Expand Down
Loading