org.hamcrest.collection.IsIn Java Examples

The following examples show how to use org.hamcrest.collection.IsIn. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeamSqlLineTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testSqlLine_selectFromTable() throws Exception {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  String[] args =
      buildArgs(
          "CREATE EXTERNAL TABLE table_test (col_a VARCHAR, col_b VARCHAR, "
              + "col_c VARCHAR, col_x TINYINT, col_y INT, col_z BIGINT) TYPE 'test';",
          "INSERT INTO table_test VALUES ('a', 'b', 'c', 1, 2, 3);",
          "SELECT * FROM table_test;");

  BeamSqlLine.runSqlLine(args, null, byteArrayOutputStream, null);

  List<List<String>> lines = toLines(byteArrayOutputStream);
  assertThat(
      Arrays.asList(
          Arrays.asList("col_a", "col_b", "col_c", "col_x", "col_y", "col_z"),
          Arrays.asList("a", "b", "c", "1", "2", "3")),
      everyItem(IsIn.isOneOf(lines.toArray())));
}
 
Example #2
Source File: BeamSqlLineTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testSqlLine_GroupBy() throws Exception {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  String[] args =
      buildArgs(
          "CREATE EXTERNAL TABLE table_test (col_a VARCHAR, col_b VARCHAR) TYPE 'test';",
          "INSERT INTO table_test SELECT '3', 'foo';",
          "INSERT INTO table_test SELECT '3', 'bar';",
          "INSERT INTO table_test SELECT '4', 'foo';",
          "SELECT col_a, count(*) FROM table_test GROUP BY col_a;");

  BeamSqlLine.runSqlLine(args, null, byteArrayOutputStream, null);

  List<List<String>> lines = toLines(byteArrayOutputStream);
  assertThat(
      Arrays.asList(Arrays.asList("3", "2"), Arrays.asList("4", "1")),
      everyItem(IsIn.isOneOf(lines.toArray())));
}
 
Example #3
Source File: BeamSqlLineTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testSqlLine_fixedWindow() throws Exception {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  String[] args =
      buildArgs(
          "CREATE EXTERNAL TABLE table_test (col_a VARCHAR, col_b TIMESTAMP) TYPE 'test';",
          "INSERT INTO table_test SELECT '3', TIMESTAMP '2018-07-01 21:26:06';",
          "INSERT INTO table_test SELECT '3', TIMESTAMP '2018-07-01 21:26:07';",
          "SELECT TUMBLE_START(col_b, INTERVAL '1' SECOND), count(*) FROM table_test "
              + "GROUP BY TUMBLE(col_b, INTERVAL '1' SECOND);");

  BeamSqlLine.runSqlLine(args, null, byteArrayOutputStream, null);

  List<List<String>> lines = toLines(byteArrayOutputStream);
  assertThat(
      Arrays.asList(
          Arrays.asList("2018-07-01 21:26:06", "1"), Arrays.asList("2018-07-01 21:26:07", "1")),
      everyItem(IsIn.isOneOf(lines.toArray())));
}
 
Example #4
Source File: BeamSqlLineTest.java    From beam with Apache License 2.0 6 votes vote down vote up
@Test
public void testSqlLine_slidingWindow() throws Exception {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  String[] args =
      buildArgs(
          "CREATE EXTERNAL TABLE table_test (col_a VARCHAR, col_b TIMESTAMP) TYPE 'test';",
          "INSERT INTO table_test SELECT '3', TIMESTAMP '2018-07-01 21:26:06';",
          "INSERT INTO table_test SELECT '4', TIMESTAMP '2018-07-01 21:26:07';",
          "INSERT INTO table_test SELECT '6', TIMESTAMP '2018-07-01 21:26:08';",
          "INSERT INTO table_test SELECT '7', TIMESTAMP '2018-07-01 21:26:09';",
          "SELECT HOP_END(col_b, INTERVAL '1' SECOND, INTERVAL '2' SECOND), count(*) FROM "
              + "table_test GROUP BY HOP(col_b, INTERVAL '1' SECOND, INTERVAL '2' SECOND);");

  BeamSqlLine.runSqlLine(args, null, byteArrayOutputStream, null);

  List<List<String>> lines = toLines(byteArrayOutputStream);
  assertThat(
      Arrays.asList(
          Arrays.asList("2018-07-01 21:26:07", "1"),
          Arrays.asList("2018-07-01 21:26:08", "2"),
          Arrays.asList("2018-07-01 21:26:09", "2"),
          Arrays.asList("2018-07-01 21:26:10", "2"),
          Arrays.asList("2018-07-01 21:26:11", "1")),
      everyItem(IsIn.isOneOf(lines.toArray())));
}
 
Example #5
Source File: ECDSAAlgorithmTest.java    From java-jwt with MIT License 6 votes vote down vote up
static void assertValidJOSESignature(byte[] joseSignature, int numberSize, boolean withRPadding, boolean withSPadding) {
    Assert.assertThat(joseSignature, is(Matchers.notNullValue()));
    Assert.assertThat(numberSize, is(IsIn.oneOf(32, 48, 66)));

    Assert.assertThat(joseSignature.length, is(numberSize * 2));

    byte[] rCopy = Arrays.copyOfRange(joseSignature, 0, numberSize);
    byte[] sCopy = Arrays.copyOfRange(joseSignature, numberSize, numberSize * 2);

    byte[] rNumber = new byte[numberSize];
    byte[] sNumber = new byte[numberSize];
    Arrays.fill(rNumber, (byte) 0x11);
    Arrays.fill(sNumber, (byte) 0x22);
    if (withRPadding) {
        rNumber[0] = (byte) 0;
    }
    if (withSPadding) {
        sNumber[0] = (byte) 0;
    }
    Assert.assertThat(Arrays.equals(rNumber, rCopy), is(true));
    Assert.assertThat(Arrays.equals(sNumber, sCopy), is(true));
}
 
Example #6
Source File: ECDSAAlgorithmTest.java    From java-jwt with MIT License 6 votes vote down vote up
static byte[] createJOSESignature(int numberSize, boolean withRPadding, boolean withSPadding) {
    Assert.assertThat(numberSize, is(IsIn.oneOf(32, 48, 66)));

    byte[] rNumber = new byte[numberSize];
    byte[] sNumber = new byte[numberSize];
    Arrays.fill(rNumber, (byte) 0x11);
    Arrays.fill(sNumber, (byte) 0x22);
    if (withRPadding) {
        rNumber[0] = (byte) 0;
    }
    if (withSPadding) {
        sNumber[0] = (byte) 0;
    }
    byte[] joseSignature = new byte[numberSize * 2];
    System.arraycopy(rNumber, 0, joseSignature, 0, numberSize);
    System.arraycopy(sNumber, 0, joseSignature, numberSize, numberSize);
    return joseSignature;
}
 
Example #7
Source File: AndroidBinaryRDotJavaIntegrationTest.java    From buck with Apache License 2.0 6 votes vote down vote up
private void verifyTrimmedRDotJava(ImmutableSet<String> expected) throws IOException {
  List<String> lines =
      filesystem.readLines(
          BuildTargetPaths.getGenPath(
                  filesystem,
                  BuildTargetFactory.newInstance("//apps/multidex:disassemble_app_r_dot_java"),
                  "%s")
              .resolve("all_r_fields.smali"));

  ImmutableSet.Builder<String> found = ImmutableSet.builder();
  for (String line : lines) {
    Matcher m = SMALI_STATIC_FINAL_INT_PATTERN.matcher(line);
    assertTrue("Could not match line: " + line, m.matches());
    assertThat(m.group(1), IsIn.in(expected));
    found.add(m.group(1));
  }
  assertEquals(expected, found.build());
}
 
Example #8
Source File: BeamSqlLineTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testSqlLine_select() throws Exception {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  String[] args = buildArgs("SELECT 3, 'hello', DATE '2018-05-28';");

  BeamSqlLine.runSqlLine(args, null, byteArrayOutputStream, null);

  List<List<String>> lines = toLines(byteArrayOutputStream);
  assertThat(
      Arrays.asList(Arrays.asList("3", "hello", "2018-05-28")),
      everyItem(IsIn.isOneOf(lines.toArray())));
}
 
Example #9
Source File: BeamSqlLineTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
public void testSqlLine_insertSelect() throws Exception {
  ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
  String[] args =
      buildArgs(
          "CREATE EXTERNAL TABLE table_test (col_a VARCHAR, col_b VARCHAR) TYPE 'test';",
          "INSERT INTO table_test SELECT '3', 'hello';",
          "SELECT * FROM table_test;");

  BeamSqlLine.runSqlLine(args, null, byteArrayOutputStream, null);

  List<List<String>> lines = toLines(byteArrayOutputStream);
  assertThat(
      Arrays.asList(Arrays.asList("3", "hello")), everyItem(IsIn.isOneOf(lines.toArray())));
}
 
Example #10
Source File: BeamSqlLineIT.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore("https://jira.apache.org/jira/browse/BEAM-7582")
public void testSelectFromPubsub() throws Exception {
  String[] args =
      buildArgs(
          String.format(createPubsubTableStatement, eventsTopic.topicPath()),
          setProject,
          "SELECT event_timestamp, taxi_rides.payload.ride_status, taxi_rides.payload.latitude, "
              + "taxi_rides.payload.longitude from taxi_rides LIMIT 3;");

  Future<List<List<String>>> expectedResult = runQueryInBackground(args);
  eventsTopic.checkIfAnySubscriptionExists(project, Duration.standardMinutes(1));

  List<PubsubMessage> messages =
      ImmutableList.of(
          message(
              convertTimestampToMillis("2018-07-01 21:25:20"),
              taxiRideJSON("id1", 1, 40.702, -74.001, 1000, 10, "enroute", 2)),
          message(
              convertTimestampToMillis("2018-07-01 21:26:06"),
              taxiRideJSON("id2", 2, 40.703, -74.002, 1000, 10, "enroute", 4)),
          message(
              convertTimestampToMillis("2018-07-02 13:26:06"),
              taxiRideJSON("id3", 3, 30.0, -72.32324, 2000, 20, "enroute", 7)));

  eventsTopic.publish(messages);

  assertThat(
      Arrays.asList(
          Arrays.asList("2018-07-01 21:25:20", "enroute", "40.702", "-74.001"),
          Arrays.asList("2018-07-01 21:26:06", "enroute", "40.703", "-74.002"),
          Arrays.asList("2018-07-02 13:26:06", "enroute", "30.0", "-72.32324")),
      everyItem(IsIn.isOneOf(expectedResult.get(30, TimeUnit.SECONDS).toArray())));
}
 
Example #11
Source File: BeamSqlLineIT.java    From beam with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore("https://jira.apache.org/jira/browse/BEAM-7582")
public void testFilterForSouthManhattan() throws Exception {
  String[] args =
      buildArgs(
          String.format(createPubsubTableStatement, eventsTopic.topicPath()),
          setProject,
          "SELECT event_timestamp, taxi_rides.payload.ride_status, \n"
              + "taxi_rides.payload.latitude, taxi_rides.payload.longitude from taxi_rides\n"
              + "       WHERE taxi_rides.payload.longitude > -74.747\n"
              + "         AND taxi_rides.payload.longitude < -73.969\n"
              + "         AND taxi_rides.payload.latitude > 40.699\n"
              + "         AND taxi_rides.payload.latitude < 40.720 LIMIT 2;");

  Future<List<List<String>>> expectedResult = runQueryInBackground(args);
  eventsTopic.checkIfAnySubscriptionExists(project, Duration.standardMinutes(1));

  List<PubsubMessage> messages =
      ImmutableList.of(
          message(
              convertTimestampToMillis("2018-07-01 21:25:20"),
              taxiRideJSON("id1", 1, 40.701, -74.001, 1000, 10, "enroute", 2)),
          message(
              convertTimestampToMillis("2018-07-01 21:26:06"),
              taxiRideJSON("id2", 2, 40.702, -74.002, 1000, 10, "enroute", 4)),
          message(
              convertTimestampToMillis("2018-07-02 13:26:06"),
              taxiRideJSON("id3", 3, 30, -72.32324, 2000, 20, "enroute", 7)),
          message(
              convertTimestampToMillis("2018-07-02 14:28:22"),
              taxiRideJSON("id4", 4, 34, -73.32324, 2000, 20, "enroute", 8)));

  eventsTopic.publish(messages);

  assertThat(
      Arrays.asList(
          Arrays.asList("2018-07-01 21:25:20", "enroute", "40.701", "-74.001"),
          Arrays.asList("2018-07-01 21:26:06", "enroute", "40.702", "-74.002")),
      everyItem(IsIn.isOneOf(expectedResult.get(30, TimeUnit.SECONDS).toArray())));
}
 
Example #12
Source File: ECDSAAlgorithmTest.java    From java-jwt with MIT License 5 votes vote down vote up
static void assertValidDERSignature(byte[] derSignature, int numberSize, boolean withRPadding, boolean withSPadding) {
    Assert.assertThat(derSignature, is(Matchers.notNullValue()));
    Assert.assertThat(numberSize, is(IsIn.oneOf(32, 48, 66)));

    int rLength = withRPadding ? numberSize - 1 : numberSize;
    int sLength = withSPadding ? numberSize - 1 : numberSize;
    int totalLength = 2 + (2 + rLength) + (2 + sLength);
    int offset = 0;

    //Start sequence
    Assert.assertThat(derSignature[offset++], is((byte) 0x30));
    if (totalLength > 0x7f) {
        //Add sign before sequence length
        totalLength++;
        Assert.assertThat(derSignature[offset++], is((byte) 0x81));
    }
    //Sequence length
    Assert.assertThat(derSignature[offset++], is((byte) (totalLength - offset)));

    //R number
    Assert.assertThat(derSignature[offset++], is((byte) 0x02));
    Assert.assertThat(derSignature[offset++], is((byte) rLength));
    byte[] rCopy = Arrays.copyOfRange(derSignature, offset, offset + rLength);
    offset += rLength;

    //S number
    Assert.assertThat(derSignature[offset++], is((byte) 0x02));
    Assert.assertThat(derSignature[offset++], is((byte) sLength));
    byte[] sCopy = Arrays.copyOfRange(derSignature, offset, offset + sLength);


    byte[] rNumber = new byte[rLength];
    byte[] sNumber = new byte[sLength];
    Arrays.fill(rNumber, (byte) 0x11);
    Arrays.fill(sNumber, (byte) 0x22);
    Assert.assertThat(Arrays.equals(rNumber, rCopy), is(true));
    Assert.assertThat(Arrays.equals(sNumber, sCopy), is(true));
    Assert.assertThat(derSignature.length, is(totalLength));
}
 
Example #13
Source File: ManagementServiceAsyncOperationsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetJobsRetryAsyncWithProcessListInDifferentDeployments() throws Exception {
  // given a second deployment
  prepareData();
  ProcessDefinitionQuery definitionQuery = engineRule.getRepositoryService().createProcessDefinitionQuery();
  String firstDeploymentId = definitionQuery.processDefinitionVersion(1).singleResult().getDeploymentId();
  String secondDeploymentId = definitionQuery.processDefinitionVersion(2).singleResult().getDeploymentId();

  engineRule.getProcessEngineConfiguration().setInvocationsPerBatchJob(2);

  // when
  Batch batch = managementService.setJobRetriesAsync(processInstanceIds, (ProcessInstanceQuery) null, RETRIES);
  executeSeedJobs(batch, 2);
  // then batch jobs with different deployment ids exist
  List<Job> batchJobs = managementService.createJobQuery().jobDefinitionId(batch.getBatchJobDefinitionId()).list();
  assertThat(batchJobs.size(), is(2));
  assertThat(batchJobs.get(0).getDeploymentId(), IsIn.isOneOf(firstDeploymentId, secondDeploymentId));
  assertThat(batchJobs.get(1).getDeploymentId(), IsIn.isOneOf(firstDeploymentId, secondDeploymentId));
  assertThat(batchJobs.get(0).getDeploymentId(), is(not(batchJobs.get(1).getDeploymentId())));

  // when the batch jobs for the first deployment are executed
  assertThat(getJobCountWithUnchangedRetries(), is(4L));
  getJobIdsByDeployment(batchJobs, firstDeploymentId).forEach(managementService::executeJob);
  // then the retries for jobs from process instances related to the first deployment should be changed
  assertThat(getJobCountWithUnchangedRetries(), is(2L));

  // when the remaining batch jobs are executed
  getJobIdsByDeployment(batchJobs, secondDeploymentId).forEach(managementService::executeJob);
  // then
  assertRetries(ids, RETRIES);
  assertHistoricBatchExists(testRule);
}
 
Example #14
Source File: HistoryServiceAsyncOperationsTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteHistoryProcessInstancesAsyncWithListInDifferentDeployments() throws Exception {
  // given a second deployment
  prepareData();
  ProcessDefinitionQuery definitionQuery = engineRule.getRepositoryService().createProcessDefinitionQuery();
  String firstDeploymentId = definitionQuery.processDefinitionVersion(1).singleResult().getDeploymentId();
  String secondDeploymentId = definitionQuery.processDefinitionVersion(2).singleResult().getDeploymentId();

  engineRule.getProcessEngineConfiguration().setInvocationsPerBatchJob(2);

  // when
  Batch batch = historyService.deleteHistoricProcessInstancesAsync(historicProcessInstances, TEST_REASON);
  executeSeedJobs(batch, 2);
  // then batch jobs with different deployment ids exist
  List<Job> batchJobs = managementService.createJobQuery().jobDefinitionId(batch.getBatchJobDefinitionId()).list();
  assertThat(batchJobs.size(), is(2));
  assertThat(batchJobs.get(0).getDeploymentId(), IsIn.isOneOf(firstDeploymentId, secondDeploymentId));
  assertThat(batchJobs.get(1).getDeploymentId(), IsIn.isOneOf(firstDeploymentId, secondDeploymentId));
  assertThat(batchJobs.get(0).getDeploymentId(), is(not(batchJobs.get(1).getDeploymentId())));
  assertThat(historicProcessInstances.size(), is(4));
  assertThat(getHistoricProcessInstanceCountByDeploymentId(firstDeploymentId), is(2L));
  assertThat(getHistoricProcessInstanceCountByDeploymentId(secondDeploymentId), is(2L));

  // when the batch jobs for the first deployment are executed
  getJobIdsByDeployment(batchJobs, firstDeploymentId).forEach(managementService::executeJob);
  // then the historic process instances related to the first deployment should be deleted
  assertThat(getHistoricProcessInstanceCountByDeploymentId(firstDeploymentId), is(0L));
  // and historic process instances related to the second deployment should not be deleted
  assertThat(getHistoricProcessInstanceCountByDeploymentId(secondDeploymentId), is(2L));

  // when the remaining batch jobs are executed
  getJobIdsByDeployment(batchJobs, secondDeploymentId).forEach(managementService::executeJob);
  // then
  assertNoHistoryForTasks();
  assertHistoricBatchExists(testRule);
  assertAllHistoricProcessInstancesAreDeleted();
}
 
Example #15
Source File: ECDSAAlgorithmTest.java    From java-jwt with MIT License 4 votes vote down vote up
static byte[] createDERSignature(int numberSize, boolean withRPadding, boolean withSPadding) {
    Assert.assertThat(numberSize, is(IsIn.oneOf(32, 48, 66)));

    int rLength = withRPadding ? numberSize - 1 : numberSize;
    int sLength = withSPadding ? numberSize - 1 : numberSize;
    int totalLength = 2 + (2 + rLength) + (2 + sLength);

    byte[] rNumber = new byte[rLength];
    byte[] sNumber = new byte[sLength];
    Arrays.fill(rNumber, (byte) 0x11);
    Arrays.fill(sNumber, (byte) 0x22);

    byte[] derSignature;
    int offset = 0;
    if (totalLength > 0x7f) {
        totalLength++;
        derSignature = new byte[totalLength];
        //Start sequence and sign
        derSignature[offset++] = (byte) 0x30;
        derSignature[offset++] = (byte) 0x81;
    } else {
        derSignature = new byte[totalLength];
        //Start sequence
        derSignature[offset++] = (byte) 0x30;
    }

    //Sequence length
    derSignature[offset++] = (byte) (totalLength - offset);

    //R number
    derSignature[offset++] = (byte) 0x02;
    derSignature[offset++] = (byte) rLength;
    System.arraycopy(rNumber, 0, derSignature, offset, rLength);
    offset += rLength;

    //S number
    derSignature[offset++] = (byte) 0x02;
    derSignature[offset++] = (byte) sLength;
    System.arraycopy(sNumber, 0, derSignature, offset, sLength);

    return derSignature;
}