Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
import org.apache.jmeter.gui.TestElementMetadata;
import org.apache.jmeter.save.CSVSaveService;
import org.apache.jmeter.services.FileServer;
import org.apache.jmeter.testbeans.PropertyBackedTestBean;
import org.apache.jmeter.testbeans.TestBean;
import org.apache.jmeter.testbeans.gui.GenericTestBeanCustomizer;
import org.apache.jmeter.testelement.property.JMeterProperty;
import org.apache.jmeter.testelement.property.StringProperty;
import org.apache.jmeter.testelement.schema.PropertiesAccessor;
import org.apache.jmeter.threads.JMeterContext;
import org.apache.jmeter.threads.JMeterVariables;
import org.apache.jmeter.util.JMeterUtils;
Expand Down Expand Up @@ -68,7 +71,7 @@
@GUIMenuSortOrder(1)
@TestElementMetadata(labelResource = "displayName")
public class CSVDataSet extends ConfigTestElement
implements TestBean, LoopIterationListener, NoConfigMerge {
implements TestBean, PropertyBackedTestBean, LoopIterationListener, NoConfigMerge {

public enum ShareMode {
ALL("shareMode.all"),
Expand All @@ -94,33 +97,20 @@ public String toString() {
private static final String EOFVALUE = // value to return at EOF
JMeterUtils.getPropDefault("csvdataset.eofstring", "<EOF>"); //$NON-NLS-1$ //$NON-NLS-2$

private transient String filename;

private transient String fileEncoding;

private transient String variableNames;

private transient String delimiter;

private transient boolean quoted;

private transient boolean recycle = true;

private transient boolean stopThread;

private transient String[] vars;

private transient String alias;

private transient String shareMode;

private boolean firstLineIsNames = false;

private boolean ignoreFirstLine = false;
@Override
public CSVDataSetSchema getSchema() {
return CSVDataSetSchema.INSTANCE;
}

private Object readResolve(){
recycle = true;
return this;
@Override
public PropertiesAccessor<? extends CSVDataSet, ? extends CSVDataSetSchema> getProps() {
return new PropertiesAccessor<>(this, getSchema());
}

/**
Expand All @@ -137,7 +127,14 @@ private Object readResolve(){
@Override
public void setProperty(JMeterProperty property) {
String propName = property.getName();
if ("shareMode".equals(propName)) {
if (getSchema().getShareMode().getName().equals(propName)) {
if (property instanceof StringProperty stringProperty) {
String stringValue = stringProperty.getStringValue();
if (stringValue == null || !stringValue.contains(" ")) {
super.setProperty(property);
return;
}
}
JMeterProperty shareMode =
GenericTestBeanCustomizer.normalizeEnumProperty(getClass(), ShareMode.class, property);
if (shareMode != null) {
Expand All @@ -164,6 +161,8 @@ public void iterationStart(LoopIterationEvent iterEvent) {
initVars(server, context, delim);
}

boolean recycle = getRecycle();
boolean ignoreFirstLine = isIgnoreFirstLine();
// TODO: fetch this once as per vars above?
JMeterVariables threadVars = context.getVariables();
String[] lineValues = {};
Expand Down Expand Up @@ -206,7 +205,7 @@ private void initVars(FileServer server, final JMeterContext context, String del
throw new IllegalArgumentException("Could not split CSV header line from file:" + fileName,e);
}
} else {
server.reserveFile(fileName, getFileEncoding(), alias, ignoreFirstLine);
server.reserveFile(fileName, getFileEncoding(), alias, isIgnoreFirstLine());
vars = JOrphanUtils.split(names, ","); // $NON-NLS-1$
}
trimVarNames(vars);
Expand Down Expand Up @@ -239,81 +238,81 @@ private static void trimVarNames(String[] varsNames) {
* @return Returns the filename.
*/
public String getFilename() {
return filename;
return get(getSchema().getFilename());
}

/**
* @param filename
* The filename to set.
*/
public void setFilename(String filename) {
this.filename = filename;
set(getSchema().getFilename(), filename);
}

/**
* @return Returns the file encoding.
*/
public String getFileEncoding() {
return fileEncoding;
return get(getSchema().getFileEncoding());
}

/**
* @param fileEncoding
* The fileEncoding to set.
*/
public void setFileEncoding(String fileEncoding) {
this.fileEncoding = fileEncoding;
set(getSchema().getFileEncoding(), fileEncoding);
}

/**
* @return Returns the variableNames.
*/
public String getVariableNames() {
return variableNames;
return get(getSchema().getVariableNames());
}

/**
* @param variableNames
* The variableNames to set.
*/
public void setVariableNames(String variableNames) {
this.variableNames = variableNames;
set(getSchema().getVariableNames(), variableNames);
}

public String getDelimiter() {
return delimiter;
return get(getSchema().getDelimiter());
}

public void setDelimiter(String delimiter) {
this.delimiter = delimiter;
set(getSchema().getDelimiter(), delimiter);
}

public boolean getQuotedData() {
return quoted;
return get(getSchema().getQuotedData());
}

public void setQuotedData(boolean quoted) {
this.quoted = quoted;
set(getSchema().getQuotedData(), quoted);
}

public boolean getRecycle() {
return recycle;
return get(getSchema().getRecycle());
}

public void setRecycle(boolean recycle) {
this.recycle = recycle;
set(getSchema().getRecycle(), recycle);
}

public boolean getStopThread() {
return stopThread;
return get(getSchema().getStopThread());
}

public void setStopThread(boolean value) {
this.stopThread = value;
set(getSchema().getStopThread(), value);
}

public String getShareMode() {
return shareMode;
return get(getSchema().getShareMode());
}

@Nullable ShareMode getShareModeAsEnum() {
Expand All @@ -325,20 +324,20 @@ public String getShareMode() {
}

public void setShareMode(String value) {
this.shareMode = value;
set(getSchema().getShareMode(), value);
}

/**
* @return the ignoreFirstLine
*/
public boolean isIgnoreFirstLine() {
return ignoreFirstLine;
return get(getSchema().getIgnoreFirstLine());
}

/**
* @param ignoreFirstLine the ignoreFirstLine to set
*/
public void setIgnoreFirstLine(boolean ignoreFirstLine) {
this.ignoreFirstLine = ignoreFirstLine;
set(getSchema().getIgnoreFirstLine(), ignoreFirstLine);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,7 @@

public class CSVDataSetBeanInfo extends BeanInfoSupport {

// These names must agree case-wise with the variable and property names
private static final String FILENAME = "filename"; //$NON-NLS-1$
private static final String FILE_ENCODING = "fileEncoding"; //$NON-NLS-1$
private static final String VARIABLE_NAMES = "variableNames"; //$NON-NLS-1$
private static final String IGNORE_FIRST_LINE = "ignoreFirstLine"; //$NON-NLS-1$
private static final String DELIMITER = "delimiter"; //$NON-NLS-1$
private static final String RECYCLE = "recycle"; //$NON-NLS-1$
private static final String STOPTHREAD = "stopThread"; //$NON-NLS-1$
private static final String QUOTED_DATA = "quotedData"; //$NON-NLS-1$
private static final String SHAREMODE = "shareMode"; //$NON-NLS-1$
private static final CSVDataSetSchema SCHEMA = CSVDataSetSchema.INSTANCE;

private static final String[] SHARE_TAGS = new String[3];
static final int SHARE_ALL = 0;
Expand All @@ -55,51 +46,53 @@ public CSVDataSetBeanInfo() {
super(CSVDataSet.class);

createPropertyGroup("csv_data", //$NON-NLS-1$
new String[] { FILENAME, FILE_ENCODING, VARIABLE_NAMES,
IGNORE_FIRST_LINE, DELIMITER, QUOTED_DATA,
RECYCLE, STOPTHREAD, SHAREMODE });
new String[] { SCHEMA.getFilename().getName(), SCHEMA.getFileEncoding().getName(),
SCHEMA.getVariableNames().getName(), SCHEMA.getIgnoreFirstLine().getName(),
SCHEMA.getDelimiter().getName(), SCHEMA.getQuotedData().getName(),
SCHEMA.getRecycle().getName(), SCHEMA.getStopThread().getName(),
SCHEMA.getShareMode().getName() });

PropertyDescriptor p = property(FILENAME);
PropertyDescriptor p = property(SCHEMA.getFilename().getName());
p.setValue(NOT_UNDEFINED, true);
p.setValue(DEFAULT, ""); //$NON-NLS-1$
p.setValue(DEFAULT, SCHEMA.getFilename().getDefaultValue());
p.setValue(NOT_EXPRESSION, true);
p.setPropertyEditorClass(FileEditor.class);

p = property(FILE_ENCODING, TypeEditor.ComboStringEditor);
p = property(SCHEMA.getFileEncoding().getName(), TypeEditor.ComboStringEditor);
p.setValue(NOT_UNDEFINED, true);
p.setValue(DEFAULT, ""); //$NON-NLS-1$
p.setValue(DEFAULT, SCHEMA.getFileEncoding().getDefaultValue());
p.setValue(TAGS, getListFileEncoding());

p = property(VARIABLE_NAMES);
p = property(SCHEMA.getVariableNames().getName());
p.setValue(NOT_UNDEFINED, true);
p.setValue(DEFAULT, ""); //$NON-NLS-1$
p.setValue(DEFAULT, SCHEMA.getVariableNames().getDefaultValue());
p.setValue(NOT_EXPRESSION, true);

p = property(IGNORE_FIRST_LINE);
p = property(SCHEMA.getIgnoreFirstLine().getName());
p.setValue(NOT_UNDEFINED, true);
p.setValue(DEFAULT, false);
p.setValue(DEFAULT, SCHEMA.getIgnoreFirstLine().getDefaultValue());

p = property(DELIMITER);
p = property(SCHEMA.getDelimiter().getName());
p.setValue(NOT_UNDEFINED, true);
p.setValue(DEFAULT, ","); //$NON-NLS-1$
p.setValue(DEFAULT, SCHEMA.getDelimiter().getDefaultValue());
p.setValue(NOT_EXPRESSION, true);

p = property(QUOTED_DATA);
p = property(SCHEMA.getQuotedData().getName());
p.setValue(NOT_UNDEFINED, true);
p.setValue(DEFAULT, false);
p.setValue(DEFAULT, SCHEMA.getQuotedData().getDefaultValue());

p = property(RECYCLE);
p = property(SCHEMA.getRecycle().getName());
p.setValue(NOT_UNDEFINED, true);
p.setValue(DEFAULT, true);
p.setValue(DEFAULT, SCHEMA.getRecycle().getDefaultValue());

p = property(STOPTHREAD);
p = property(SCHEMA.getStopThread().getName());
p.setValue(NOT_UNDEFINED, true);
p.setValue(DEFAULT, false);
p.setValue(DEFAULT, SCHEMA.getStopThread().getDefaultValue());

p = property(SHAREMODE, TypeEditor.ComboStringEditor);
p = property(SCHEMA.getShareMode().getName(), TypeEditor.ComboStringEditor);
p.setValue(RESOURCE_BUNDLE, getBeanDescriptor().getValue(RESOURCE_BUNDLE));
p.setValue(NOT_UNDEFINED, true);
p.setValue(DEFAULT, SHARE_TAGS[SHARE_ALL]);
p.setValue(DEFAULT, SCHEMA.getShareMode().getDefaultValue());
p.setValue(NOT_OTHER, false);
p.setValue(NOT_EXPRESSION, false);
p.setValue(TAGS, SHARE_TAGS);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.config

import org.apache.jmeter.testelement.schema.BooleanPropertyDescriptor
import org.apache.jmeter.testelement.schema.StringPropertyDescriptor
import org.apiguardian.api.API

/**
* Lists properties of a [CSVDataSet].
* @since 6.0
*/
@API(status = API.Status.EXPERIMENTAL, since = "6.0.0")
public abstract class CSVDataSetSchema : ConfigTestElementSchema() {
public companion object INSTANCE : CSVDataSetSchema()

public val filename: StringPropertyDescriptor<CSVDataSetSchema>
by string("filename", default = "")

public val fileEncoding: StringPropertyDescriptor<CSVDataSetSchema>
by string("fileEncoding", default = "")

public val variableNames: StringPropertyDescriptor<CSVDataSetSchema>
by string("variableNames", default = "")

public val ignoreFirstLine: BooleanPropertyDescriptor<CSVDataSetSchema>
by boolean("ignoreFirstLine", default = false)

public val delimiter: StringPropertyDescriptor<CSVDataSetSchema>
by string("delimiter", default = ",")

public val quotedData: BooleanPropertyDescriptor<CSVDataSetSchema>
by boolean("quotedData", default = false)

public val recycle: BooleanPropertyDescriptor<CSVDataSetSchema>
by boolean("recycle", default = true)

public val stopThread: BooleanPropertyDescriptor<CSVDataSetSchema>
by boolean("stopThread", default = false)

public val shareMode: StringPropertyDescriptor<CSVDataSetSchema>
by string("shareMode", default = "shareMode.all")
}
Loading