Question: This is a Java program. Task - Updates to Message/Transfer System In P3, we make several extensions to our system: Add specialized toString() to receiver

This is a Java program.

Task - Updates to Message/Transfer System

In P3, we make several extensions to our system:

Add specialized toString() to receiver and transmitter

Add a three message queue to the receiver

Define a logger to stdout for logging events

Add JUnit unit testing for Transmitter, Receiver, Message

We will continue testing to validate the quality of our implementation developing evidence of correct operation.

Transmitter Modifications

Modify Transmitter such that

one can connect a PrintLogger to it

it send log entries to the connected PrintLogger (if any) for any actions that cause state changes and when sending a

message

it has a meaningful toString()

More specifically, the following methods should be added or modified to Transmitter:

void addLog(PrintLogger printLogger) shall add a PrintLogger to the Transmitter.

String toString() shall return a string consisting of Transmitter(address).

update other methods to add meaningful logging for any actions that cause state changes and when sending a message.

Receiver Modifications

Modify Receiver such that

one can connect a PrintLogger to it

it send log entries to the connected PrintLogger (if any) for any actions that cause state changes

it has a meaningful toString()

it should initialize its source and destination addresses to unset

More specifically, the following methods should be added or modified to Transmitter:

void addLog(PrintLogger printLogger) shall add a PrintLogger to the Receiver.

String toString() shall return a string consisting of Receiver(address).

update other methods to add meaningful logging for any actions that cause state changes.

Create a PrintLogger class

An I/O class for conditionally outputting strings to stdout. PrintLogger implements a concept of a level where nothing will print if the level of the request does not equal or exceed the level at which the printLogger is operating at.

Constructor

PrintLogger(int logLevel)

Commands

where

newLogLevel is the level that must be met or exceeded when the logger is asked to log (print) something

where

level is a value noting the type of the information where common values are given in the table below

logEntry is a text to be part of the printed log

which prints a string to stdout if level is active. The printing routine will add a newline to the logEntry. Define some public constants in PrintLogger to provide some suggested levels:

Name

Level

DEBUG

0

INFO

10

WARNING

50

ERROR

100

JUNIT

Add the tests to your development system:

MessageTest - furnished

TransmitterTest - furnished

ReceiverTest - you must do (with a null print logger)

Produce a TestP3 program

Produce a demo program that demonstrates the features of the classes not tested by JUnit (including the use of a print logger.)

Supply a log of the running of the demo program with developer supplied commentary on how the log shows correct operation of the system.

Hint: A possible implementation of this program is

/* File: TestP3.java

* Author: David Green

* Assignment: 2017-4FallP2to5 - EE333 Fall 2017

* Vers: 1.0.0 09/15/2017 dgg - initial coding

/**

* @author

*/

public class TestP3 {

/**

* Exercise those features of P3 that can not be exercised by unit tests

* (especially the logging behavior)

*

* @param args the command line arguments

*/

public static void main(String[] args) {

PrintLogger logger = new PrintLogger();

Transmitter t1 = new Transmitter("tx");

t1.addLog(logger);

Receiver r1 = new Receiver("rx");

r1.addLog(logger);

Message m1 = new Message();

Message m2 = new Message("m2 contents");

Message m3 = new Message("m3 contents");

// check Messages (left to guarantee start at 10000)

passFail(m1.getUID() == 10000, "test1");

for ( int i = 0; i < 2; i++ ) {

if ( i == 1 ) {

logger.setLogLevel(PrintLogger.ERROR);

System.out.println("Second pass, log only errors ********");

}

/*

*

* UID: nnnnn Source: sourceaddr destination: destaddr

* ContentType: text/plain

* Message:

* Text of message

*

*/

String lineSeparator = System.getProperty("line.separator");

String messageDump

= "UID: 10001 Source: unset Destination: unset" + lineSeparator

+ "ContentType: text/plain" + lineSeparator

+ "Message:" + lineSeparator

+ ">>m2 contents<<";

String mDump = m2.dump();

if ( i == 0 ) {

passFail(mDump.equals(messageDump), "test2");

}

// send before connecting a transmitter

t1.send(m3);

// connect r1 to t1 and send a message

t1.connect(r1);

t1.send(m2);

Message m = r1.getMessage();

messageDump

= "UID: 10001 Source: tx Destination: rx" + lineSeparator

+ "ContentType: text/plain" + lineSeparator

+ "Message:" + lineSeparator

+ ">>m2 contents<<";

mDump = m.dump();

passFail(mDump.equals(messageDump), "test3");

// check overrun behavior followed by reset

t1.send(m2);

t1.send(m3);

t1.send(m3);

t1.send(m3);

passFail(r1.overrun(), "test4");

r1.reset();

passFail(!r1.overrun(), "test5");

passFail(r1.getMessage() == nul l, "test6");

t1.disconnect();

}

}

// Helper function to print results of test

private static void passFail( boolean test, String name) {

System.out.println("Test " + name + (test ? " passes" : " fails"));

}

}

--------------------------------------------------------------------

and might produce an output on stdout of

--------------------------------------------------------------------

Test test1 passes

Test test2 passes

Transmitter(tx): No connected receiver.

Transmitter(tx): Connected receiver: Receiver(rx)

Receiver(rx): delivery of message: m2 contents

Transmitter(tx): Sending message to Receiver(rx)

Transmitter(tx): Delivering message: m2 contents

Receiver(rx): retrieving message: m2 contents

Test test3 passes

Receiver(rx): delivery of message: m2 contents

Transmitter(tx): Sending message to Receiver(rx)

Transmitter(tx): Delivering message: m2 contents

Receiver(rx): delivery of message: m3 contents

Transmitter(tx): Sending message to Receiver(rx)

Transmitter(tx): Delivering message: m3 contents

Receiver(rx): delivery of message: m3 contents

Transmitter(tx): Sending message to Receiver(rx)

Transmitter(tx): Delivering message: m3 contents

Receiver(rx): overrun caused by delivery of message: m3 contents

Transmitter(tx): Sending message to Receiver(rx)

Transmitter(tx): Delivering message: m3 contents

Test test4 passes

Receiver(rx): reseting

Test test5 passes

Receiver(rx): attempt to get non-existent message

Test test6 passes

Transmitter(tx): Receiver Receiver(rx) disconnected.

Second pass, log only errors ********

Transmitter(tx): No connected receiver.

Test test3 passes

Receiver(rx): overrun caused by delivery of message: m3 contents

Test test4 passes

Test test5 passes

Receiver(rx): attempt to get non-existent message

Test test6 passes

Hints

The JUnit tests can be written not quite completely as unit tests. In other words, while you can test Message without anything else, you will probably want to use Message while testing Receiver, and both Message and Receiver while testing Transmitter. There are some techniques to avoid this but they require more code.

You can use the existing P2 receiver for running the transmitter unit tests if desired.

There is support for generating the test skeleton code with NetBeans.

The first time, you try to add a test, you will be invited to install the JUNIT package (choose the latest version).

Obey Java Documentation Style

Continue to use the specified documentation standard for Java source code. There are commands in NetBeans to assist in compliance.

http://www-ece.eng.uab.edu/DGreen/java_ex/JavaDocStyle.html

Discussion/Questions

The P3 discussion forum is available for discussion and questions.

Delivery

You shall produce source code that complies with the documentation standards. Furnish UML Class Diagram(s) for the entire project. Your program MUST show your name and BlazerID near the top of source code file. Produce a blazerid-p3.zip file containing a directory blazerid-p3 which contains the NetBeans Directory and your UML diagram(s).

The programette will be graded using the rubric available within the LMS.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!