Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 495-objectSleep
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasNx committed Oct 17, 2024
2 parents 489a74d + bdb93ad commit 7b6e932
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 20 deletions.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=1541fa36599e12857140465f3c91a97409b4512501c26f9631fb113e392c5bd1
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip
distributionSha256Sum=31c55713e40233a8303827ceb42ca48a47267a0ad4bab9177123121e71524c26
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ public void literal(final String name, final String value) {

@Override
protected void onResetStream() {
pipe.resetStream();
encoder.onResetStream();
}

@Override
Expand Down Expand Up @@ -372,7 +372,9 @@ protected void onResetStream() {

@Override
protected void onCloseStream() {
writeFooter();
if (!atStreamStart) {
writeFooter();
}
sendAndClearData();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class MarcXmlEncoderTest {
private static final String RECORD_ID = "92005291";

private static StringBuilder resultCollector;
private static int resultCollectorsResetStreamCount;
private static MarcXmlEncoder encoder;

@Before
Expand All @@ -62,6 +63,11 @@ public void setUp() {
public void process(final String obj) {
resultCollector.append(obj);
}
@Override
public void resetStream() {
++resultCollectorsResetStreamCount;
}

});
resultCollector = new StringBuilder();
}
Expand Down Expand Up @@ -389,4 +395,26 @@ public void shouldNotEncodeNestedTypeLiteralAsAttribute() {
assertEquals(expected, actual);
}

@Test
public void issue543_shouldNotWriteFooterWhenRecordIsEmpty() {
encoder.closeStream();
String actual = resultCollector.toString();
assertTrue(actual.isEmpty());
}

@Test
public void issue543_shouldOnlyResetStreamOnce() {
resultCollectorsResetStreamCount = 0;
encoder.resetStream();
assertEquals(resultCollectorsResetStreamCount, 1);
}

@Test
public void issue543_shouldOnlyResetStreamOnceUsingWrapper() {
resultCollectorsResetStreamCount = 0;
encoder.setEnsureCorrectMarc21Xml(true);
encoder.resetStream();
assertEquals(resultCollectorsResetStreamCount, 1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ public void setCompression(final String compression) {
@Override
public void process(final T obj) {
assert !closed;
try {
if (firstObject) {
getWriter().write(getHeader());
firstObject = false;
final String objStr = obj.toString();
if (!objStr.isEmpty()) {
try {
if (firstObject) {
getWriter().write(getHeader());
firstObject = false;
}
else {
getWriter().write(getSeparator());
}
getWriter().write(objStr);
}
else {
getWriter().write(getSeparator());
catch (final IOException e) {
throw new MetafactureException(e);
}
getWriter().write(obj.toString());
}
catch (final IOException e) {
throw new MetafactureException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.metafacture.commons.ResourceUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
Expand All @@ -28,12 +34,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.metafacture.commons.ResourceUtil;

/**
* Tests for class {@link ObjectFileWriter}.
*
Expand Down Expand Up @@ -105,6 +105,14 @@ public void shouldIncrementCountOnResetBeforeStartingNewFile() throws IOExceptio
assertTrue(new File(tempFolder.getRoot(), "test-1").exists());
}

@Test
public void issue543_shouldResultEmptyWhenNothingIsProcessed() throws IOException {
writer.process("");
writer.closeStream();

assertOutput("");
}

@Override
protected ConfigurableObjectWriter<String> getWriter() {
return writer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.metafacture.framework.FluxCommand;
import org.metafacture.framework.StreamReceiver;
import org.metafacture.framework.annotations.Description;
import org.metafacture.framework.annotations.In;
import org.metafacture.framework.annotations.Out;
import org.metafacture.framework.helpers.DefaultObjectPipe;

Expand All @@ -29,6 +30,7 @@
* @author Christoph Böhme, Fabian Steeg
*/
@Description("Outputs a record containing the input object as literal")
@In(Object.class)
@Out(StreamReceiver.class)
@FluxCommand("object-to-literal")
public final class ObjectToLiteral<T> extends
Expand Down

0 comments on commit 7b6e932

Please sign in to comment.