Skip to content

Commit

Permalink
simplified testing EchoServer
Browse files Browse the repository at this point in the history
  • Loading branch information
jh3nd3rs0n committed Feb 3, 2024
1 parent 0d0cdd6 commit 4b1f9e8
Show file tree
Hide file tree
Showing 11 changed files with 162 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@

import java.io.IOException;

import com.github.jh3nd3rs0n.echo.EchoClient;
import com.github.jh3nd3rs0n.echo.EchoServer;

public final class EchoServerHelper {

public static void startThenExecuteThenStop(
final EchoServer echoServer,
final IoRunnable runnable) throws IOException {
public static String startThenEchoThenStop(
final EchoServer echoServer,
final EchoClient echoClient,
final String string) throws IOException {
String returningString;
echoServer.start();
try {
runnable.run();
returningString = echoClient.echo(
string, echoServer.getInetAddress(), echoServer.getPort());
} finally {
if (!echoServer.getState().equals(EchoServer.State.STOPPED)) {
echoServer.stop();
}
}
return returningString;
}

private EchoServerHelper() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,35 +157,29 @@ public void testEchoServerUsingChainedSocks5ClientToSocksServers01() throws IOEx
EchoServer echServer = new EchoServer(
newChainedSocks5ClientToSocksServers().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_01;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingChainedSocks5ClientToSocksServers02() throws IOException {
EchoServer echServer = new EchoServer(
newChainedSocks5ClientToSocksServers().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_02;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingChainedSocks5ClientToSocksServers03() throws IOException {
EchoServer echServer = new EchoServer(
newChainedSocks5ClientToSocksServers().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_03;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -197,35 +197,29 @@ public void testEchoServerUsingChainedSocks5ClientToSocksServersUsingSocks5Userp
EchoServer echServer = new EchoServer(
newChainedSocks5ClientToSocksServersUsingSocks5UserpassMethod().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_01;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingChainedSocks5ClientToSocksServersUsingSocks5UserpassMethod02() throws IOException {
EchoServer echServer = new EchoServer(
newChainedSocks5ClientToSocksServersUsingSocks5UserpassMethod().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_02;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingChainedSocks5ClientToSocksServersUsingSocks5UserpassMethod03() throws IOException {
EchoServer echServer = new EchoServer(
newChainedSocks5ClientToSocksServersUsingSocks5UserpassMethod().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_03;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -168,35 +168,29 @@ public void testEchoServerUsingChainedSocks5ClientToSocksServersUsingSsl01() thr
EchoServer echServer = new EchoServer(
newChainedSocks5ClientToSocksServersUsingSsl().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_01;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingChainedSocks5ClientToSocksServersUsingSsl02() throws IOException {
EchoServer echServer = new EchoServer(
newChainedSocks5ClientToSocksServersUsingSsl().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_02;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingChainedSocks5ClientToSocksServersUsingSsl03() throws IOException {
EchoServer echServer = new EchoServer(
newChainedSocks5ClientToSocksServersUsingSsl().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_03;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -152,35 +152,29 @@ public void testEchoServerUsingSocks5ClientToChainedSocksServers01() throws IOEx
EchoServer echServer = new EchoServer(
newSocks5ClientToChainedSocksServers().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_01;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingSocks5ClientToChainedSocksServers02() throws IOException {
EchoServer echServer = new EchoServer(
newSocks5ClientToChainedSocksServers().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_02;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingSocks5ClientToChainedSocksServers03() throws IOException {
EchoServer echServer = new EchoServer(
newSocks5ClientToChainedSocksServers().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_03;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -192,35 +192,29 @@ public void testEchoServerUsingSocks5ClientToChainedSocksServersUsingSocks5Userp
EchoServer echServer = new EchoServer(
newSocks5ClientToChainedSocksServersUsingSocks5UserpassMethod().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_01;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingSocks5ClientToChainedSocksServersUsingSocks5UserpassMethod02() throws IOException {
EchoServer echServer = new EchoServer(
newSocks5ClientToChainedSocksServersUsingSocks5UserpassMethod().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_02;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingSocks5ClientToChainedSocksServersUsingSocks5UserpassMethod03() throws IOException {
EchoServer echServer = new EchoServer(
newSocks5ClientToChainedSocksServersUsingSocks5UserpassMethod().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_03;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -166,35 +166,29 @@ public void testEchoServerUsingSocks5ClientToChainedSocksServersUsingSsl01() thr
EchoServer echServer = new EchoServer(
newSocks5ClientToChainedSocksServersUsingSsl().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_01;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingSocks5ClientToChainedSocksServersUsingSsl02() throws IOException {
EchoServer echServer = new EchoServer(
newSocks5ClientToChainedSocksServersUsingSsl().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_02;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingSocks5ClientToChainedSocksServersUsingSsl03() throws IOException {
EchoServer echServer = new EchoServer(
newSocks5ClientToChainedSocksServersUsingSsl().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_03;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,35 +129,29 @@ public void testEchoServerUsingSocks5ClientToSocksServer01() throws IOException
EchoServer echServer = new EchoServer(
newSocks5Client().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_01;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingSocks5ClientToSocksServer02() throws IOException {
EchoServer echServer = new EchoServer(
newSocks5Client().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_02;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

@Test
public void testEchoServerUsingSocks5ClientToSocksServer03() throws IOException {
EchoServer echServer = new EchoServer(
newSocks5Client().newSocksNetObjectFactory(), 0);
String string = TestStringConstants.STRING_03;
EchoServerHelper.startThenExecuteThenStop(echServer, () -> {
String returningString = new EchoClient().echo(
string, echServer.getInetAddress(), echServer.getPort());
assertEquals(string, returningString);
});
String returningString = EchoServerHelper.startThenEchoThenStop(
echServer, new EchoClient(), string);
assertEquals(string, returningString);
}

}
Loading

0 comments on commit 4b1f9e8

Please sign in to comment.