You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

NewInstanceExecutorTest.java 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package com.uqac.rthoni.java_rmi.server.executors;
  2. import com.uqac.rthoni.java_rmi.common.Command;
  3. import com.uqac.rthoni.java_rmi.server.ServerApplication;
  4. import org.junit.Test;
  5. import static org.junit.Assert.*;
  6. /**
  7. * Created by robin on 9/16/16.
  8. */
  9. public class NewInstanceExecutorTest {
  10. public String runCommand(String str, ServerApplication app) throws Exception {
  11. Command command = Command.fromString(str);
  12. AbstractCommandExecutor executor = app.getExecutor(command);
  13. return executor.run(command, app);
  14. }
  15. public ServerApplication getServer() throws Exception {
  16. ServerApplication app = new ServerApplication();
  17. app.loadExecutors();
  18. return app;
  19. }
  20. @Test
  21. public void test1() throws Exception
  22. {
  23. ServerApplication app = getServer();
  24. String res = runCommand("creation#com.uqac.rthoni.java_rmi.server.TestDbo#test", app);
  25. assertNull(res);
  26. Object obj = app.getObject("test");
  27. assertNotNull(obj);
  28. }
  29. @Test
  30. public void test2() throws Exception
  31. {
  32. ServerApplication app = getServer();
  33. String res = runCommand("creation#java.lang.String#mystr", app);
  34. assertNull(res);
  35. Object obj = app.getObject("mystr");
  36. assertNotNull(obj);
  37. assertEquals(obj.toString(), "");
  38. }
  39. @Test(expected = ClassNotFoundException.class)
  40. public void test3() throws Exception
  41. {
  42. runCommand("creation#not_existing_class#myobj", getServer());
  43. }
  44. }