コード例 #1
0
ファイル: LocalNodeTest.java プロジェクト: hojanssen/las2peer
  @Test
  public void testUserRegistry() throws CryptoException, L2pSecurityException, AgentException {
    UserAgent a = UserAgent.createUserAgent("a");
    UserAgent b = UserAgent.createUserAgent("b");

    a.unlockPrivateKey("a");
    b.unlockPrivateKey("b");

    a.setLoginName("alpha");
    b.setLoginName("beta");

    LocalNode testee = LocalNode.launchNode();
    testee.storeAgent(a);
    testee.storeAgent(b);

    assertEquals(a.getId(), testee.getAgentIdForLogin("alpha"));
    assertEquals(b.getId(), testee.getAgentIdForLogin("beta"));

    try {
      testee.getAgentIdForLogin("bla");
      fail("AgentNotKnownException expected");
    } catch (AgentNotKnownException e) {
      // corrects
    }
  }
コード例 #2
0
ファイル: LocalNodeTest.java プロジェクト: hojanssen/las2peer
  @Test
  public void testTwoNodes()
      throws L2pSecurityException, EncodingFailedException, SerializationException,
          InterruptedException, AgentException {
    adam.unlockPrivateKey("adamspass");
    eve.unlockPrivateKey("evespass");

    // launch to nodes with one agent each
    LocalNode testee1 = LocalNode.launchAgent(adam);
    LocalNode.launchAgent(eve);

    assertTrue(LocalNode.findAllNodesWithAgent(adam.getId()).length > 0);
    assertTrue(LocalNode.findAllNodesWithAgent(eve.getId()).length > 0);

    MessageResultListener l = new MessageResultListener(10000);
    Message m = new Message(adam, eve, new PingPongContent());

    testee1.sendMessage(m, l);

    l.waitForAllAnswers();

    assertEquals(1, l.getNumberOfExpectedResults());
    assertTrue(l.isFinished());
    assertTrue(l.isSuccess());
  }
コード例 #3
0
ファイル: LocalNodeTest.java プロジェクト: hojanssen/las2peer
  @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);
  }
コード例 #4
0
ファイル: LocalNodeTest.java プロジェクト: hojanssen/las2peer
  @Test
  public void testBroadcast()
      throws EncodingFailedException, L2pSecurityException, SerializationException,
          InterruptedException, AgentException, AgentNotKnownException {
    adam.unlockPrivateKey("adamspass");
    eve.unlockPrivateKey("evespass");

    // launch three nodes with one agent each
    LocalNode testee1 = LocalNode.launchAgent(adam);
    LocalNode hosting1 = LocalNode.launchAgent(eve);
    assertEquals(1, LocalNode.findAllNodesWithAgent(eve.getId()).length);

    LocalNode hosting2 = LocalNode.launchAgent(eve);

    assertTrue(hosting1.hasLocalAgent(eve));
    assertTrue(hosting2.hasLocalAgent(eve));

    assertNotSame(hosting1.getAgent(eve.getId()), hosting2.getAgent(eve.getId()));

    assertEquals(2, LocalNode.findAllNodesWithAgent(eve.getId()).length);

    MessageResultListener l =
        new MessageResultListener(10000) {
          public void notifySuccess() {
            synchronized (this) {
              System.out.println("result retrieved");
              LocalNodeTest.counter++;
            }
          }
        };
    // l.addRecipient();
    assertEquals(1, l.getNumberOfExpectedResults());

    Message m = new Message(adam, eve, new PingPongContent());
    testee1.sendMessage(m, l, Node.SendMode.BROADCAST);
    assertEquals(2, l.getNumberOfExpectedResults());

    l.waitForAllAnswers();

    assertEquals(2, l.getNumberOfResults());
    assertEquals(counter, 2);
    assertTrue(l.isSuccess());
    assertTrue(l.isFinished());
  }
コード例 #5
0
ファイル: LocalNodeTest.java プロジェクト: hojanssen/las2peer
  @Test
  public void testRegisteringAgents()
      throws L2pSecurityException, MalformedXMLException, IOException,
          AgentAlreadyRegisteredException, AgentNotKnownException, AgentException {
    adam.unlockPrivateKey("adamspass");
    // abel.unlockPrivateKey ( "abelspass");

    LocalNode testee = LocalNode.launchAgent(adam);

    // testee.storeAgent(abel);

    try {
      testee.storeAgent(abel);
      fail("L2sSecurityAxception expected");
    } catch (L2pSecurityException e) {
    }

    try {
      testee.storeAgent(adam);
      fail("AgentAlreadyRegistered exception expected");
    } catch (AgentAlreadyRegisteredException e) {
    }

    abel.unlockPrivateKey("abelspass");
    testee.storeAgent(abel);

    LocalNode testee2 = LocalNode.launchNode();

    UserAgent retrieve = (UserAgent) testee2.getAgent(abel.getId());
    assertTrue(retrieve.isLocked());

    try {
      testee2.updateAgent(retrieve);
      fail("SecurtityException expected");
    } catch (L2pSecurityException e) {
    }

    retrieve.unlockPrivateKey("abelspass");
    testee2.updateAgent(retrieve);
  }
 /** Test for the getGraphList method. */
 @Test
 public void testgetGraphList() {
   MiniClient c = new MiniClient();
   c.setAddressPort(HTTP_ADDRESS, HTTP_PORT);
   try {
     c.setLogin(Long.toString(testAgent.getId()), testPass);
     @SuppressWarnings("unchecked")
     ClientResponse result =
         c.sendRequest(
             "GET",
             mainPath + "/",
             "",
             MediaType.TEXT_PLAIN,
             MediaType.APPLICATION_JSON,
             new Pair[] {});
     assertTrue(true); // change here
     System.out.println("Result of 'testgetGraphList': " + result.getResponse().trim());
   } catch (Exception e) {
     e.printStackTrace();
     fail("Exception: " + e);
   }
 }