Ejemplo n.º 1
0
  public void checkSlice(
      String[][] values, Set<KeyColumn> removed, int key, int start, int end, int limit) {
    List<Entry> entries;
    if (limit <= 0)
      entries =
          store.getSlice(
              KeyValueStoreUtil.getBuffer(key),
              KeyValueStoreUtil.getBuffer(start),
              KeyValueStoreUtil.getBuffer(end),
              tx);
    else
      entries =
          store.getSlice(
              KeyValueStoreUtil.getBuffer(key),
              KeyValueStoreUtil.getBuffer(start),
              KeyValueStoreUtil.getBuffer(end),
              limit,
              tx);

    int pos = 0;
    for (int i = start; i < end; i++) {
      if (removed.contains(new KeyColumn(key, i))) continue;
      if (limit <= 0 || pos < limit) {
        Entry entry = entries.get(pos);
        int col = KeyValueStoreUtil.getID(entry.getColumn());
        String str = KeyValueStoreUtil.getString(entry.getValue());
        assertEquals(i, col);
        assertEquals(values[key][i], str);
      }
      pos++;
    }
    assertNotNull(entries);
    if (limit > 0 && pos > limit) assertEquals(limit, entries.size());
    else assertEquals(pos, entries.size());
  }
Ejemplo n.º 2
0
  @Test
  public void testParameterToPairsWhenValueIsCollection() throws Exception {
    Map<String, String> collectionFormatMap = new HashMap<String, String>();
    collectionFormatMap.put("csv", ",");
    collectionFormatMap.put("tsv", "\t");
    collectionFormatMap.put("ssv", " ");
    collectionFormatMap.put("pipes", "\\|");
    collectionFormatMap.put("", ","); // no format, must default to csv
    collectionFormatMap.put("unknown", ","); // all other formats, must default to csv

    String name = "param-a";

    List<Object> values = new ArrayList<Object>();
    values.add("value-a");
    values.add(123);
    values.add(new Date());

    // check for multi separately
    List<Pair> multiPairs = apiClient.parameterToPairs("multi", name, values);
    assertEquals(values.size(), multiPairs.size());

    // all other formats
    for (String collectionFormat : collectionFormatMap.keySet()) {
      List<Pair> pairs = apiClient.parameterToPairs(collectionFormat, name, values);

      assertEquals(1, pairs.size());

      String delimiter = collectionFormatMap.get(collectionFormat);
      String[] pairValueSplit = pairs.get(0).getValue().split(delimiter);

      // must equal input values
      assertEquals(values.size(), pairValueSplit.length);
    }
  }
Ejemplo n.º 3
0
  @Test
  public void testCaseInsensitive() {
    sql2o
        .createQuery(
            "create table testCI(id2 int primary key, value2 varchar(20), sometext varchar(20), valwithgetter varchar(20))")
        .executeUpdate();

    Query query =
        sql2o.createQuery(
            "insert into testCI(id2, value2, sometext, valwithgetter) values(:id, :value, :someText, :valwithgetter)");
    for (int i = 0; i < 20; i++) {
      query
          .addParameter("id", i)
          .addParameter("value", "some text " + i)
          .addParameter("someText", "whatever " + i)
          .addParameter("valwithgetter", "spaz" + i)
          .addToBatch();
    }
    query.executeBatch();

    List<CIEntity> ciEntities =
        sql2o
            .createQuery("select * from testCI")
            .setCaseSensitive(false)
            .executeAndFetch(CIEntity.class);

    assertTrue(ciEntities.size() == 20);

    // test defaultCaseSensitive;
    sql2o.setDefaultCaseSensitive(false);
    List<CIEntity> ciEntities2 =
        sql2o.createQuery("select * from testCI").executeAndFetch(CIEntity.class);
    assertTrue(ciEntities2.size() == 20);
  }
  @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));
  }
Ejemplo n.º 5
0
 @Override
 public void restore() throws TransformException {
   List<Node> references = mod.references();
   ItemList targets = mod.nearest(NodeTarget.class).targets();
   proxies = new ArrayList<Pair<String, Node>>(references.size());
   for (int i = 0; i < references.size(); i++) {
     proxies.add(Pair.of(targets.get(i).query().single("@xml:id").value(), references.get(i)));
   }
 }
Ejemplo n.º 6
0
 @org.junit.Test
 public void testUnmanagedClasspath() {
   List<Object> list1 = WrapUtil.toList("a", new Object());
   assertSame(test, test.unmanagedClasspath(list1.toArray(new Object[list1.size()])));
   assertEquals(list1, test.getUnmanagedClasspath());
   List list2 = WrapUtil.toList(WrapUtil.toList("b", "c"));
   test.unmanagedClasspath(list2.toArray(new Object[list2.size()]));
   assertEquals(GUtil.addLists(list1, GUtil.flatten(list2)), test.getUnmanagedClasspath());
 }
Ejemplo n.º 7
0
  @Test
  public void testGetElementsWithAttributeValue() {
    Document doc = Jsoup.parse("<div style='bold'><p><p><b style></b></p></div>");
    List<Element> els = doc.getElementsByAttributeValue("style", "bold");
    assertEquals(1, els.size());
    assertEquals("div", els.get(0).tagName());

    List<Element> none = doc.getElementsByAttributeValue("style", "none");
    assertEquals(0, none.size());
  }
Ejemplo n.º 8
0
  @Test
  public void canFollowLogfile() throws IOException {
    File tempFile =
        File.createTempFile("commons-io", "", new File(System.getProperty("java.io.tmpdir")));
    tempFile.deleteOnExit();
    System.out.println("Temp file = " + tempFile.getAbsolutePath());
    PrintStream log = new PrintStream(tempFile);
    LogfileFollower follower = new LogfileFollower(tempFile);
    List<String> lines;

    // Empty file:
    lines = follower.newLines();
    assertEquals(0, lines.size());

    // Write two lines:
    log.println("Line 1");
    log.println("Line 2");
    lines = follower.newLines();
    assertEquals(2, lines.size());
    assertEquals("Line 2", lines.get(1));

    // Write one more line:
    log.println("Line 3");
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 3", lines.get(0));

    // Write one and a half line and finish later:
    log.println("Line 4");
    log.print("Line 5 begin");
    lines = follower.newLines();
    assertEquals(1, lines.size());

    // End last line and start a new one:
    log.println(" end");
    log.print("Line 6 begin");
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 5 begin end", lines.get(0));

    // End last line:
    log.println(" end");
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 6 begin end", lines.get(0));

    // A line only missing a newline:
    log.print("Line 7");
    lines = follower.newLines();
    assertEquals(0, lines.size());
    log.println();
    lines = follower.newLines();
    assertEquals(1, lines.size());
    assertEquals("Line 7", lines.get(0));

    // Delete:
    log.close();
    lines = follower.newLines();
    assertEquals(0, lines.size());
  }
Ejemplo n.º 9
0
 @Test
 public void testFindAvailableAttributes1() {
   List<Attribute> attrs =
       attributeService.findAvailableAttributes(AttributeGroupNames.PRODUCT, null); // getByKey all
   assertEquals(24, attrs.size());
   List<String> assignedAttributes = new ArrayList<String>();
   for (Attribute attr : attrs) {
     assignedAttributes.add(attr.getCode());
   }
   attrs =
       attributeService.findAvailableAttributes(AttributeGroupNames.PRODUCT, assignedAttributes);
   assertEquals(0, attrs.size());
 }
Ejemplo n.º 10
0
  private void assertQuery(MongodbQuery<User> query, User... expected) {
    // System.out.println(query.toString());
    List<User> results = query.list();

    assertNotNull(results);
    if (expected == null) {
      assertEquals("Should get empty result", 0, results.size());
      return;
    }
    assertEquals(expected.length, results.size());
    int i = 0;
    for (User u : expected) {
      assertEquals(u, results.get(i++));
    }
  }
Ejemplo n.º 11
0
 @Override
 public void verify() throws TransformException {
   ItemList targets = mod.nearest(NodeTarget.class).targets();
   List<Node> references = mod.references();
   ItemList records = mod.supplementQuery().all("sort-proxy");
   assert targets.size() == references.size();
   assert records.size() == references.size();
   for (int i = 0; i < targets.size(); i++) {
     Node target = targets.get(i).node();
     Node restoredProxy = references.get(i);
     ItemList items = query.runOn(mod.scope(target.query()));
     if (items.size() != 1)
       throw new TransformException(
           "sort by corresponding node must select one node per target, but instead selected "
               + items.size()
               + ": "
               + items);
     Node proxy = items.get(0).node();
     if (!restoredProxy.equals(proxy)) throw new TransformException("computed proxy changed");
     if (!proxy
         .query()
         .single(
             "(count(preceding::*) + count(ancestor::*)) eq xs:integer($_1/@position)",
             records.get(i))
         .booleanValue()) throw new SortingException("computed proxy moved");
   }
 }
Ejemplo n.º 12
0
 @Test
 public void test2() {
   List<Integer> input = new ArrayList<>(Arrays.asList(1, 2, 3));
   List<Integer> output = new ArrayList<>(Arrays.asList(3, 2, 1));
   WithList.reverse(input);
   for (int i = 0; i < input.size(); i++) assertEquals(output.get(i), input.get(i));
 }
  /**
   * Test usage from multiple threads.
   *
   * @throws InterruptedException if interrupted
   */
  public final void testInstancesUsedFromMultipleThreads() throws InterruptedException {
    final Set<Touchable> set = Collections.synchronizedSet(new HashSet<Touchable>());
    final List<Touchable> list = Collections.synchronizedList(new ArrayList<Touchable>());
    final ComponentAdapter componentAdapter =
        new ThreadLocalizing.ThreadLocalized(
            new ConstructorInjection.ConstructorInjector(
                Touchable.class, SimpleTouchable.class, null));
    final Touchable touchable =
        (Touchable) componentAdapter.getComponentInstance(null, ComponentAdapter.NOTHING.class);

    final Thread[] threads = {
      new Thread(new Runner(touchable, list, set), "junit-1"),
      new Thread(new Runner(touchable, list, set), "junit-2"),
      new Thread(new Runner(touchable, list, set), "junit-3"),
    };
    for (int i = threads.length; i-- > 0; ) {
      threads[i].start();
    }
    Thread.sleep(300);
    for (int i = threads.length; i-- > 0; ) {
      synchronized (threads[i]) {
        threads[i].notifyAll();
      }
    }
    Thread.sleep(300);
    for (int i = threads.length; i-- > 0; ) {
      threads[i].interrupt();
    }
    Thread.sleep(300);
    assertEquals(6, list.size());
    assertEquals(3, set.size());
  }
Ejemplo n.º 14
0
  @Test
  public void test_find_children_2() {
    for (boolean left : new boolean[] {true, false}) {
      for (boolean right : new boolean[] {true, false}) {
        List keys = new ArrayList();
        for (int i = 0; i < 100; i += 10) {
          keys.add(i);
        }

        int[] child = new int[keys.size() + (right ? 1 : 0) + (left ? 1 : 0)];
        Arrays.fill(child, 11);
        if (right) child[child.length - 1] = 0;

        BTreeMap.BNode n = new BTreeMap.DirNode(keys.toArray(), left, right, false, mkchild(child));

        for (int i = -10; i < 110; i++) {
          int pos = BTreeKeySerializer.BASIC.findChildren(n, i);
          int expected = (i + (left ? 19 : 9)) / 10;
          expected = Math.max(left ? 1 : 0, expected);
          expected = Math.min(left ? 11 : 10, expected);
          assertEquals("i:" + i + " - l:" + left + " - r:" + right, expected, pos);
        }
      }
    }
  }
 @Test
 public void testNetworkConfig() {
   NetworkConfig networkConfig = config.getNetworkConfig();
   assertNotNull(networkConfig);
   assertEquals(5700, networkConfig.getPort());
   assertFalse(networkConfig.isPortAutoIncrement());
   final Collection<String> allowedPorts = networkConfig.getOutboundPortDefinitions();
   assertEquals(2, allowedPorts.size());
   Iterator portIter = allowedPorts.iterator();
   assertEquals("35000-35100", portIter.next());
   assertEquals("36000,36100", portIter.next());
   assertFalse(networkConfig.getJoin().getMulticastConfig().isEnabled());
   assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeoutSeconds(), 8);
   assertEquals(networkConfig.getJoin().getMulticastConfig().getMulticastTimeToLive(), 16);
   assertFalse(networkConfig.getInterfaces().isEnabled());
   assertEquals(1, networkConfig.getInterfaces().getInterfaces().size());
   assertEquals("10.10.1.*", networkConfig.getInterfaces().getInterfaces().iterator().next());
   TcpIpConfig tcp = networkConfig.getJoin().getTcpIpConfig();
   assertNotNull(tcp);
   assertTrue(tcp.isEnabled());
   assertTrue(networkConfig.getSymmetricEncryptionConfig().isEnabled());
   final List<String> members = tcp.getMembers();
   assertEquals(members.toString(), 2, members.size());
   assertEquals("127.0.0.1:5700", members.get(0));
   assertEquals("127.0.0.1:5701", members.get(1));
   assertEquals("127.0.0.1:5700", tcp.getRequiredMember());
   AwsConfig aws = networkConfig.getJoin().getAwsConfig();
   assertFalse(aws.isEnabled());
   assertEquals("sample-access-key", aws.getAccessKey());
   assertEquals("sample-secret-key", aws.getSecretKey());
   assertEquals("sample-region", aws.getRegion());
   assertEquals("sample-group", aws.getSecurityGroupName());
   assertEquals("sample-tag-key", aws.getTagKey());
   assertEquals("sample-tag-value", aws.getTagValue());
 }
Ejemplo n.º 16
0
  @Test
  public void getSliceRespectsAllBoundsInclusionArguments() throws Exception {
    // Test case where endColumn=startColumn+1
    ByteBuffer key = KeyColumnValueStoreUtil.longToByteBuffer(0);
    ByteBuffer columnBeforeStart = KeyColumnValueStoreUtil.longToByteBuffer(776);
    ByteBuffer columnStart = KeyColumnValueStoreUtil.longToByteBuffer(777);
    ByteBuffer columnEnd = KeyColumnValueStoreUtil.longToByteBuffer(778);
    ByteBuffer columnAfterEnd = KeyColumnValueStoreUtil.longToByteBuffer(779);

    // First insert four test Entries
    TransactionHandle txn = manager.beginTransaction();
    List<Entry> entries =
        Arrays.asList(
            new Entry(columnBeforeStart, columnBeforeStart),
            new Entry(columnStart, columnStart),
            new Entry(columnEnd, columnEnd),
            new Entry(columnAfterEnd, columnAfterEnd));
    store.mutate(key, entries, null, txn);
    txn.commit();

    // getSlice() with only start inclusive
    txn = manager.beginTransaction();
    List<Entry> result = store.getSlice(key, columnStart, columnEnd, txn);
    assertEquals(1, result.size());
    assertEquals(777, result.get(0).getColumn().getLong());
    txn.commit();
  }
Ejemplo n.º 17
0
  @Test
  public void testUtilDate() {
    sql2o
        .createQuery("create table testutildate(id int primary key, d1 datetime, d2 timestamp)")
        .executeUpdate();

    sql2o
        .createQuery("insert into testutildate(id, d1, d2) values(:id, :d1, :d2)")
        .addParameter("id", 1)
        .addParameter("d1", new Date())
        .addParameter("d2", new Date())
        .addToBatch()
        .addParameter("id", 2)
        .addParameter("d1", new Date())
        .addParameter("d2", new Date())
        .addToBatch()
        .addParameter("id", 3)
        .addParameter("d1", new Date())
        .addParameter("d2", new Date())
        .addToBatch()
        .executeBatch();

    List<UtilDateEntity> list =
        sql2o.createQuery("select * from testutildate").executeAndFetch(UtilDateEntity.class);

    assertTrue(list.size() == 3);
  }
Ejemplo n.º 18
0
  @Test
  public void testJodaTime() {

    sql2o
        .createQuery("create table testjoda(id int primary key, joda1 datetime, joda2 datetime)")
        .executeUpdate();

    sql2o
        .createQuery("insert into testjoda(id, joda1, joda2) values(:id, :joda1, :joda2)")
        .addParameter("id", 1)
        .addParameter("joda1", new DateTime())
        .addParameter("joda2", new DateTime().plusDays(-1))
        .addToBatch()
        .addParameter("id", 2)
        .addParameter("joda1", new DateTime().plusYears(1))
        .addParameter("joda2", new DateTime().plusDays(-2))
        .addToBatch()
        .addParameter("id", 3)
        .addParameter("joda1", new DateTime().plusYears(2))
        .addParameter("joda2", new DateTime().plusDays(-3))
        .addToBatch()
        .executeBatch();

    List<JodaEntity> list =
        sql2o.createQuery("select * from testjoda").executeAndFetch(JodaEntity.class);

    assertTrue(list.size() == 3);
    assertTrue(list.get(0).getJoda2().isBeforeNow());
  }
Ejemplo n.º 19
0
  /**
   * Test importing of Clinical Data File.
   *
   * @throws DaoException Database Access Error.
   * @throws IOException IO Error.
   */
  @Test
  @Ignore("To be fixed")
  public void testImportClinicalDataSurvival() throws Exception {

    // TBD: change this to use getResourceAsStream()
    File clinicalFile = new File("target/test-classes/clinical_data.txt");
    ImportClinicalData importClinicalData = new ImportClinicalData(study, clinicalFile);
    importClinicalData.importData();

    LinkedHashSet<String> caseSet = new LinkedHashSet<String>();
    caseSet.add("TCGA-A1-A0SB");
    caseSet.add("TCGA-A1-A0SI");
    caseSet.add("TCGA-A1-A0SE");

    List<Patient> clinicalCaseList =
        DaoClinicalData.getSurvivalData(study.getInternalId(), caseSet);
    assertEquals(3, clinicalCaseList.size());

    Patient clinical0 = clinicalCaseList.get(0);
    assertEquals(new Double(79.04), clinical0.getAgeAtDiagnosis());
    assertEquals("DECEASED", clinical0.getOverallSurvivalStatus());
    assertEquals("Recurred/Progressed", clinical0.getDiseaseFreeSurvivalStatus());
    assertEquals(new Double(43.8), clinical0.getOverallSurvivalMonths());
    assertEquals(new Double(15.05), clinical0.getDiseaseFreeSurvivalMonths());

    Patient clinical1 = clinicalCaseList.get(1);
    assertEquals(new Double(55.53), clinical1.getAgeAtDiagnosis());
    assertEquals("LIVING", clinical1.getOverallSurvivalStatus());
    assertEquals("DiseaseFree", clinical1.getDiseaseFreeSurvivalStatus());
    assertEquals(new Double(49.02), clinical1.getOverallSurvivalMonths());
    assertEquals(new Double(49.02), clinical1.getDiseaseFreeSurvivalMonths());

    Patient clinical2 = clinicalCaseList.get(2);
    assertEquals(null, clinical2.getDiseaseFreeSurvivalMonths());
  }
Ejemplo n.º 20
0
  @Test
  public void testAdd() throws DatabaseException {

    Project census = new Project("census", 2, 3, 4, 5);
    Project births = new Project("births", 6, 7, 8, 9);

    dbProjects.add(census);
    dbProjects.add(births);

    List<Project> all = dbProjects.getAll();
    assertEquals(2, all.size());

    boolean foundAge = false;
    boolean foundPlace = false;

    for (Project p : all) {

      assertFalse(p.getId() == -1);

      if (!foundAge) {
        foundAge = areEqual(p, census, false);
      }
      if (!foundPlace) {
        foundPlace = areEqual(p, births, false);
      }
    }

    assertTrue(foundAge && foundPlace);
  }
  @Test
  public void testCompareSame() throws Exception {

    final Category cat1 = context.mock(Category.class, "cat1");

    context.checking(
        new Expectations() {
          {
            allowing(cat1).getRank();
            will(returnValue(0));
            allowing(cat1).getDisplayName();
            will(returnValue("en#~#Name 1#~#ru#~#Name 1"));
            allowing(cat1).getName();
            will(returnValue("name 1"));
            allowing(cat1).getCategoryId();
            will(returnValue(1L));
          }
        });

    final SortedSet<Category> set = new TreeSet<Category>(new CategoryRankNameComparator());
    set.addAll(Arrays.asList(cat1, cat1));

    final List<Category> list = new ArrayList<Category>(set);
    assertEquals(1, list.size());
    assertTrue(cat1 == list.get(0));
  }
Ejemplo n.º 22
0
 public RelOptTable getTableForMember(List<String> names) {
   final SqlValidatorTable table = catalogReader.getTable(names);
   final RelDataType rowType = table.getRowType();
   final List<RelCollation> collationList = deduceMonotonicity(table);
   if (names.size() < 3) {
     String[] newNames2 = {"CATALOG", "SALES", ""};
     List<String> newNames = new ArrayList<String>();
     int i = 0;
     while (newNames.size() < newNames2.length) {
       newNames.add(i, newNames2[i]);
       ++i;
     }
     names = newNames;
   }
   return createColumnSet(table, names, rowType, collationList);
 }
Ejemplo n.º 23
0
 /** Reads a custom schema. */
 @Test
 public void testCustomSchema() throws IOException {
   final ObjectMapper mapper = mapper();
   JsonRoot root =
       mapper.readValue(
           "{\n"
               + "  version: '1.0',\n"
               + "   schemas: [\n"
               + "     {\n"
               + "       type: 'custom',\n"
               + "       name: 'My Custom Schema',\n"
               + "       factory: 'com.acme.MySchemaFactory',\n"
               + "       operand: {a: 'foo', b: [1, 3.5] }\n"
               + "     }\n"
               + "   ]\n"
               + "}",
           JsonRoot.class);
   assertEquals("1.0", root.version);
   assertEquals(1, root.schemas.size());
   final JsonCustomSchema schema = (JsonCustomSchema) root.schemas.get(0);
   assertEquals("My Custom Schema", schema.name);
   assertEquals("com.acme.MySchemaFactory", schema.factory);
   assertEquals("foo", schema.operand.get("a"));
   assertNull(schema.operand.get("c"));
   assertTrue(schema.operand.get("b") instanceof List);
   final List list = (List) schema.operand.get("b");
   assertEquals(2, list.size());
   assertEquals(1, list.get(0));
   assertEquals(3.5, list.get(1));
 }
Ejemplo n.º 24
0
 public void orderTest3() {
   Customer customer = customerDAO.getCustomerById(2);
   List list = orderService.getOrdersByUsername(customer.getUsername());
   System.out.println("List size :" + list.size());
   for (Object obj : list) {
     System.out.println(obj);
   }
 }
Ejemplo n.º 25
0
  public void testAddElements(int size) {
    List<Integer> src = makeRandomNumberList(size);
    SinglyLinkedList l = new SinglyLinkedList();
    copy(src, l);

    ListIterator it = src.listIterator(src.size());
    while (it.hasPrevious()) assertEquals(it.previous(), l.pop_back());
  }
Ejemplo n.º 26
0
 @Test
 public void mustRepeat() throws Exception {
   final CompletionStage<List<Integer>> f =
       Source.repeat(42).grouped(10000).runWith(Sink.<List<Integer>>head(), materializer);
   final List<Integer> result = f.toCompletableFuture().get(3, TimeUnit.SECONDS);
   assertEquals(result.size(), 10000);
   for (Integer i : result) assertEquals(i, (Integer) 42);
 }
Ejemplo n.º 27
0
  @Test
  public void testGetDataNodes() {
    Document doc = Jsoup.parse("<script>One Two</script> <style>Three Four</style> <p>Fix Six</p>");
    Element script = doc.select("script").first();
    Element style = doc.select("style").first();
    Element p = doc.select("p").first();

    List<DataNode> scriptData = script.dataNodes();
    assertEquals(1, scriptData.size());
    assertEquals("One Two", scriptData.get(0).getWholeData());

    List<DataNode> styleData = style.dataNodes();
    assertEquals(1, styleData.size());
    assertEquals("Three Four", styleData.get(0).getWholeData());

    List<DataNode> pData = p.dataNodes();
    assertEquals(0, pData.size());
  }
Ejemplo n.º 28
0
  @Test
  public void testParameterToPairsWhenValueIsEmptyStrings() throws Exception {

    // single empty string
    List<Pair> pairs = apiClient.parameterToPairs("csv", "param-a", " ");
    assertEquals(1, pairs.size());

    // list of empty strings
    List<String> strs = new ArrayList<String>();
    strs.add(" ");
    strs.add(" ");
    strs.add(" ");

    List<Pair> concatStrings = apiClient.parameterToPairs("csv", "param-a", strs);

    assertEquals(1, concatStrings.size());
    assertFalse(concatStrings.get(0).getValue().isEmpty()); // should contain some delimiters
  }
Ejemplo n.º 29
0
  @Test
  public void testDelete() throws DatabaseException {

    Project census = new Project("census", 2, 3, 4, 5);
    Project births = new Project("births", 6, 7, 8, 9);

    dbProjects.add(census);
    dbProjects.add(births);

    List<Project> all = dbProjects.getAll();
    assertEquals(2, all.size());

    dbProjects.delete(census);
    dbProjects.delete(births);

    all = dbProjects.getAll();
    assertEquals(0, all.size());
  }
Ejemplo n.º 30
0
 @Test
 public void mustWorkFromRange() throws Exception {
   CompletionStage<List<Integer>> f =
       Source.range(0, 10).grouped(20).runWith(Sink.<List<Integer>>head(), materializer);
   final List<Integer> result = f.toCompletableFuture().get(3, TimeUnit.SECONDS);
   assertEquals(11, result.size());
   Integer counter = 0;
   for (Integer i : result) assertEquals(i, counter++);
 }