View | Details | Raw Unified | Return to bug 65336
Collapse All | Expand All

(-)a/src/core/src/main/java/org/apache/jmeter/testelement/AbstractTestElement.java (-1 / +9 lines)
Lines 546-558 public abstract class AbstractTestElement implements TestElement, Serializable, Link Here
546
            temporaryProperties = new LinkedHashSet<>();
546
            temporaryProperties = new LinkedHashSet<>();
547
        }
547
        }
548
        temporaryProperties.add(property);
548
        temporaryProperties.add(property);
549
        if (property instanceof MultiProperty) {
549
        if (isMergingEnclosedProperties(property)) {
550
            for (JMeterProperty jMeterProperty : (MultiProperty) property) {
550
            for (JMeterProperty jMeterProperty : (MultiProperty) property) {
551
                setTemporary(jMeterProperty);
551
                setTemporary(jMeterProperty);
552
            }
552
            }
553
        }
553
        }
554
    }
554
    }
555
555
556
    // While TestElementProperty is implementing MultiProperty, it works differently.
557
    // It doesn't merge the inner properties one by one as MultiProperty would do.
558
    // Therefore we must not mark the enclosed properties of TestElementProperty as
559
    // temporary (Bug 65336)
560
    private boolean isMergingEnclosedProperties(JMeterProperty property) {
561
        return property instanceof MultiProperty && !(property instanceof TestElementProperty);
562
    }
563
556
    /**
564
    /**
557
     * @return Returns the threadContext.
565
     * @return Returns the threadContext.
558
     */
566
     */
(-)a/src/core/src/test/groovy/org/apache/jmeter/testelement/AbstractTestElementSpec.groovy (-1 / +99 lines)
Line 0 Link Here
0
- 
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to you under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
package org.apache.jmeter.testelement
19
20
import org.apache.jmeter.junit.spock.JMeterSpec
21
import org.apache.jmeter.testelement.property.JMeterProperty
22
import org.apache.jmeter.testelement.property.MultiProperty
23
import org.apache.jmeter.testelement.property.PropertyIterator
24
import org.apache.jmeter.testelement.property.TestElementProperty
25
26
import spock.lang.Unroll
27
import sun.reflect.generics.reflectiveObjects.NotImplementedException
28
29
@Unroll
30
class AbstractTestElementSpec extends JMeterSpec {
31
32
    def "set outer properties as temporary when using a TestElementProperty"() {
33
        given:
34
            AbstractTestElement sut = Spy(AbstractTestElement.class)
35
            def outerElement = Mock(TestElement.class)
36
            def innerElement = Mock(TestElement.class)
37
            def outerProp = new TestElementProperty("outerProp", outerElement)
38
            def innerProp = new TestElementProperty("innerProp", innerElement)
39
            outerProp.addProperty(innerProp)
40
        when:
41
            sut.setTemporary(outerProp)
42
        then:
43
            sut.isTemporary(outerProp)
44
            !sut.isTemporary(innerProp)
45
    }
46
47
    def "set all properties as temporary when using a MultiProperty"() {
48
        given:
49
            AbstractTestElement sut = Spy(AbstractTestElement.class)
50
            def outerProp = new MinimalMultiProperty()
51
            def innerProp = new MinimalMultiProperty()
52
            outerProp.addProperty(innerProp)
53
        when:
54
            sut.setTemporary(outerProp)
55
        then:
56
            sut.isTemporary(outerProp)
57
            sut.isTemporary(innerProp)
58
    }
59
60
    private class MinimalMultiProperty extends MultiProperty {
61
62
        Set<JMeterProperty> props = new HashSet<>()
63
64
        @Override
65
        void recoverRunningVersion(TestElement owner) {
66
            throw new NotImplementedException()
67
        }
68
69
        @Override
70
        String getStringValue() {
71
            throw new NotImplementedException()
72
        }
73
74
        @Override
75
        Object getObjectValue() {
76
            return null
77
        }
78
79
        @Override
80
        void setObjectValue(Object value) {
81
            throw new NotImplementedException()
82
        }
83
84
        @Override
85
        PropertyIterator iterator() {
86
            return props.iterator() as PropertyIterator
87
        }
88
89
        @Override
90
        void addProperty(JMeterProperty prop) {
91
            props.add(prop)
92
        }
93
94
        @Override
95
        void clear() {
96
            props.clear()
97
        }
98
    }
99
}

Return to bug 65336