Skip to content

Commit

Permalink
WIP10 mit interface jetzt - zudem tests anfang!
Browse files Browse the repository at this point in the history
  • Loading branch information
dr0i committed May 3, 2024
1 parent cb5186a commit 60f3b57
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@


import org.metafacture.framework.FluxCommand;
import org.metafacture.framework.ObjectReceiver;
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.DefaultStreamPipe;


/**
* Acts as a wrapper: pipes input to Marc21Encoder which output is piped to Marc21Decoder which output is piped to MarcXmlEncoder.
Expand All @@ -35,7 +32,7 @@
@Out(String.class)
@Description("Encodes MARC21 records as MARCXML. It wraps 'encode-marc21 | decode-marc21 | encode-marcxml ' to generate MARCXML more safely, especially when the building the 'leader'.")
@FluxCommand("encode-marc21xml")
public class Marc21XmlEncoder extends DefaultStreamPipe<ObjectReceiver<String>> implements MarcXmlEncoderInterface {
public class Marc21XmlEncoder extends MarcXmlEncoderAbstract {
private final Marc21Decoder marc21Decoder = new Marc21Decoder();
private final Marc21Encoder marc21Encoder = new Marc21Encoder ();
private final MarcXmlEncoder marcXmlEncoder =new MarcXmlEncoder();
Expand Down Expand Up @@ -81,7 +78,7 @@ protected void onCloseStream() {
}

@Override
protected void onResetStream() {
public void onResetStream() {
marc21Encoder.resetStream();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
@In(StreamReceiver.class)
@Out(String.class)
@FluxCommand("encode-marcxml")
public class MarcXmlEncoder extends DefaultStreamPipe<ObjectReceiver<String>> implements MarcXmlEncoderInterface {
public class MarcXmlEncoder extends MarcXmlEncoderAbstract {

public static final String NAMESPACE_NAME = "marc";
public static final String XML_ENCODING = "UTF-8";
Expand Down Expand Up @@ -282,7 +282,7 @@ else if (!writeLeader(currentEntity, value)) {
}

@Override
protected void onResetStream() {
public void onResetStream() {
if (!atStreamStart) {
writeFooter();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.metafacture.biblio.marc21;

import org.metafacture.framework.ObjectReceiver;
import org.metafacture.framework.helpers.DefaultStreamPipe;

public abstract class MarcXmlEncoderAbstract extends DefaultStreamPipe<ObjectReceiver<String>> implements MarcXmlEncoderInterface {
public void onResetStream(){
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.metafacture.biblio.marc21;

public interface MarcXmlEncoderInterface {

/**
* Sets the flag to decide whether to emit the {@value MarcXmlEncoder#NAMESPACE_NAME}
* namespace
*
* @param emitNamespace true if the namespace is emitted, otherwise false
*/
void setEmitNamespace(final boolean emitNamespace);

/**
* Sets the flag to decide whether to omit the XML declaration.
*
* <strong>Default value: {@value MarcXmlEncoder#OMIT_XML_DECLARATION}</strong>
*
* @param currentOmitXmlDeclaration true if the XML declaration is omitted, otherwise
* false
*/
void omitXmlDeclaration(final boolean currentOmitXmlDeclaration);

/**
* Sets the XML version.
*
* <strong>Default value: {@value MarcXmlEncoder#XML_VERSION}</strong>
*
* @param xmlVersion the XML version
*/
void setXmlVersion(final String xmlVersion);

/**
* Sets the XML encoding.
*
* <strong>Default value: {@value MarcXmlEncoder#XML_ENCODING}</strong>
*
* @param xmlEncoding the XML encoding
*/
void setXmlEncoding(final String xmlEncoding);

/**
* Formats the resulting xml by indentation. Aka "pretty printing".
*
* <strong>Default value: {@value MarcXmlEncoder#PRETTY_PRINTED}</strong>
*
* @param formatted true if formatting is activated, otherwise false
*/
void setFormatted(final boolean formatted);
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void setup() {

marcXmlHandlerWrapper =new Marc21XmlEncoder();

marcXmlHandlerWrapper.setFormatted(true);
marc21Decoder.setReceiver(marcXmlHandlerWrapper);
marcXmlHandlerWrapper.setReceiver(receiver);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
import org.junit.Before;
import org.junit.Test;
import org.metafacture.framework.MetafactureException;
import org.metafacture.framework.ObjectReceiver;
import org.metafacture.framework.helpers.DefaultObjectReceiver;
import org.metafacture.framework.helpers.DefaultStreamPipe;
import org.mockito.Mock;

/**
* Tests for class {@link MarcXmlEncoder}.
Expand All @@ -34,7 +37,7 @@
*
*/

public class MarcXmlEncoderTest {
class MarcXmlEncoderTest {

private static final String XML_DECLARATION = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
private static final String XML_1_DECLARATION = "<?xml version=\"1.1\" encoding=\"UTF-8\"?>";
Expand All @@ -49,11 +52,17 @@ public class MarcXmlEncoderTest {
private static final String RECORD_ID = "92005291";

private static StringBuilder resultCollector;
private static MarcXmlEncoder encoder;
private static MarcXmlEncoderAbstract encoder;

// private DefaultObjectReceiver<String> receiver = new DefaultObjectReceiver<String>();

MarcXmlEncoderTest(MarcXmlEncoderAbstract encoder){
MarcXmlEncoderTest.encoder=encoder;
// encoder.setReceiver(receiver);
setUp();
}
@Before
public void setUp() {
encoder = new MarcXmlEncoder();
encoder.setFormatted(false);
encoder.setReceiver(new DefaultObjectReceiver<String>() {
@Override
Expand All @@ -68,7 +77,7 @@ public void process(final String obj) {
public void tearDown() {
}

private void addOneRecord(MarcXmlEncoder encoder) {
private void addOneRecord(MarcXmlEncoderAbstract encoder) {
encoder.startRecord(RECORD_ID);
encoder.literal("001", RECORD_ID);
encoder.startEntity("010 ");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.metafacture.biblio.marc21;

import org.junit.Test;

public class MarcXmlEncoderWrapperTest {
@Test
public void testMarcXmlEncoder() {
MarcXmlEncoderTest test = new MarcXmlEncoderTest(new MarcXmlEncoder());
test.createAnRecordWithLeader();
MarcXmlEncoderTest test1 = new MarcXmlEncoderTest(new Marc21XmlEncoder());
test1.createAnRecordWithLeader();
}
}

0 comments on commit 60f3b57

Please sign in to comment.