Я пытаюсь выполнить тест в DSpace 6, но мой сервис равен Null, когда я запускаю тест. Я тестирую его в сервлете и работаю правильно, но тест не работает
Мой тест:
public class PonderationServiceTest extends AbstractUnitTest {
/** log4j category */
private static final Logger log = Logger.getLogger(RecomendationManualServiceTest.class);
protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
protected InstallItemService installItemService = ContentServiceFactory.getInstance().getInstallItemService();
protected CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService();
protected CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService();
protected EPersonService ePersonService = EPersonServiceFactory.getInstance().getEPersonService();
protected ItemService itemService = ContentServiceFactory.getInstance().getItemService();
private PonderationService ponderationService = //<-- THIS NOT WORK. NullPointerException here !!!!
PonderationServiceFactory.getInstance().getPonderationService();
private Community community;
private Collection collection;
private WorkspaceItem workspaceItem;
private EPerson eperson;
private Item item;
@Before
@Override
public void init() {
super.init();
try {
context.turnOffAuthorisationSystem();
eperson = ePersonService.create(context);
community = communityService.create(null, context);
collection = collectionService.create(context, community);
workspaceItem = workspaceItemService.create(context, collection, false);
item = installItemService.installItem(context, workspaceItem);
context.commit();
}catch (SQLException | AuthorizeException ex)
{
throw new RuntimeException(ex);
}
finally
{
context.restoreAuthSystemState();
}
}
@Test
public void testCreate() throws Exception
{
context.turnOffAuthorisationSystem();
Ponderation ponderation = new Ponderation();
ponderation.setDateCreated(new Date());
ponderation.setValue(5);
ponderation.setItem(item);
ponderation.setEPerson(eperson);
log.info("Ponderation: " + ponderation);
Assert.assertNotNull(ponderation);
// Persist
ponderationService.create(context, ponderation); // <-- NullPointerException
context.complete();
context.restoreAuthSystemState();
}
}
UPDATE
Я запускаю тест:
mvn -pl dspace-api -Dtest=org.dspace.content.PonderationServiceTest -Dmaven.test.skip=false test
и это вывод:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running org.dspace.content.PonderationServiceTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 12.55 sec <<< FAILURE! - in org.dspace.content.PonderationServiceTest
testCreate(org.dspace.content.PonderationServiceTest) Time elapsed: 0.007 sec <<< ERROR!
java.lang.NullPointerException
at org.dspace.content.PonderationServiceTest.<init>(PonderationServiceTest.java:34)
Results :
Tests in error:
PonderationServiceTest.<init>:34 NullPointer
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
Сервисы DSpace работают правильно
Я не могу найти свою ошибку, я не знаю, будет ли какая-то конфигурация, которую я пропускаю
Заранее спасибо.