Fields Summary |
---|
private final String | TEST_NAMEThe fully qualified name of this test. |
private final String | MMS_TO_DEVICE_IDThe device ID ("phone number") of the recipient. |
private final String | MMS_TO_APP_IDThe application ID of the recipient. |
private final String | MMS_TO_ADDRESSThe MMS address to which the message will be sent. |
private final String | MMS_FROM_DEVICE_IDThe device ID ("phone number") of the sender. |
private final String | MMS_FROM_APP_IDThe application ID of the sender. |
private final String | MMS_FROM_ADDRESSThe MMS address from which the message will be sent. |
private final String | MMS_CLIENT_ADDRESSThe MMS client address. |
private final String | MMS_CONTENT_MESSAGEThe MMS test message. |
private final byte[] | MMS_CONTENTThe contents of an MMS message. |
private javax.wireless.messaging.MessageConnection | conThe MMS connection. |
private boolean | passedTest passed/failed flag. |
Methods Summary |
---|
private void | checkMultipartMessage(javax.wireless.messaging.MultipartMessage msg)Verify that the contents of the multipart message match the message
data that were sent..
// Pick up all message parts.
MessagePart[] parts = msg.getMessageParts();
if (parts == null) {
System.out.println("No message parts.");
return;
}
// Make sure the message part contains the expected content.
for (int i = 0, n = parts.length; i < n; i++) {
MessagePart part = parts[i];
byte[] content = part.getContent();
if (content == null) {
System.out.println("No content in message part #" + i);
return;
}
String data = new String(content);
if (!data.equals(MMS_CONTENT_MESSAGE)) {
System.out.println("Content message mismatch.");
return;
}
}
|
void | cleanUp()Provide clean-up services, following the run of this test.
closeConnection();
|
private void | closeConnection()Close the MMS connection.
try {
con.close();
} catch (IOException ioe) {
// Fail silently.
} catch (Exception e) {
// Fail silently.
}
|
private void | createClientConnection(java.lang.String clientAddress)Create and open an MMS connection.
con = (MessageConnection)Connector.open(clientAddress);
|
private javax.wireless.messaging.MultipartMessage | createCompleteMessage(java.lang.String toAddress, java.lang.String fromAddress, byte[] content)Create the MMS message to be sent.
// The MIME type for this message.
String mimeType = "mms:";
// The unique content ID.
String contentID = "message1";
// No content location.
String contentLocation = null;
// No encoding.
String encoding = null;
MessagePart part = new MessagePart(content, 0, content.length,
mimeType, contentID, contentLocation, encoding);
MultipartObject mm = new MultipartObject(toAddress);
mm.addMessagePart(part);
mm.setFromAddress(fromAddress);
return mm;
|
public void | run()Create, send and receive a multipart message. This test assumes that the
underlying code employs the loopback scheme (i.e., messages are not
actually sent or received; however, the messages get added to the pool,
which triggers notifications.).
try {
MultipartMessage mm =
createCompleteMessage(MMS_TO_ADDRESS, MMS_FROM_ADDRESS,
MMS_CONTENT);
con.send(mm);
Message m = con.receive();
if (m instanceof MultipartMessage) {
checkMultipartMessage((MultipartMessage)m);
} else {
System.out.println("Not a MultipartMessage.");
return;
}
closeConnection();
passed = true;
assertTrue("Indicate that the test passed.", passed);
} catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
|
public void | runTests()Main entry point.
setUp();
declare(TEST_NAME);
run();
cleanUp();
|
void | setUp()Set up the physical connection.
try {
createClientConnection(MMS_CLIENT_ADDRESS);
} catch (IOException ioe) {
System.out.println(TEST_NAME + " set-up failed:");
ioe.printStackTrace();
}
|