Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gov.hhs.aspr.ms.gcm.simulation.nucleus;

import java.util.Optional;

import gov.hhs.aspr.ms.util.errors.ContractException;

/**
Expand All @@ -16,20 +18,35 @@ boolean isInitialized() {

private boolean initialized;

private DataManagerId dataManagerId;

/**
* Initializes the data manager. This method should only be invoked by the
* simulation. All data manager descendant classes that override this method
* must invoke the super. <br>
*
* @param dataManagerContext
* @throws ContractException {@linkplain NucleusError#DATA_MANAGER_DUPLICATE_INITIALIZATION}
* if init() is invoked more than once
* @throws ContractException
* <ul>
* <li>
* {@linkplain NucleusError#NULL_DATA_MANAGER_CONTEXT}
* if the data manager context is null</li>
* <li>
* {@linkplain NucleusError#DATA_MANAGER_DUPLICATE_INITIALIZATION}
* if init() is invoked more than once</li>
* </ul>
*/
public void init(DataManagerContext dataManagerContext) {
if (dataManagerContext == null) {
throw new ContractException(NucleusError.NULL_DATA_MANAGER_CONTEXT);
}

if (initialized) {
throw new ContractException(NucleusError.DATA_MANAGER_DUPLICATE_INITIALIZATION);
}
initialized = true;

dataManagerId = dataManagerContext.getDataManagerId();
}

/**
Expand All @@ -42,4 +59,12 @@ public String toString() {
return "DataManager[]";
}

/**
* Returns the data manager's id. Result will be present after simulation
* initialization is complete for data managers.
*/
public final Optional<DataManagerId> getDataManagerId() {
return Optional.ofNullable(dataManagerId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public enum NucleusError implements ContractError {
NULL_CLASS_REFERENCE("Null class reference"),//
NULL_DATA_MANAGER("Null data manager"),//
NULL_DATA_MANAGER_CLASS("Null data manager class"),//
NULL_DATA_MANAGER_CONTEXT("Null data manager context"),//
NULL_DATA_MANAGER_CONTEXT_CONSUMER("Null data manager context consumer"),//
NULL_DIMENSION_LEVEL_NAME("Null Dimension level name"), //
NULL_EVENT("Event is null"),//
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
package gov.hhs.aspr.ms.gcm.simulation.nucleus;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;

import gov.hhs.aspr.ms.util.annotations.UnitTestConstructor;
import gov.hhs.aspr.ms.util.annotations.UnitTestMethod;

import gov.hhs.aspr.ms.util.errors.ContractException;

public class AT_DataManager {




@Test
@UnitTestMethod(target = DataManager.class ,name = "init", args = {DataManagerContext.class})
@UnitTestMethod(target = DataManager.class, name = "init", args = { DataManagerContext.class })
public void testInit() {
DataManager dataManager = new DataManager();
assertFalse(dataManager.isInitialized());
dataManager.init(null);
DataManagerContext dataManagerContext = new DataManagerContext(new DataManagerId(5), null);
dataManager.init(dataManagerContext);
assertTrue(dataManager.isInitialized());

ContractException contractException = assertThrows(ContractException.class,
() -> dataManager.init(dataManagerContext));
assertEquals(NucleusError.DATA_MANAGER_DUPLICATE_INITIALIZATION, contractException.getErrorType());

contractException = assertThrows(ContractException.class, () -> {
DataManager dm = new DataManager();
dm.init(null);
});
assertEquals(NucleusError.NULL_DATA_MANAGER_CONTEXT, contractException.getErrorType());

}
@UnitTestConstructor(target = DataManager.class ,args = {})

@UnitTestConstructor(target = DataManager.class, args = {})
@Test
public void testConstructor() {
//nothing to test
// nothing to test
}

@Test
@UnitTestMethod(target = DataManager.class ,name = "toString", args = {})
@UnitTestMethod(target = DataManager.class, name = "toString", args = {})
public void testToString() {
//nothing to test
// nothing to test
}
}