@Test public void getOwaspTop10Report_aggregation_no_cwe() { List<SecurityStandardCategoryStatistics> owaspTop10Report = indexIssuesAndAssertOwaspReport(false); assertThat(owaspTop10Report).allMatch(category -> category.getChildren().isEmpty()); }
@Test public void testGroupsForUserWithCommaInDN() { UserGroupCallback ldapUserGroupCallback = createLdapUserGroupCallback(Configuration.CUSTOM); Assertions.assertThat(ldapUserGroupCallback).isNotNull(); List<String> userGroups = ldapUserGroupCallback.getGroupsForUser("john,jr"); Assertions.assertThat(userGroups).hasSize(1).allMatch(s -> s.equals("manager,eng")); }
@Test public void testSomethingByIterableHandleVoidWithEmptyList() { final List<String> log = new ArrayList<>(); handle.setSqlParser(new LoggingParser(log)); final SomethingByIterableHandleVoid s = handle.attach(SomethingByIterableHandleVoid.class); final List<Something> out = s.get(new ArrayList<>()); assertThat(out).isEmpty(); assertThat(log).hasSize(1).allMatch(e -> e.contains(" where id in ();")); }
@Test public void testSomethingByIterableHandleVoidWithNull() { final List<String> log = new ArrayList<>(); handle.setSqlParser(new LoggingParser(log)); final SomethingByIterableHandleVoid s = handle.attach(SomethingByIterableHandleVoid.class); final List<Something> out = s.get(null); assertThat(out).isEmpty(); assertThat(log).hasSize(1).allMatch(e -> e.contains(" where id in ();")); }
@Test public void testStatementException() { h.execute(CREATE); Throwable e = catchThrowable(h.createUpdate(INSERT_NULL)::execute); assertThat(e) .isInstanceOf(RuntimeException.class) .hasCauseInstanceOf(SQLException.class); assertThat(logger.getRawSql()).containsExactly(CREATE, CREATE, INSERT_NULL, INSERT_NULL); assertThat(logger.getTimings()).hasSize(2).allMatch(IS_POSITIVE); assertThat(logger.getExceptions()).containsExactly((SQLException) e.getCause()); }
@Test public void testPreparedBatchException() { h.execute(CREATE); Throwable e = catchThrowable(h.prepareBatch(INSERT_PREPARED).bindByType(0, null, Integer.class)::execute); assertThat(logger.getRawSql()).containsExactly(CREATE, CREATE, INSERT_PREPARED, INSERT_PREPARED); assertThat(logger.getTimings()).hasSize(2).allMatch(IS_POSITIVE); assertThat(logger.getExceptions()).containsExactly((SQLException) e.getCause()); }
@Test public void testBatchException() { h.execute(CREATE); Throwable e = catchThrowable(h.createBatch().add(INSERT_NULL)::execute); // unfortunately... assertThat(logger.getRawSql()).containsExactly(CREATE, CREATE, null, null); assertThat(logger.getTimings()).hasSize(2).allMatch(IS_POSITIVE); assertThat(logger.getExceptions()).containsExactly((SQLException) e.getCause()); }
@Test public void testStatement() { h.execute(CREATE); h.createUpdate(INSERT).execute(); assertThat(logger.getRawSql()).containsExactly(CREATE, CREATE, INSERT, INSERT); assertThat(logger.getTimings()).hasSize(2).allMatch(IS_POSITIVE); assertThat(logger.getExceptions()).isEmpty(); }
@Test public void testBatch() { h.execute(CREATE); h.createBatch().add(INSERT).execute(); // unfortunately... assertThat(logger.getRawSql()).containsExactly(CREATE, CREATE, null, null); assertThat(logger.getTimings()).hasSize(2).allMatch(IS_POSITIVE); assertThat(logger.getExceptions()).isEmpty(); }
@Test public void testPreparedBatch() { h.execute(CREATE); h.prepareBatch(INSERT_PREPARED).bind(0, 1).execute(); assertThat(logger.getRawSql()).containsExactly(CREATE, CREATE, INSERT_PREPARED, INSERT_PREPARED); assertThat(logger.getTimings()).hasSize(2).allMatch(IS_POSITIVE); assertThat(logger.getExceptions()).isEmpty(); }
@Test public void raceRequest() { List<Long> requests = Collections.synchronizedList(new ArrayList<>()); final Flux<Integer> flux = Flux.range(1, 1000) .doOnRequest(requests::add) .limitRequest(81); BaseSubscriber<Integer> base = new BaseSubscriber<Integer>() { @Override protected void hookOnSubscribe(Subscription subscription) { } }; flux.subscribe(base); for (int i = 0; i < 11; i++) { final int idx = i; RaceTestUtils.race( () -> base.request(idx % 2 == 0 ? 10 : 8), () -> base.request(8) ); } assertThat(requests.stream().mapToLong(l -> l).sum()) .as("total request should match the limitRequest") .isEqualTo(81); assertThat(requests.subList(0, requests.size() - 2)) .allMatch(l -> l % 2 == 0, "all requests except last two are even"); assertThat(requests) .filteredOn(l -> l % 2 == 1) .as("only one odd element toward end") .hasSize(1); }
@Test public void testPreparedBatch() { h.configure(SqlStatements.class, c -> c.setSqlLogger(SqlLogger.NOP_SQL_LOGGER)); h.createUpdate(CREATE).define("x", "foo").execute(); h.configure(SqlStatements.class, c -> c.setSqlLogger(logger)); int id = 0; h.prepareBatch("insert into <x>(bar) values(?)") .define("x", "foo") .bind(0, new Argument() { @Override public void apply(int position, PreparedStatement statement, StatementContext ctx) throws SQLException { statement.setInt(1, id); } @Override public String toString() { return Objects.toString(id); } }) .execute(); assertThat(logger.getAttributes()) .hasSize(2) .allMatch(x -> x.get("x").equals("foo")) .allMatch(x -> x.size() == 1); assertThat(logger.getBindings()).containsExactly(String.valueOf(id), String.valueOf(id)); }
.allMatch(ctx -> ctx.hasKey("thirdPartyContext"));
assertThat(finalizeStats).areAtLeast(5, hasFinalized); assertThat(finalizeStats).allMatch(t3 -> t3.getT2() <= 3, "max 3 windows in flight");
"emitted 2 elements this attempt, 0 repeats left"); assertThat(contexts).allMatch(ctx -> ctx.hasKey("thirdPartyContext"));
assertThat(sansTop25Report).allMatch(category -> category.getChildren().isEmpty());
tuple(SANS_TOP_25_POROUS_DEFENSES, 0L, OptionalInt.empty(), 0L, 0L, 0L)); assertThat(sansTop25Report).allMatch(category -> category.getChildren().isEmpty());
@Test(timeout = 50000) public void testSweepBatchesDownToDeleteBatchSize() { CellsSweeper cellsSweeper = Mockito.mock(CellsSweeper.class); SweepTaskRunner spiedSweepRunner = new SweepTaskRunner(kvs, tsSupplier, tsSupplier, txService, ssm, cellsSweeper); putTwoValuesInEachCell(SMALL_LIST_OF_CELLS); int deleteBatchSize = 1; Pair<List<List<Cell>>, SweepResults> sweptCellsAndSweepResults = runSweep(cellsSweeper, spiedSweepRunner, 8, 8, deleteBatchSize); List<List<Cell>> sweptCells = sweptCellsAndSweepResults.getLhSide(); assertThat(sweptCells).allMatch(list -> list.size() <= 2 * deleteBatchSize); assertThat(Iterables.concat(sweptCells)).containsExactlyElementsOf(SMALL_LIST_OF_CELLS); }