@Test
 public void shouldHaveOnlyDefinedDependencies() {
   List<String> unexpected = new ArrayList<>();
   packageDependencies
       .keySet()
       .stream()
       .map(Package::getPackage)
       .forEach(
           sourcePackage -> {
             List<String> allowed = dependenciesOf(sourcePackage);
             String source = sourcePackage.getName();
             packageDependencies
                 .get(source)
                 .stream()
                 .filter(target -> !source.equals(target))
                 .filter(target -> !allowed.contains(target))
                 .filter(target -> !isAlwaysAllowed(target))
                 .forEach(target -> unexpected.add(source + " -> " + target));
           });
   if (!unexpected.isEmpty()) fail("unexpected dependencies:\n" + String.join("\n", unexpected));
 }
 @Test
 public void testInputTypes() {
   final Class[] classes = plugIn.getInputTypes();
   assertNotNull(classes);
   assertEquals(2, classes.length);
   final List<Class> list = Arrays.asList(classes);
   assertEquals(true, list.contains(File.class));
   assertEquals(true, list.contains(String.class));
 }
Exemplo n.º 3
0
  /**
   * Тестирование на динамическом списке
   *
   * @throws Exception
   */
  @Test
  public void testOnArrayList() throws Exception {
    List<UserHashcode> users = new ArrayList<>();
    users.add(user1);
    assertTrue(users.contains(user1));

    // user3 копия user1, но не содержится в списке. equals не переопределен, поэтому False
    assertFalse(users.contains(user3));

    users.add(user2);
    users.add(user3);

    // ожидаемо для списка, т.к. может содержать много копий даже одного объекта
    assertEquals(3, users.size());
  }
Exemplo n.º 4
0
  @Test
  public void testCreateAndDropManyDatabases() throws Exception {
    List<String> createdDatabases = new ArrayList<>();
    InfoSchemaMetadataDictionary dictionary = new InfoSchemaMetadataDictionary();
    String namePrefix = "database_";
    final int NUM = 10;
    for (int i = 0; i < NUM; i++) {
      String databaseName = namePrefix + i;
      assertFalse(catalog.existDatabase(databaseName));
      catalog.createDatabase(databaseName, TajoConstants.DEFAULT_TABLESPACE_NAME);
      assertTrue(catalog.existDatabase(databaseName));
      createdDatabases.add(databaseName);
    }

    Collection<String> allDatabaseNames = catalog.getAllDatabaseNames();
    for (String databaseName : allDatabaseNames) {
      assertTrue(
          databaseName.equals(DEFAULT_DATABASE_NAME)
              || createdDatabases.contains(databaseName)
              || dictionary.isSystemDatabase(databaseName));
    }
    // additional ones are 'default' and 'system' databases.
    assertEquals(NUM + 2, allDatabaseNames.size());

    Collections.shuffle(createdDatabases);
    for (String tobeDropped : createdDatabases) {
      assertTrue(catalog.existDatabase(tobeDropped));
      catalog.dropDatabase(tobeDropped);
      assertFalse(catalog.existDatabase(tobeDropped));
    }
  }
  @Test
  public void testSendAndReceive() throws Exception {

    // Run the main controller
    ControllerRunner controllerRunner =
        new ControllerRunner(10, 9090, InetAddress.getLocalHost(), "127.0.0.1", 8008);
    controllerRunner.run();
    System.out.println("Controller running");

    Random random = new Random();
    int player = random.nextInt();

    // Connect a new controller and send test alarm
    Controller controller = new Controller(10);
    Socket connection1 = controller.connectTo(InetAddress.getLocalHost().getHostAddress(), 9090);
    Alarm alarm = new Alarm(player, System.currentTimeMillis(), new PlayerCause(player));
    controller.send(alarm, connection1);

    Controller controller2 = new Controller(10);
    Socket connection2 = controller2.connectTo(InetAddress.getLocalHost().getHostAddress(), 9090);
    long alarmtime = System.currentTimeMillis() + 500;
    Position position1 = new Position(player, System.currentTimeMillis(), 1, 2, 3);
    Position position2 = new Position(player, alarmtime, 100, 200, 300);
    controller2.send(position1, connection2);
    controller2.send(position2, connection2);
    controller2.send(new Request(player, DataType.ACCEL, -1, -1), connection2);
    controller2.send(new Request(player, DataType.POS, -1, -1), connection2);

    Thread.sleep(15000);
    List<Sendable> received = controller2.receive(connection2);
    List<Alarm> alarms = new ArrayList<Alarm>();
    List<Acceleration> accelerations = new ArrayList<Acceleration>();
    List<Position> positions = new ArrayList<Position>();

    // Distribute the sendable objects
    for (Sendable sendable : received) {
      if (sendable instanceof Alarm) {
        alarms.add((Alarm) sendable);

      } else if (sendable instanceof Service) {
        Service service = (Service) sendable;
        List<?> data = service.getData();
        for (Object o : data) {
          if (o instanceof Acceleration) {
            accelerations.add((Acceleration) o);
          } else if (o instanceof Position) {
            positions.add((Position) o);
          }
        }
      }
    }

    controller.disconnectFromClient(connection1);
    controller2.disconnectFromClient(connection2);

    assertTrue("Alarm was not sent from controller", alarms.size() >= 1);
    assertTrue("Acceleration not received from controller", accelerations.size() >= 1);
    assertTrue("Position 1 not contained in received positions", positions.contains(position1));
    assertTrue("Position 2 not contained in received positions", positions.contains(position2));
  }
  @Test // Uses of JMockit API: 8
  public void useArgumentMatchers() {
    new Expectations() {
      {
        // Using built-in matchers:
        mockedList.get(anyInt);
        result = "element";

        // Using Hamcrest matchers:
        mockedList.get(withArgThat(is(equalTo(5))));
        result = new IllegalArgumentException();
        minTimes = 0;
        mockedList.contains(withArgThat(hasProperty("bytes")));
        result = true;
        mockedList.containsAll(withArgThat(hasSize(2)));
        result = true;
      }
    };

    assertEquals("element", mockedList.get(999));
    assertTrue(mockedList.contains("abc"));
    assertTrue(mockedList.containsAll(asList("a", "b")));

    new Verifications() {
      {
        mockedList.get(anyInt);
      }
    };
  }
    public void beforeExecute(Task task) {
      assertTrue(planned.contains(task));

      String taskPath = path(task);
      if (taskPath.startsWith(":buildSrc:")) {
        return;
      }

      executedTasks.add(taskPath);
    }
  @Test
  public void testFindAllAlbumsByOwner() throws Exception {
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    // Execute
    List<Album> foundAlbums = repository.findAllByOwner(user.getUserId());

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, createdAlbum.getAlbumId());
    assertEquals(1, foundAlbums.size());
    assertTrue(foundAlbums.contains(actualAlbum));
  }
 /**
  * Prove of availability to getByKey list of available attributes within given <code>
  * attributeGroupCode</code>, that can be assigned to business entity.
  */
 @Test
 public void testFindAvailableAttributes2() {
   List<String> allCodes =
       Arrays.asList(
           "URI",
           "CATEGORY_ITEMS_PER_PAGE",
           "CATEGORY_IMAGE_RETRIEVE_STRATEGY",
           "CATEGORY_IMAGE0",
           "CATEGORY_DESCRIPTION_en",
           "CATEGORY_DESCRIPTION_ru",
           "CONTENT_BODY_ru_1",
           "CONTENT_BODY_ru_2",
           "CONTENT_BODY_en_1",
           "CONTENT_BODY_en_2");
   // getByKey all attributes available for category
   List<Attribute> attributes =
       attributeService.findAvailableAttributes(AttributeGroupNames.CATEGORY, null);
   assertNotNull(attributes);
   assertFalse(attributes.isEmpty());
   for (Attribute attr : attributes) {
     assertTrue(allCodes.contains(attr.getCode()));
   }
   // category already has all attributes
   attributes = attributeService.findAvailableAttributes(AttributeGroupNames.CATEGORY, allCodes);
   assertNotNull(attributes);
   assertTrue(attributes.isEmpty());
   // get all except URI
   attributes =
       attributeService.findAvailableAttributes(
           AttributeGroupNames.CATEGORY, Arrays.asList("URI"));
   assertNotNull(attributes);
   assertFalse(attributes.isEmpty());
   assertEquals("CATEGORY_ITEMS_PER_PAGE", attributes.get(0).getCode());
   // get just URI
   attributes =
       attributeService.findAttributesByCodes(AttributeGroupNames.CATEGORY, Arrays.asList("URI"));
   assertNotNull(attributes);
   assertFalse(attributes.isEmpty());
   assertEquals("URI", attributes.get(0).getCode());
 }
Exemplo n.º 10
0
 @Test
 public void FilesName() {
   assertTrue(files.contains("file1.test") && files.contains("file2.test"));
 }