package org.sagebionetworks.repo.model.dbo.persistence;

import static org.junit.Assert.assertEquals;

import java.sql.Timestamp;
import java.time.LocalDateTime;

import org.junit.Test;
import org.sagebionetworks.repo.model.ObjectType;
import org.sagebionetworks.repo.model.doi.DoiStatus;
public class DBODoiTest {

	@Test
	public void translateToNonNullVersion() {
		DBODoi doi = new DBODoi();
		doi.setId(1000L);
		doi.setCreatedOn(Timestamp.valueOf(LocalDateTime.now()));
		doi.setUpdatedOn(Timestamp.valueOf(LocalDateTime.now()));
		doi.setCreatedBy(0L);
		doi.setETag("some etag");
		doi.setDoiStatus(DoiStatus.IN_PROCESS);
		doi.setObjectId(1234L);
		doi.setObjectType(ObjectType.ENTITY);
		doi.setObjectVersion(null);

		// Method under test
		DBODoi newDoi = doi.getTranslator().createDatabaseObjectFromBackup(doi);
		assertEquals((Long) (-1L), newDoi.getObjectVersion());
		assertEquals(doi.getCreatedBy(), newDoi.getCreatedBy());
		assertEquals(doi.getObjectId(), newDoi.getObjectId());
		assertEquals(doi.getObjectType(), newDoi.getObjectType());
		assertEquals(doi.getETag(), newDoi.getETag());
		assertEquals(doi.getDoiStatus(), newDoi.getDoiStatus());
		assertEquals(doi.getCreatedOn(), newDoi.getCreatedOn());
		assertEquals(doi.getUpdatedOn(), newDoi.getUpdatedOn());
	}
}

@@ -333,33 +333,35 @@
 oid 
-translateToNonNullVersion
+setNullUpdatedByToCreatedBy
 () %7B
@@ -522,32 +522,58 @@
 teTime.now()));%0A
+%09%09doi.setUpdatedBy(null);%0A
 %09%09doi.setCreated
@@ -739,20 +739,19 @@
 Version(
-null
+-1L
 );%0A%0A%09%09//
@@ -844,16 +844,17 @@
 p(doi);%0A
+%0A
 %09%09assert
@@ -864,19 +864,88 @@
 als(
-(Long) (-1L
+doi.getCreatedBy(), newDoi.getUpdatedBy());%0A%09%09assertEquals(doi.getObjectVersion(
 ), n

add dbo migration test