@Before
  public void setup()
      throws NoPeerConnectionException, InvalidProcessStateException, ProcessExecutionException {
    // setup network
    network = NetworkTestUtil.createH2HNetwork(NETWORK_SIZE);
    // create some random user credentials
    userCredentials = H2HJUnitTest.generateRandomCredentials();
    // register and login a user (peer 0)
    uploaderRoot = FileTestUtil.getTempDirectory();
    uploader = network.get(0);
    uploader.getUserManager().createRegisterProcess(userCredentials).execute();
    uploader
        .getUserManager()
        .createLoginProcess(userCredentials, new TestFileAgent(uploaderRoot))
        .execute();

    // other client to verify this
    File downloaderRoot = FileTestUtil.getTempDirectory();
    downloader = network.get(1);
    downloader
        .getUserManager()
        .createLoginProcess(userCredentials, new TestFileAgent(downloaderRoot))
        .execute();

    nodeManager = Mockito.mock(INodeManager.class);
    Mockito.stub(nodeManager.getNode()).toReturn(uploader);
    UserConfig userConfig = Mockito.mock(UserConfig.class);
    Mockito.stub(userConfig.getRootPath()).toReturn(uploaderRoot.toPath());
    fileManager = new FileManager(nodeManager, userConfig);
  }
 @After
 public void teardown() {
   if (uploaderRoot != null) {
     FileUtils.deleteQuietly(uploaderRoot);
   }
   NetworkTestUtil.shutdownH2HNetwork(network);
 }
  @Before
  public void setup() throws NoPeerConnectionException, IOException, GeneralSecurityException {
    userCredentials = generateRandomCredentials();
    client = NetworkTestUtil.getRandomNode(network);
    root = FileTestUtil.getTempDirectory();

    // create an user profile
    UserProfile userProfile =
        new UserProfile(
            userCredentials.getUserId(),
            generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS),
            generateRSAKeyPair(H2HConstants.KEYLENGTH_PROTECTION));
    // encrypt it (fake encryption)
    EncryptedNetworkContent encrypted =
        client.getDataManager().getEncryption().encryptAES(userProfile, null);
    encrypted.setVersionKey(userProfile.getVersionKey());
    encrypted.generateVersionKey();

    // upload user profile, avoids register step
    IParameters parameters =
        new Parameters()
            .setLocationKey(userCredentials.getProfileLocationKey())
            .setContentKey(H2HConstants.USER_PROFILE)
            .setVersionKey(encrypted.getVersionKey())
            .setNetworkContent(encrypted)
            .setProtectionKeys(userProfile.getProtectionKeys())
            .setTTL(userProfile.getTimeToLive());
    client.getDataManager().put(parameters);
  }
Пример #4
0
  @Test
  public void testRepair() throws Exception {
    NetworkManager node = NetworkTestUtil.getRandomNode(network);
    UseCaseTestUtil.registerAndLogin(
        generateRandomCredentials(), node, FileTestUtil.getTempDirectory());

    Locations repaired = node.getSession().getLocationsManager().repairLocations();
    Assert.assertNotNull(repaired);
    Assert.assertEquals(0, repaired.getPeerAddresses().size());
  }
Пример #5
0
  @BeforeClass
  public static void initTest() throws Exception {
    testClass = LogoutTest.class;
    beforeClass();

    network = NetworkTestUtil.createNetwork(DEFAULT_NETWORK_SIZE);
    userCredentials = generateRandomCredentials();

    UseCaseTestUtil.registerAndLogin(
        userCredentials, network.get(0), FileTestUtil.getTempDirectory());
  }
Пример #6
0
 @AfterClass
 public static void cleanAfterClass() {
   NetworkTestUtil.shutdownNetwork(network);
   afterClass();
 }
Пример #7
0
 @BeforeClass
 public static void initTest() throws Exception {
   testClass = LocationsManagerTest.class;
   beforeClass();
   network = NetworkTestUtil.createNetwork(DEFAULT_NETWORK_SIZE);
 }