Ejemplo n.º 1
0
  @Test
  public void testPlayerSelectionEvent() {
    ArrayList<Player> players = new ArrayList<Player>();
    Player p1 = new Player("ABC Player1", Position.QB, null, 1.0);
    Player p2 = new Player("DEF Player2", Position.QB, null, 1.0);
    players.add(p1);
    players.add(p2);

    PlayerSelector sel = new PlayerSelector(players);

    NameSelectionListener listener = mock(NameSelectionListener.class);
    NameSelectionListener listener2 = mock(NameSelectionListener.class);
    sel.addNameSelectionListener(listener);
    sel.addNameSelectionListener(listener2);

    assertEquals(sel.getAvailablePlayer(0), p1);

    sel.setText("de");

    assertEquals(sel.getAvailablePlayer(0), p2);

    sel.selectName();

    verify(listener).nameSelected(p2);
    verify(listener2).nameSelected(p2);

    sel.removeNameSelectionListener(listener);
    sel.setText("ab");
    sel.selectName();

    verifyNoMoreInteractions(listener);
    verify(listener2).nameSelected(p1);
  }
Ejemplo n.º 2
0
  @Test
  public void testPlayerSelectorNameSelection() {
    ArrayList<Player> players = new ArrayList<Player>();
    Player p1 = new Player("Tim Player1", Position.QB, null, 1.0);
    Player p2 = new Player("Tom Player2", Position.QB, null, 1.0);
    Player p3 = new Player("John Player3", Position.QB, null, 1.0);
    players.add(p1);
    players.add(p2);
    players.add(p3);

    PlayerSelector sel = new PlayerSelector(players);

    assertEquals(sel.getNumTotalPlayers(), 3);
    assertEquals(sel.getNumAvailablePlayers(), 3);
    assertEquals(sel.getAvailablePlayer(0), p3);

    sel.setText("T");

    assertEquals(sel.getNumTotalPlayers(), 3);
    assertEquals(sel.getNumAvailablePlayers(), 2);
    assertEquals(sel.getAvailablePlayer(0), p1);

    sel.setText("to");

    assertEquals(sel.getNumTotalPlayers(), 3);
    assertEquals(sel.getNumAvailablePlayers(), 1);
    assertEquals(sel.getAvailablePlayer(0), p2);
  }
Ejemplo n.º 3
0
  /** Generates the insert statements that will be used in testing */
  private static Collection<String> getPrimitiveInsertStatements() {
    ArrayList<String> insertStatements = new ArrayList<String>();

    for (DataType dataType : SAMPLE_DATA.keySet()) {
      String value = helperStringifiedData(dataType);
      insertStatements.add(String.format(PRIMITIVE_INSERT_FORMAT, dataType, value));
    }

    return insertStatements;
  }
Ejemplo n.º 4
0
  /** Generates the table definitions that will be used in testing */
  @Override
  protected Collection<String> getTableDefinitions() {
    ArrayList<String> tableDefinitions = new ArrayList<String>();

    // Create primitive data type definitions
    for (DataType dataType : DATA_TYPE_PRIMITIVES) {
      if (exclude(dataType)) continue;

      tableDefinitions.add(
          String.format("CREATE TABLE %1$s (k %2$s PRIMARY KEY, v %1$s)", dataType, dataType));
    }

    // Create collection data type definitions
    for (DataType.Name dataTypeName : DATA_TYPE_NON_PRIMITIVE_NAMES) {
      // Create MAP data type definitions
      if (dataTypeName == DataType.Name.MAP) {
        for (DataType typeArgument1 : DATA_TYPE_PRIMITIVES) {
          if (exclude(typeArgument1)) continue;

          for (DataType typeArgument2 : DATA_TYPE_PRIMITIVES) {
            if (exclude(typeArgument2)) continue;

            tableDefinitions.add(
                String.format(
                    "CREATE TABLE %1$s_%2$s_%3$s (k %3$s PRIMARY KEY, v %1$s<%2$s, %3$s>)",
                    dataTypeName, typeArgument1, typeArgument2));
          }
        }
        // Create SET and LIST data type definitions
      } else {
        for (DataType typeArgument : DATA_TYPE_PRIMITIVES) {
          if (exclude(typeArgument)) continue;

          tableDefinitions.add(
              String.format(
                  "CREATE TABLE %1$s_%2$s (k %2$s PRIMARY KEY, v %1$s<%2$s>)",
                  dataTypeName, typeArgument));
        }
      }
    }

    return tableDefinitions;
  }
Ejemplo n.º 5
0
  /** Generates the insert statements that will be used in testing */
  @SuppressWarnings("unchecked")
  private static Collection<String> getCollectionInsertStatements() {
    ArrayList<String> insertStatements = new ArrayList<String>();

    String tableName;
    String key;
    String value;
    for (DataType dataType : SAMPLE_COLLECTIONS.keySet()) {
      HashMap<DataType, Object> sampleValueMap =
          (HashMap<DataType, Object>) SAMPLE_COLLECTIONS.get(dataType);

      // Create tableName in form of: DataType_TypeArgument[_TypeArgument]
      tableName = helperGenerateTableName(dataType);

      if (dataType.getName() == DataType.Name.MAP) {
        List<DataType> typeArgument = dataType.getTypeArguments();

        key = helperStringifiedData(typeArgument.get(0));
        value = helperStringifiedData(typeArgument.get(1));

        insertStatements.add(String.format(MAP_INSERT_FORMAT, tableName, key, value));
      } else if (dataType.getName() == DataType.Name.LIST) {
        DataType typeArgument = sampleValueMap.keySet().iterator().next();
        key = helperStringifiedData(typeArgument);

        // Create the value to be a list of the same 5 elements
        value = "[";
        for (int i = 0; i < 5; i++) value += key + ',';
        value = value.substring(0, value.length() - 1) + ']';

        insertStatements.add(String.format(COLLECTION_INSERT_FORMAT, tableName, key, value));
      } else {
        DataType typeArgument = sampleValueMap.keySet().iterator().next();
        key = helperStringifiedData(typeArgument);
        value = '{' + key + '}';

        insertStatements.add(String.format(COLLECTION_INSERT_FORMAT, tableName, key, value));
      }
    }

    return insertStatements;
  }
  /** Tests the maximum persistent search limit imposed by the server. */
  @Test
  public void testMaxPSearch() throws Exception {
    TestCaseUtils.initializeTestBackend(true);
    // Modify the configuration to allow only 1 concurrent persistent search.
    InternalClientConnection conn = getRootConnection();

    LDAPAttribute attr = new LDAPAttribute("ds-cfg-max-psearches", "1");

    ArrayList<RawModification> mods = new ArrayList<>();
    mods.add(new LDAPModification(ModificationType.REPLACE, attr));

    ModifyOperation modifyOperation = conn.processModify(ByteString.valueOf("cn=config"), mods);
    assertEquals(modifyOperation.getResultCode(), ResultCode.SUCCESS);

    // Create a persistent search request.
    Set<PersistentSearchChangeType> changeTypes = EnumSet.of(ADD, DELETE, MODIFY, MODIFY_DN);
    SearchRequest request =
        newSearchRequest(DN.valueOf("o=test"), SearchScope.BASE_OBJECT)
            .setTypesOnly(true)
            .addAttribute("cn")
            .addControl(new PersistentSearchControl(changeTypes, true, true));
    final InternalSearchOperation search = conn.processSearch(request);

    Thread t =
        new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  search.run();
                } catch (Exception ex) {
                }
              }
            },
            "Persistent Search Test");
    t.start();
    t.join(2000);
    // Create a persistent search request.
    final String[] args = {
      "-D",
      "cn=Directory Manager",
      "-w",
      "password",
      "-h",
      "127.0.0.1",
      "-p",
      String.valueOf(TestCaseUtils.getServerLdapPort()),
      "-b",
      "o=test",
      "-s",
      "sub",
      "-C",
      "ps:add:true:true",
      "--noPropertiesFile",
      "(objectClass=*)"
    };

    assertEquals(LDAPSearch.mainSearch(args, false, true, null, System.err), 11);
    // cancel the persisting persistent search.
    search.cancel(new CancelRequest(true, LocalizableMessage.EMPTY));
  }