@Test
  public void test()
      throws ApplicationAlreadyRegisteredException, WrongApplicationIdException,
          SpaceAlreadyRegisteredException, IllegalArgumentException {

    Set<SpaceInstanceInfo> spaces = new HashSet<SpaceInstanceInfo>();
    Set<Long> appsRegistered;

    spaces.add(spaceInstanceInput1);
    spaces.add(spaceInstanceInput2);
    spaces.add(spaceInstanceOutput1);
    spaces.add(spaceInstanceOutput2);

    assertFalse(stub.isApplicationIdRegistered(MAIN_APPID));
    // TEST REGISTER APP
    logger.info("Test register application");
    stub.registerApplication(MAIN_APPID, spaces);

    // check if everything has been registered
    logger.info("Checking that application has been registered");
    assertTrue(stub.isApplicationIdRegistered(MAIN_APPID));
    appsRegistered = stub.getRegisteredApplications();
    appsRegistered.contains(MAIN_APPID);

    // TEST LOOKUP FIRST
    logger.info("Test Lookup First");
    assertIsSpaceRegistered(spaceInstanceInput1);
    assertIsSpaceRegistered(spaceInstanceInput2);
    assertIsSpaceRegistered(spaceInstanceOutput1);
    assertIsSpaceRegistered(spaceInstanceOutput2);

    // TEST LOOKUP ALL
    logger.info("Test Lookup All");
    final DataSpacesURI query = DataSpacesURI.createURI(MAIN_APPID);
    final Set<SpaceInstanceInfo> actual = stub.lookupMany(query);
    assertEquals(spaces, actual);

    // TEST UNREGISTER
    logger.info("Test unregister");
    assertTrue(stub.unregister(spaceInstanceInput1.getMountingPoint()));
    assertTrue(stub.unregister(spaceInstanceOutput1.getMountingPoint()));

    // TEST LOOKUP FIRST WITH NULL ANSWER
    logger.info("Test looup first with null answer");
    assertIsSpaceUnregistered(spaceInstanceInput1);
    assertIsSpaceUnregistered(spaceInstanceOutput1);

    // TEST REGISTER
    logger.info("Test register");
    stub.register(spaceInstanceInput1);
    stub.register(spaceInstanceOutput1);

    // TEST EXCEPTION WHEN SPACE ALREADY REGISTERED
    logger.info("Test Exception when space already registered");
    try {
      stub.register(spaceInstanceInput1);
      fail("Exception expected");
    } catch (SpaceAlreadyRegisteredException e) {
    } catch (Exception e) {
      fail("Expected exception of different type");
    }

    // TEST EXCEPTION WHEN APP NOT REGISTERED
    logger.info("Test Exception when app not registered");
    try {
      stub.register(spaceInstanceInput1b);
      fail("Exception expected");
    } catch (WrongApplicationIdException e) {
    } catch (Exception e) {
      fail("Expected exception of different type");
    }

    // TEST EXCEPTION WHEN APP ALREADY REGISTERED
    logger.info("Test Exception when app already registered");
    try {
      stub.registerApplication(MAIN_APPID, null);
      fail("Exception expected");
    } catch (ApplicationAlreadyRegisteredException e) {
    } catch (Exception e) {
      fail("Expected exception of different type");
    }

    // TEST UNREGISTER APP
    logger.info("Test unregister");
    stub.unregisterApplication(MAIN_APPID);
  }