public class ProtocolTest extends BaseTestCase
The protocol to send to the Net server is contained in a file encoded
as calls to routines in DDMReader
and DDMWriter
.
Additional commands have been added for testing purposes.
To add tests, modify the file protocol.tests.
Tests can also be done as separate files and given as an argument to
this class.
This test was copied / converted from testProto.
Modifier and Type | Field and Description |
---|---|
private org.apache.derby.impl.drda.ProtocolTestAdapter |
adapter
The adapter that lives on the DRDA package, allowing us to call the
otherwise unavailable methods we need to call in package private
classes.
|
private java.lang.String |
commandSequence
The sequence of commands this test is composed of.
|
private java.lang.String |
filename
Name of the file from which the test is obtained.
|
private int |
lineCount
Number of lines this test is composed of.
|
private static java.lang.String |
MULTIVAL_END |
private static java.lang.String |
MULTIVAL_SEP |
private static java.lang.String |
MULTIVAL_START |
private static java.lang.String |
NL
Newline character(s).
|
private static java.lang.String |
PREFIX |
private int |
startLine
The start line of the test from the input file.
|
private static java.lang.String |
UTF8_TEST_MATCH |
private static java.lang.String |
UTF8_TEST_STRING |
DEFAULT_DB_DIR, DERBY_LOG, ERRORSTACKTRACEFILE
Modifier | Constructor and Description |
---|---|
private |
ProtocolTest(java.lang.String file,
java.lang.String cmds,
int startLine,
int lines)
Creates a new test case.
|
Modifier and Type | Method and Description |
---|---|
private void |
assertCP(int reqCP,
int cp)
Codepoint error
|
private void |
checkError(java.io.StreamTokenizer tkn)
Check error sent back to application requester
|
private boolean |
checkIntOrCP(java.io.StreamTokenizer tkn,
int val)
checks if value matches next int or cp.
|
private void |
checkSQLCARD(int sqlCode,
java.lang.String sqlState)
Check the value of SQLCARD
|
private int |
convertHex(java.lang.String str,
int lineNumber)
Convert a token in hex format to int from the command file
|
private static java.net.Socket |
createSocket()
Initializes a socket to the server.
|
private int |
decodeCP(java.lang.String strval,
int lineNumber)
Translate a string codepoint such as ACCSEC to the equivalent int value
|
private void |
deleteDatabase(java.lang.String name)
Delete the database with the name 'name'
|
private byte[] |
getBytes(java.io.StreamTokenizer tkn)
Read an array of bytes from the command file
A byte string can start with 0x in which case the bytes are interpreted
in hex format or it can just be a string, in which case each char is
interpreted as 2 byte UNICODE
|
private int |
getCP(java.io.StreamTokenizer tkn)
Read the string version of a CodePoint
|
private byte[] |
getEBCDIC(java.lang.String str)
Translate a string to EBCDIC for use in the protocol
|
private int |
getInt(java.io.StreamTokenizer tkn)
Read an int from the command file
Negative numbers are preceded by "-"
|
private int |
getIntOrCP(java.io.StreamTokenizer tkn)
Read an int or codepoint - codepoint is given as a string
|
private java.lang.String |
getString(java.io.StreamTokenizer tkn)
Read a string from the command file
|
private int |
ln(java.io.StreamTokenizer st)
Calculates the current line number from the source file.
|
private boolean |
processCommand(java.io.StreamTokenizer tkn)
Process a command.
|
private void |
processCommands(java.io.Reader cmdStream)
Processes the test commands in the stream.
|
private void |
processFile(java.lang.String fileName)
Executes the test commands in the specified file.
|
private void |
readLengthAndCodePoint(java.io.StreamTokenizer tkn)
Read length and codepoint and check against required values
|
private void |
readSecMecAndSECCHKCD()
Handle the case of testing the reading of SECMEC and SECCHKCD,
where on an invalid SECMEC value for ACCSEC, the server can send
valid supported SECMEC values.
|
static junit.framework.Test |
suite()
Creates a suite of tests dynamically from a file describing protocol
tests.
|
void |
tearDown()
Cleans up test resources.
|
void |
testProtocolSequence()
Executes the test sequence.
|
private void |
writeEncodedLDString(java.lang.String str,
java.lang.String encoding,
int len)
Write length and encoded string
|
private void |
writeEncodedString(java.lang.String str,
java.lang.String encoding)
Write an encoded string
|
alarm, assertDirectoryDeleted, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertExecJavaCmdAsExpected, assertLaunchedJUnitTestMethod, assertLaunchedJUnitTestMethod, assertSameNullness, assertSecurityManager, assertThrowableEquals, currentDirectory, execJavaCmd, execJavaCmd, execJavaCmd, fail, getClassVersionMajor, getEmmaJar, getFailureFolder, getFilesWith, getJavaExecutableName, getSystemProperty, getTestConfiguration, getTestResource, hasInterruptibleIO, isCVM, isIBMJVM, isJ9Platform, isJava5, isJava7, isPhoneME, isPlatform, isSunJVM, isWindowsPlatform, newAssertionFailedError, openTestResource, println, printStackTrace, readProcessOutput, removeDirectory, removeDirectory, removeFiles, removeSystemProperty, runBare, runsWithEmma, runsWithJaCoCo, setSystemErr, setSystemOut, setSystemProperty, sleep, sleepAtLeastOneTick, traceit, vmAtLeast
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runTest, setName, setUp, toString
private static final java.lang.String PREFIX
private static final java.lang.String NL
private static final java.lang.String MULTIVAL_START
private static final java.lang.String MULTIVAL_SEP
private static final java.lang.String MULTIVAL_END
private static final java.lang.String UTF8_TEST_MATCH
private static final java.lang.String UTF8_TEST_STRING
private final java.lang.String filename
private final int startLine
private final int lineCount
private java.lang.String commandSequence
The sequence is expected to be line oriented, that is a one command and optionally its arguments per line. The lines must be separated by a newline token.
private org.apache.derby.impl.drda.ProtocolTestAdapter adapter
private ProtocolTest(java.lang.String file, java.lang.String cmds, int startLine, int lines)
file
- name of file containing the protocol tests (for verbosity)cmds
- the sequence of commands (see commandSequence
)startLine
- starting line in the source filelines
- number of lines from the source filepublic void testProtocolSequence() throws java.io.IOException, java.net.UnknownHostException
java.io.IOException
- if accessing a file or the socket fails, or if
Derby detects an unexpected protocol errorjava.net.UnknownHostException
- if the server host cannot be resolvedpublic void tearDown() throws java.lang.Exception
tearDown
in class junit.framework.TestCase
java.lang.Exception
private static java.net.Socket createSocket() throws java.io.IOException, java.net.UnknownHostException
java.io.IOException
- if reading/writing to the socket failsjava.net.UnknownHostException
- if the server host cannot be resolvedprivate void processFile(java.lang.String fileName) throws java.io.IOException
fileName
- file containing the testjava.io.IOException
- if accessing a file or the socket fails, or if
Derby detects an unexpected protocol errorprivate void processCommands(java.io.Reader cmdStream) throws java.io.IOException
cmdStream
- command stream (see commandSequence
)java.io.IOException
- if accessing a file or the socket fails, or if
Derby detects an unexpected protocol errorprivate boolean processCommand(java.io.StreamTokenizer tkn) throws java.io.IOException
java.io.IOException
private int getInt(java.io.StreamTokenizer tkn) throws java.io.IOException
java.io.IOException
private int convertHex(java.lang.String str, int lineNumber) throws java.io.IOException
java.io.IOException
private boolean checkIntOrCP(java.io.StreamTokenizer tkn, int val) throws java.io.IOException
java.io.IOException
private int getIntOrCP(java.io.StreamTokenizer tkn) throws java.io.IOException
java.io.IOException
private byte[] getBytes(java.io.StreamTokenizer tkn) throws java.io.IOException
java.io.IOException
private java.lang.String getString(java.io.StreamTokenizer tkn) throws java.io.IOException
java.io.IOException
- error reading fileprivate int getCP(java.io.StreamTokenizer tkn) throws java.io.IOException
java.io.IOException
- error reading fileprivate int decodeCP(java.lang.String strval, int lineNumber)
strval
- string codepointprivate void checkError(java.io.StreamTokenizer tkn) throws java.io.IOException
java.io.IOException
- error reading file or protocolprivate void readLengthAndCodePoint(java.io.StreamTokenizer tkn) throws java.io.IOException
java.io.IOException
- error reading file or protocolprivate void readSecMecAndSECCHKCD() throws java.io.IOException
java.io.IOException
- error reading file or protocolprivate void assertCP(int reqCP, int cp)
java.io.IOException
- error reading command fileprivate byte[] getEBCDIC(java.lang.String str)
str
- string to transformprivate void writeEncodedString(java.lang.String str, java.lang.String encoding)
str
- string to writeencoding
- Java encoding to usejava.io.IOException
private void writeEncodedLDString(java.lang.String str, java.lang.String encoding, int len)
str
- string to writeencoding
- Java encoding to uselen
- Size of length value (2 or 4 bytes)java.io.IOException
private void checkSQLCARD(int sqlCode, java.lang.String sqlState) throws java.io.IOException
sqlCode
- SQLCODE valuesqlState
- SQLSTATE valueIOException,
- DRDAProtocolExceptionjava.io.IOException
private int ln(java.io.StreamTokenizer st)
The intention is to be able to print which line number the test failed on, so that the source of the error can be easily located.
st
- processing stream tokenizerprivate void deleteDatabase(java.lang.String name)
name
- Name of the database to deletepublic static junit.framework.Test suite() throws java.lang.Exception
java.lang.Exception
- if creating the suite fails for some reasonApache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.