2019-05-22 23:51:37 -07:00
|
|
|
/*
|
|
|
|
|
* ProcessManagerTest
|
|
|
|
|
*
|
|
|
|
|
* v1.0
|
|
|
|
|
*
|
|
|
|
|
* May 22, 2019
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package JobServ;
|
|
|
|
|
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
|
import org.junit.runners.JUnit4;
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* ProcessManagerTest
|
|
|
|
|
* Class that performs positive and negative unit tests
|
|
|
|
|
* of every public method in ProcessManager. This not
|
|
|
|
|
* only unit tests ProcessManager but also integration
|
|
|
|
|
* tests it with ProcessController.
|
|
|
|
|
*/
|
|
|
|
|
public class ProcessManagerTest {
|
|
|
|
|
ProcessManager manager;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* ProcessManagerTest constructor
|
|
|
|
|
* initializes the process manager
|
|
|
|
|
*/
|
|
|
|
|
public ProcessManagerTest() {
|
|
|
|
|
manager = new ProcessManager();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* addProcessTest()
|
|
|
|
|
* positive unit test for newProcess
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void addProcessesTest() {
|
2019-05-23 01:26:28 -07:00
|
|
|
int pid1 = manager.newProcess("ping google.com");
|
|
|
|
|
int pid2 = manager.newProcess("ping google.com");
|
|
|
|
|
assertEquals(2, pid2);
|
|
|
|
|
assertEquals(1, pid1);
|
2019-05-22 23:51:37 -07:00
|
|
|
|
2019-05-23 01:26:28 -07:00
|
|
|
manager.shutdown();
|
2019-05-22 23:51:37 -07:00
|
|
|
}
|
|
|
|
|
|
2019-05-23 01:26:28 -07:00
|
|
|
/*
|
|
|
|
|
* getStatusTest
|
|
|
|
|
* positive unit test for getStatus
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void getStatusTest() {
|
|
|
|
|
int pid1 = manager.newProcess("ping google.com");
|
|
|
|
|
assertEquals(0, pid1);
|
|
|
|
|
|
|
|
|
|
int status = manager.getProcessStatus(pid1);
|
|
|
|
|
assertEquals(0, status);
|
|
|
|
|
|
|
|
|
|
manager.shutdown();
|
|
|
|
|
}
|
2019-05-22 23:51:37 -07:00
|
|
|
}
|
|
|
|
|
|