Skip to content

Commit

Permalink
Merge pull request #19 from Blazemeter/FIX_SCREEN_AND_TAB_INPUT_ISSUES
Browse files Browse the repository at this point in the history
- Fixed issue on InputByTab when recording 
- Fixed screen to support a large range of screens
- Added support for ALP charset 
- Consecutive input by label support
  • Loading branch information
sebastianlorenzo88 committed Feb 18, 2021
2 parents 9f50d05 + cad4ed4 commit e71603c
Show file tree
Hide file tree
Showing 16 changed files with 150 additions and 128 deletions.
Binary file modified docs/blazemeter-labs-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.blazemeter.jmeter</groupId>
<artifactId>jmeter-bzm-rte</artifactId>
<packaging>jar</packaging>
<version>3.1.0</version>
<version>3.1.1</version>
<name>RTEPlugin Sampler as JMeter plugin</name>

<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public Position calculateInputFinalPosition(Position currentPos,

@Override
public String getCsv() {
return "<" + navigationType + "*" + repeat + ">\t" + input;
return "<" + navigationType + "*" + repeat + ">," + input;
}

public int getRepeat() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Area getSearchArea() {

@Override
public String getDescription() {
return "emulator screen area " + searchArea + " to contain " + regex.getPattern();
return "emulator screen area " + searchArea + " to contain '" + regex.getPattern() + "'";
}

public boolean matchesScreen(Screen screen) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import javax.naming.OperationNotSupportedException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -62,7 +62,7 @@ public class Tn3270Client extends BaseProtocolClient {
private static final Map<AttentionKey, Byte> AID_COMMANDS = buildAIdCommandsKeysMapping();

private TerminalClient client;
private Map<TerminalStateListener, Tn3270TerminalStateListenerProxy> listenersProxies =
private final Map<TerminalStateListener, Tn3270TerminalStateListenerProxy> listenersProxies =
new ConcurrentHashMap<>();

private static List<TerminalType> buildTerminalTypes() {
Expand Down Expand Up @@ -247,7 +247,7 @@ private void setFieldByNavigationType(NavigationInput i) {
} else {
exceptionHandler
.setPendingError(new OperationNotSupportedException(
"The navigation type \'" + i.getNavigationType() + "\' is not supported"));
"The navigation type '" + i.getNavigationType() + "' is not supported"));
}
}
}
Expand Down Expand Up @@ -284,12 +284,41 @@ protected ConditionWaiter<?> buildWaiter(WaitCondition waitCondition) {

@Override
public Screen getScreen() {
// when sscp lu data screen or screens without explicit fields
if (client.getFields().isEmpty()) {
return buildScreenFromText(client.getScreenText().replace("\n", ""));
} else {
return buildScreenFromFields(client.getFields());
List<Field> fields = client.getFields();
Dimension size = getScreenSize();
Screen screen = new Screen(size);
String screenText = client.getScreenText().replace("\n", "");
if (fields.isEmpty()) {
return buildScreenFromText(screenText);
}
int linealPosition = 0;
List<Field> unProtectedFields = fields.stream().filter(Field::isUnprotected)
.collect(Collectors.toList());
for (Field field : unProtectedFields) {
// FirstLocation is the first location of text not counting the position consumed by
// field attributes. First location can be 0 when last empty field of screen.
if (field.getFirstLocation() != 0 && field.getFirstLocation() - 1 != linealPosition) {
String chunk = getChunkOfScreenFrom(screenText, linealPosition,
field.getFirstLocation() - 1);
screen.addSegment(linealPosition, chunk);
linealPosition += chunk.length();
}
screen.addSegment(linealPosition, " ");
if (!field.getText().isEmpty()) {
if (field.isHidden()) {
screen.addSecretField(linealPosition + 1, field.getText());
} else {
screen.addField(linealPosition + 1, field.getText());
}
}
linealPosition += field.getText().length() + 1;

}
if (linealPosition < size.width * size.height) {
String chunk = getChunkOfScreenFrom(screenText, linealPosition, size.height * size.width);
screen.addSegment(linealPosition, chunk);
}
return screen;
}

private Screen buildScreenFromText(String screenText) {
Expand All @@ -311,28 +340,13 @@ private Screen buildScreenFromText(String screenText) {
return ret;
}

private Screen buildScreenFromFields(List<Field> fields) {
Dimension size = getScreenSize();
Screen ret = new Screen(size);
for (Field f : fields) {
int linealPosition =
(f.getFirstLocation() != 0 ? f.getFirstLocation() : size.height * size.width) - 1;
String text = f.isVisible() ? f.getText() : StringUtils.repeat(' ', f.getDisplayLength());
if (f.isProtected()) {
ret.addSegment(linealPosition, " " + text);
} else {
ret.addSegment(linealPosition, " ");
if (linealPosition + 1 < size.height * size.width) {
if (f.isHidden()) {
ret.addSecretField(linealPosition + 1, text);
} else {
ret.addField(linealPosition + 1, text);
}

}
}
private String getChunkOfScreenFrom(String screen, int segmentBegin,
int segmentEnd) {
StringBuilder sb = new StringBuilder();
for (int i = segmentBegin; i < segmentEnd; i++) {
sb.append(screen.charAt(i));
}
return ret;
return sb.toString();
}

public Dimension getScreenSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected List<Input> getInputFields() {
}
Iterator<XI5250Field> it = getFields().listIterator(initialField);
int index = 0;
int offset = 1;
int offset = 0;
Position lastFieldPosition = null;
while (it.hasNext() && index < getFields().size()) {
XI5250Field f = it.next();
Expand All @@ -61,7 +61,7 @@ protected List<Input> getInputFields() {
fields.add(label != null ? new LabelInput(label, trimmedInput)
: new NavigationInput(f.equals(fieldFromPos) ? 0 : offset, NavigationType.TAB,
trimmedInput));
offset = 1;
offset = trimmedInput.trim().length() == f.getLength() ? 0 : 1;
} else {
offset++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.blazemeter.jmeter.rte.sampler.gui.SwingUtils;
import com.blazemeter.jmeter.rte.sampler.gui.ThemedIconLabel;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.GroupLayout;
Expand Down Expand Up @@ -76,31 +77,14 @@ private void initIntermittentLabels() {
}

private MouseListener buildShowHelpOnMouseClickListener() {
return new MouseListener() {
return new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
public void mouseClicked(MouseEvent e) {
if (helpFrame == null) {
helpFrame = new HelpFrame();
}
helpFrame.open();
}

@Override
public void mousePressed(MouseEvent mouseEvent) {
}

@Override
public void mouseReleased(MouseEvent mouseEvent) {
}

@Override
public void mouseEntered(MouseEvent mouseEvent) {
}

@Override
public void mouseExited(MouseEvent mouseEvent) {
}

};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
Expand All @@ -21,7 +21,7 @@ public BlazemeterLabsLogo() {

private void setBrowseOnClick(String url) {
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
addMouseListener(new MouseListener() {
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent mouseEvent) {
if (Desktop.isDesktopSupported()) {
Expand All @@ -32,24 +32,6 @@ public void mouseClicked(MouseEvent mouseEvent) {
}
}
}

@Override
public void mousePressed(MouseEvent mouseEvent) {
}

@Override
public void mouseReleased(MouseEvent mouseEvent) {
}

@Override
public void mouseEntered(MouseEvent mouseEvent) {
}

@Override
public void mouseExited(MouseEvent mouseEvent) {
}

});
}

}
Binary file modified src/main/resources/dark-theme/blazemeter-labs-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/main/resources/light-theme/blazemeter-labs-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.blazemeter.jmeter.rte.protocols.tn3270;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.in;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
Expand Down Expand Up @@ -37,10 +36,9 @@
import java.util.List;
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.util.JMeterUtils;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;
import org.junit.Test;

public class Tn3270ClientIT extends RteProtocolClientIT<Tn3270Client> {
Expand Down Expand Up @@ -151,8 +149,8 @@ private void sendUsernameWithSyncWait() throws Exception {
awaitSync();
}

private List<Input> buildUsernameField() {
return Collections.singletonList(new CoordInput(new Position(2, 1), USERNAME));
private Input buildUsernameField() {
return new CoordInput(new Position(2, 1), USERNAME);
}

@Test
Expand Down Expand Up @@ -231,8 +229,8 @@ public void shouldThrowTimeoutExceptionWhenSyncWaitAndSlowResponse() throws Exce
awaitSync();
}

private void sendEnterAttentionKey(List<Input> inputs) throws RteIOException {
client.send(inputs, AttentionKey.ENTER, 0);
private void sendEnterAttentionKey(Input... inputs) throws RteIOException {
client.send(Arrays.asList(inputs), AttentionKey.ENTER, 0);
}

@Test(expected = TimeoutException.class)
Expand Down Expand Up @@ -261,13 +259,7 @@ public void shouldThrowTimeoutExceptionWhenTextWaitWithNoMatchingRegex()
loadLoginFlow();
connectToVirtualService();
sendEnterAttentionKey(buildUsernameField());
client.await(Collections
.singletonList(new TextWaitCondition(new Perl5Compiler().compile("testing-wait-text"),
new Perl5Matcher(),
Area.fromTopLeftBottomRight(1, 1, Position.UNSPECIFIED_INDEX,
Position.UNSPECIFIED_INDEX),
TIMEOUT_MILLIS,
STABLE_TIMEOUT_MILLIS)));
awaitText("testing-wait-text");
}

@Test
Expand All @@ -294,7 +286,7 @@ public void shouldThrowUnsupportedOperationExceptionWhenSelectAttentionKeyUnsupp
throws Exception {
loadFlow("login.yml");
connectToVirtualService();
client.send(buildUsernameField(), AttentionKey.ROLL_UP, 0);
client.send(Collections.singletonList(buildUsernameField()), AttentionKey.ROLL_UP, 0);
}

@Test
Expand Down Expand Up @@ -371,8 +363,12 @@ public void shouldThrowTimeoutExceptionWhenMatchedScreenChangedBeforeStablePerio
loadFlow("login-with-multiple-flash-screen.yml");
client.connect(VIRTUAL_SERVER_HOST, server.getPort(), SSLType.NONE, getDefaultTerminalType(),
TIMEOUT_MILLIS);
awaitText("AAAAA");
}

client.await(Collections.singletonList(new TextWaitCondition(JMeterUtils.getPattern("AAAAA"),
private void awaitText(String text)
throws InterruptedException, TimeoutException, RteIOException {
client.await(Collections.singletonList(new TextWaitCondition(JMeterUtils.getPattern(text),
JMeterUtils.getMatcher(),
Area.fromTopLeftBottomRight(1, 1, Position.UNSPECIFIED_INDEX, Position.UNSPECIFIED_INDEX),
TIMEOUT_MILLIS, STABLE_TIMEOUT_MILLIS)));
Expand All @@ -382,14 +378,22 @@ public void shouldThrowTimeoutExceptionWhenMatchedScreenChangedBeforeStablePerio
public void shouldGetUserMenuScreenWhenSendUserNameWithArrows() throws Exception {
loadFlow("login.yml");
connectToVirtualService();
List<Input> inputs = Arrays.asList(
new NavigationInput(1, NavigationType.DOWN, ""),
sendEnterAttentionKey(new NavigationInput(1, NavigationType.DOWN, ""),
new NavigationInput(27, NavigationType.RIGHT, ""),
new NavigationInput(2, NavigationType.UP, ""),
new NavigationInput(1, NavigationType.LEFT, "testusr"));
sendEnterAttentionKey(inputs);
awaitSync();
assertThat(client.getScreen().withInvisibleCharsToSpaces())
.isEqualTo(buildScreenFromHtmlFile("user-menu-screen.html"));
}

@Test
public void shouldValidateTextOnScreeWhenScreenBuiltFromPlainTextAndFields() throws Exception {
loadFlow("login-mixed-fields-and-plain-text.yml");
connectExtendedProtocolClientToVirtualService();
sendEnterAttentionKey(new NavigationInput(0, NavigationType.TAB, "TESTUSR "),
new NavigationInput(1, NavigationType.TAB,
"TESTPSW" + IntStream.range(0, 35).mapToObj(i -> " ").collect(Collectors.joining())));
awaitText("Ready");
}
}
Loading

0 comments on commit e71603c

Please sign in to comment.