Skip to content

Commit

Permalink
fix: after disabling the Java Request sampler, it cannot be enabled a…
Browse files Browse the repository at this point in the history
…gain

Java sampler was inheriting "enabled" status from its config element
as internally, Java Sampler UI always creates a config element and merges it
to the java sampler.

The solution is to move "configureTestElement(sampler);" to the very end of
modifyTestElement so all the base properties are populated based on
the element properties rather than "config element" properties.

Ideally we should somehow limit "mergeIn", and we should refrain from merging
unexpected properties.

Fixes #6004
  • Loading branch information
vlsi committed Jun 27, 2023
1 parent c9cb9ad commit d7e9e30
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class AbstractJMeterGuiComponent extends JPanel implements JMete
/** Logging */
private static final Logger log = LoggerFactory.getLogger(AbstractJMeterGuiComponent.class);

/** Flag indicating whether or not this component is enabled. */
/** Flag indicating whether this component is enabled. */
private boolean enabled = true;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.jmeter.gui

import org.apache.jmeter.testelement.TestElement
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import javax.swing.JPopupMenu

class AbstractJMeterGuiComponentTest {
@Test
fun isEnabled() {
val element = object : AbstractJMeterGuiComponent() {
override fun getLabelResource(): String = "dummy_element_for_tests"

override fun createTestElement(): TestElement = TODO()

override fun modifyTestElement(element: TestElement?) = TODO()

override fun createPopupMenu(): JPopupMenu = TODO()

override fun getMenuCategories(): MutableCollection<String> = TODO()
}

assertEquals(true, element.isEnabled, "element.isEnabled after creation of the element")

element.clearGui()
assertEquals(true, element.isEnabled, "element.isEnabled after element.clearGui()")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ public TestElement createTestElement() {
public void modifyTestElement(TestElement sampler) {
sampler.clear();
JavaConfig config = (JavaConfig) javaPanel.createTestElement();
configureTestElement(sampler);
sampler.addTestElement(config);
// Set base parameters (name, description, enabled) from the main control
// to avoid merging them from the config element above
configureTestElement(sampler);
}

/* Overrides AbstractJMeterGuiComponent.configure(TestElement) */
Expand Down

0 comments on commit d7e9e30

Please sign in to comment.