/**
   * Called before the tests start.
   *
   * <p>Sets up the node and initializes connector and users that can be used throughout the tests.
   *
   * @throws Exception
   */
  @BeforeClass
  public static void startServer() throws Exception {

    // start node
    node = LocalNode.newNode();
    node.storeAgent(MockAgentFactory.getAdam());
    node.launch();

    ServiceAgent testService = ServiceAgent.generateNewAgent(testTemplateService, "a pass");
    testService.unlockPrivateKey("a pass");

    node.registerReceiver(testService);

    // start connector
    logStream = new ByteArrayOutputStream();

    connector = new WebConnector(true, HTTP_PORT, false, 1000);
    connector.setLogStream(new PrintStream(logStream));
    connector.start(node);
    Thread.sleep(1000); // wait a second for the connector to become ready
    testAgent = MockAgentFactory.getAdam();

    connector.updateServiceList();
    // avoid timing errors: wait for the repository manager to get all services before continuing
    try {
      System.out.println("waiting..");
      Thread.sleep(10000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }
示例#2
0
  @Test
  public void testSimpleInvokation()
      throws L2pSecurityException, CryptoException, AgentAlreadyRegisteredException, AgentException,
          SecurityException, IllegalArgumentException, AgentNotKnownException,
          NoSuchMethodException, IllegalAccessException, InvocationTargetException,
          InterruptedException {
    String serviceClass = "i5.las2peer.api.TestService";
    ServiceAgent testService = ServiceAgent.generateNewAgent(serviceClass, "a passphrase");
    testService.unlockPrivateKey("a passphrase");

    LocalNode testee = LocalNode.launchNode();

    eve.unlockPrivateKey("evespass");
    testee.storeAgent(eve);
    eve.lockPrivateKey();

    testee.storeAgent(testService);
    testee.registerReceiver(testService);

    Serializable result =
        testee.invokeLocally(
            eve.getId(), serviceClass, "inc", new Serializable[] {new Integer(10)});

    assertEquals(12, result);
  }
  @Before
  public void startServer() throws Exception {
    // start Node
    node = LocalNode.newNode();

    adam = MockAgentFactory.getAdam();
    adam.unlockPrivateKey(adamsPass);
    node.storeAgent(adam);

    node.launch();

    ServiceAgent testService = ServiceAgent.createServiceAgent(testServiceClass, "a pass");
    testService.unlockPrivateKey("a pass");

    node.registerReceiver(testService);

    // start connector
    logStream = new ByteArrayOutputStream();
    connector = new HttpConnector();
    connector.setSocketTimeout(10000);
    connector.setLogStream(new PrintStream(logStream));
    connector.start(node);
  }