@Test public void select_line_hashes() { dbTester.prepareDbUnit(getClass(), "shared.xml"); ReaderToStringConsumer fn = new ReaderToStringConsumer(); underTest.readLineHashesStream(dbSession, "FILE1_UUID", fn); assertThat(fn.result).isEqualTo("ABC\\nDEF\\nGHI"); }
@Test public void no_line_hashes_on_unknown_file() { dbTester.prepareDbUnit(getClass(), "shared.xml"); ReaderToStringConsumer fn = new ReaderToStringConsumer(); underTest.readLineHashesStream(dbSession, "unknown", fn); assertThat(fn.result).isNull(); }
@Test public void no_line_hashes_when_only_test_data() { dbTester.prepareDbUnit(getClass(), "no_line_hashes_when_only_test_data.xml"); ReaderToStringConsumer fn = new ReaderToStringConsumer(); underTest.readLineHashesStream(dbSession, "FILE1_UUID", fn); assertThat(fn.result).isNull(); }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession session = dbClient.openSession(false)) { String componentKey = request.mandatoryParam("key"); ComponentDto component = componentFinder.getByKey(session, componentKey); userSession.checkComponentPermission(UserRole.USER, component); response.stream().setMediaType("text/plain"); try (OutputStreamWriter writer = new OutputStreamWriter(response.stream().output(), StandardCharsets.UTF_8)) { HashConsumer hashFunction = new HashConsumer(writer, componentKey); dbClient.fileSourceDao().readLineHashesStream(session, component.uuid(), hashFunction); if (!hashFunction.hasData()) { response.noContent(); } } } }
@Test public void readLineHashesStream_does_not_fail_when_lineshashes_is_null() { dbTester.prepareDbUnit(getClass(), "shared.xml"); underTest.insert(dbSession, new FileSourceDto() .setProjectUuid("PRJ_UUID") .setFileUuid("FILE2_UUID") .setBinaryData("FILE2_BINARY_DATA".getBytes()) .setDataHash("FILE2_DATA_HASH") .setSrcHash("FILE2_HASH") .setCreatedAt(1500000000000L) .setUpdatedAt(1500000000001L) .setRevision("123456789")); dbSession.commit(); boolean[] flag = {false}; underTest.readLineHashesStream(dbSession, "FILE2_UUID", new Consumer<Reader>() { @Override public void accept(@Nullable Reader input) { fail("function must never been called since there is no data to read"); flag[0] = true; } }); assertThat(flag[0]).isFalse(); }
@Override public void handle(Request request, Response response) throws Exception { try (DbSession session = dbClient.openSession(false)) { String componentKey = request.mandatoryParam("key"); ComponentDto component = componentFinder.getByKey(session, componentKey); userSession.checkComponentPermission(UserRole.USER, component); response.stream().setMediaType("text/plain"); try (OutputStreamWriter writer = new OutputStreamWriter(response.stream().output(), StandardCharsets.UTF_8)) { HashConsumer hashFunction = new HashConsumer(writer, componentKey); dbClient.fileSourceDao().readLineHashesStream(session, component.uuid(), hashFunction); if (!hashFunction.hasData()) { response.noContent(); } } } }