@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); }
@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 } }
@Test public void testStartupAgents() throws L2pSecurityException, AgentException { LocalNode testee = LocalNode.newNode(); testee.storeAgent(adam); testee.launch(); try { testee.storeAgent(abel); fail("L2pSecurityException expected"); } catch (L2pSecurityException e) { // ok } abel.unlockPrivateKey("abelspass"); testee.storeAgent(abel); }
@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 public void testUserRegDistribution() throws L2pSecurityException, AgentException, CryptoException, ArtifactNotFoundException { LocalNode testee1 = LocalNode.launchNode(); long id = Envelope.getClassEnvelopeId(UserAgentList.class, "mainlist"); for (int i = 0; i < 11; i++) { UserAgent a = UserAgent.createUserAgent("pass" + i); a.unlockPrivateKey("pass" + i); a.setLoginName("login_" + i); testee1.storeAgent(a); } // check, that the user list is stored testee1.fetchArtifact(id); LocalNode testee2 = LocalNode.launchNode(); // check, that the user list is stored testee2.fetchArtifact(id); testee2.getAgentIdForLogin("login_2"); }