Java 在DSpace 6单元测试中包括我自己的服务
我试图在DSpace 6中进行测试,但运行测试时,我的服务为空。我在servlet中测试它并正常工作,但测试不起作用 我的测试:Java 在DSpace 6单元测试中包括我自己的服务,java,junit,dspace,Java,Junit,Dspace,我试图在DSpace 6中进行测试,但运行测试时,我的服务为空。我在servlet中测试它并正常工作,但测试不起作用 我的测试: public class PonderationServiceTest extends AbstractUnitTest { /** log4j category */ private static final Logger log = Logger.getLogger(RecomendationManualServiceTest.class);
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();
}
}
这是输出:
-------------------------------------------------------
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
-------------------------------------------------------
T T S T S
-------------------------------------------------------
运行org.dspace.content.PoundationServiceTest
测试运行:1,失败:0,错误:1,跳过:0,所用时间:12.55秒请提供有关什么不起作用的详细信息。你有什么错误?@AdiBradfield谢谢你的快速回答,我编辑了我的问题。
-------------------------------------------------------
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