Skip to content

Commit

Permalink
Updates based on code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Garvey rpgarve committed Jan 7, 2025
1 parent fb4e9e6 commit 8904f9b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main/java/emissary/core/DataObjectFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ public static IBaseDataObject getInstance(final byte[] payload, final String fil
return getInstance(payload, filename, fileTypeAndForm, fileTypeAndForm);
}

/**
* Get an instance of the configured DataObject impl with filename, form, and file type set, and top level document
*
* @param payload the payload data
* @param filename the filename
* @param fileTypeAndForm the form and filetype to set on the IBDO
* @param tld The top level document
* @return an IBDO with the payload, filename, top level document set with the file type and form set to the same value
*/
public static IBaseDataObject getInstance(final byte[] payload, final String filename, final String fileTypeAndForm, IBaseDataObject tld) {
final Object o = Factory.create(clazz, payload, filename, fileTypeAndForm, tld);
return (IBaseDataObject) o;
Expand All @@ -133,6 +142,16 @@ public static IBaseDataObject getInstance(final byte[] payload, final String fil
return (IBaseDataObject) o;
}

/**
* Get an instance of the configured DataObject impl with filename, form, file type, and top level document set
*
* @param payload the payload data
* @param filename the filename
* @param form the form to set on the IBDO
* @param fileType the file type to set on the IBDO
* @param tld The top level document
* @return an IBDO with the payload, filename, file type, form, and top level document set
*/
public static IBaseDataObject getInstance(final byte[] payload, final String filename, final String form, final String fileType,
IBaseDataObject tld) {
final Object o = Factory.create(clazz, payload, filename, form, fileType, tld);
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/emissary/core/BaseDataObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.nio.channels.SeekableByteChannel;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -87,6 +88,25 @@ void testConstructors() {
final BaseDataObject b3 = new BaseDataObject("test".getBytes(), "filename.txt", null);
assertEquals("", b3.currentForm(), "Current form with null in ctor");
assertNotNull(b3.getCreationTimestamp());

final BaseDataObject tld = new BaseDataObject();
final byte[] data = "content".getBytes(StandardCharsets.UTF_8);
final String fileName = "aChild";
final String form = "UNKNOWN";
final BaseDataObject b4 = new BaseDataObject(data, fileName, form, tld);
assertEquals(fileName, b4.getFilename());
assertEquals(form, b4.currentForm());
assertNotNull(b4.getCreationTimestamp());
assertEquals(tld, b4.getTld());

final String fileType = "TEXT";
BaseDataObject b5 = new BaseDataObject(data, fileName, form, fileType, tld);
assertEquals(fileName, b5.getFilename());
assertEquals(form, b5.currentForm());
assertEquals(fileType, b5.getFileType());
assertNotNull(b5.getCreationTimestamp());
assertEquals(tld, b5.getTld());

}

@Test
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/emissary/core/DataObjectFactoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.nio.charset.StandardCharsets;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
import static org.junit.jupiter.api.Assertions.assertNotNull;
Expand Down Expand Up @@ -106,6 +108,27 @@ void testFormAndFileType() {
assertSame(testPayload, extract.data());
}

@Test
void testTLD() {
BaseDataObject tld = new BaseDataObject();
final byte[] data = "content".getBytes(StandardCharsets.UTF_8);
final String fileName = "aChild";
final String form = "UNKNOWN";
IBaseDataObject ibdo = DataObjectFactory.getInstance(data, fileName, form, tld);
assertEquals(fileName, ibdo.getFilename());
assertEquals(form, ibdo.currentForm());
assertNotNull(ibdo.getCreationTimestamp());
assertEquals(tld, ibdo.getTld());

final String fileType = "TEXT";
ibdo = DataObjectFactory.getInstance(data, fileName, form, fileType, tld);
assertEquals(fileName, ibdo.getFilename());
assertEquals(form, ibdo.currentForm());
assertEquals(fileType, ibdo.getFileType());
assertNotNull(ibdo.getCreationTimestamp());
assertEquals(tld, ibdo.getTld());
}

@SuppressWarnings("unused")
public static class MyDataObject extends BaseDataObject {
private static final long serialVersionUID = -2254597461746556210L;
Expand Down

0 comments on commit 8904f9b

Please sign in to comment.