COMP225-ProcessManager-Scanner

Objectives

The main objectives of this request are:

  • to practise software project management (Agile);
  • to gain experience in using version control systems (git);
  • to gain experience in reading code documentation;
  • to gain experience in writing code documentation;
  • to gain experience in designing unit and integration tests.

Note This request specification aims to provide as complete a description of this assessment task as possible. However, as with any specification, there will always be things we should have said that we have left out and areas in which we could have done a better job of explanation. As a result, you are strongly encouraged to ask any questions of clarification you might have, either by raising them during a lecture or by posting them on the iLearn discussion forum devoted to this request.

The Specification

In request 1, You have developed a small library, in Java. This library contains a class, ProcessManager, that provides an interface to perform simple interactions 1 other programs, typically shell scripts, not necessarily written in Java. The objective of request 2 is to extend the functionalities of the ProcessManager class to more complex interactions.

For this request, you may have to look some concepts up (e.g. regular expressions, prompt) as part of a self learning practice. The emphasis in this task is on:

  • understanding the problem to be solved and writing a formal specification;
  • understanding what Java libraries offer and how to use them;
  • documenting your code so that other developers can use it;
  • writing tests for your code;
  • developing the software as a Agile project;

Sprint 4

Useful Concept for this sprint: Scanner (Java)

In this sprint, you have to implement a send and an expect method in the

ProcessManager class (the interfaces of the methods are provided in Program 1).

Program 1: Expect method

The send method specification is simple:

  • the argument is a String s,
  • the send method should send s to the process managed by the instance of the ProcessManager.
  • it should return true if the string could be sent, or false if a problem occurred while sending s. The expect method specification is as follows:
  • the arguments are a timeout (duration) and a prompt which is given as a regular expression (Pattern in Java);
  • the method returns:
  • the string w if the process managed by the instance of the ProcessManager produces w followed by the prompt on its output channel before the timeout;
  • throw a timeout exception otherwise.

A simple use case of expect in a Java program on a Unix system is:

  • you spawn a process that is going to ‘ssh’ to a remote machine.
  • the process should return a prompt which is the string “password” (a simple regular expression);
  • when you have seen the prompt on the output channel, you can send your password (string) and the next prompt you should expect is the terminal prompt on the target machine.
  • if the prompt does not appear on the output channel, an error occured.
  • In this sprint, you have to implement the expect and send methods and write some tests to ensure that the methods do what they are supposed to do. In this sprint you may assume that expect is called only once and then the process terminates. You will need to import the following package in the ProcessManager.java file.

After that you have to make sure that the expect method can be used many times in an instance of a ProcessManager. The previous use case can be extended.

You have to modify, if needed, your implementations of expect and send to be able to interact with a managed process in a way similar to the scenario described above.

You also have to write some tests to ensure that your implementation does what it is supposed to do. We strongly encourage you to split the work as follows: one group member is in charge of writing the tests and if needed refine the specification; the other member adapts the implementations of expect and send to make sure the tests pass.