Wanted but not invoked:
provider.startAudit(
"cn=dlakshman,cn=organizational users,o=system,cn=cordys,cn=Audit,o=vanenburg.com",
"XMLS tore",
"/Cordys/Test/test.log",
"UpdateXMLObject",
"o=system,cn=cordys,cn=Audit,o=vanenburg.com",
"Add",
"input",
Cordys.XMLStore.Messages.xmlstoreUpdateEntryStart,
""
);->
at com.cordys.XMLStoreAudit.MockXMLStoreAuditTest.verifyUpdate(MockXMLStoreAuditTest.java:146)
Actually, there were zero interactions with this mock.
at com.cordys.XMLStoreAudit.MockXMLStoreAuditTest.verifyUpdate(MockXMLStoreAuditTest.java:146)
at com.cordys.XMLStoreAudit.MockXMLStoreAuditTest.testAuditXMLStoreCreate(MockXMLStoreAuditTest.java:102)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:46)
at org.junit.rules.RunRules.evaluate(RunRules.java:18)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl.run(JUnit45AndHigherRunnerImpl.java:37)
at org.mockito.runners.MockitoJUnitRunner.run(MockitoJUnitRunner.java:62)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
请帮助我解决上述问题:
我的来源看起来像:
{@RunWith(MockitoJUnitRunner.class)
public class MockXMLStoreAuditTest
{
private static final String XMLSTORE_ARTIFACT_TYPE = "XMLS tore";
private static final String USER_DN = "cn=dlakshman,cn=organizational users,o=system,cn=cordys,cn=Audit,o=vanenburg.com";
private static final String DESCRIPTION = "UpdateXMLObject";
private static final String ORG_DN = "o=system,cn=cordys,cn=Audit,o=vanenburg.com";
public @Rule
SystemPropertySetter propertiesSetter = new SystemPropertySetter();
@Mock
AuditProvider provider;
@Mock
AuditRecording recording;
private Connector connector;
@Before
public void setAuditInspector() throws ExceptionGroup, DirectoryException
{
propertiesSetter.setValue(Audit.AUDITPROVIDER_PROPERTY_NAME, TestAuditProvider.class.getCanonicalName());
TestAuditProvider.auditProvider = provider;
when(provider.isAuditEnabled(anyString(), anyString())).thenReturn(true);
when(provider.startAudit(anyString(),
isA(String.class),
isA(String.class),
isA(String.class),
isA(String.class),
isA(String.class),
anyString(),
isA(IStringResource.class),
anyVararg())).thenReturn(recording);
connector = Connector.getInstance("XMLStore");
if(!connector.isOpen())
{
connector.open();
}
}
@Test
public void testAuditXMLStoreCreate () throws Exception
{
updateXMLObject("Add");
verifyUpdate("Add");
}
private void updateXMLObject ( String operation ) throws DirectoryException, XMLException, TimeoutException,
ExceptionGroup, UnsupportedEncodingException
{
int request = 0;
int response = 0;
try
{
request = connector.createSOAPMethod("http://schemas.cordys.com/1.0/xmlstore", "UpdateXMLObject");
Node.appendToChildren(XPath.getFirstMatch(".//" + operation + "/tuple", null,NomUtil.readResourceAsNom(getClass(), "UpdateXMLRequests.xml")), request);
response = connector.sendAndWait(request);
}
finally
{
Node.delete(request);
Node.delete(response);
}
}
private void verifyUpdate (String actionType)
{
verify(provider).startAudit(USER_DN,
XMLSTORE_ARTIFACT_TYPE,
"/Cordys/Test/test.log",
DESCRIPTION,
ORG_DN,
actionType,
"input",
Messages.XMLSTORE_UPDATE_ENTRY_START,
"");
verify(recording).completed(AuditStatus.COMPLETE, Messages.XMLSTORE_AUDIT_ENTRY_COMPLETE, anyString());
verify(provider).isAuditEnabled(ORG_DN, XMLSTORE_ARTIFACT_TYPE);
}
}
对以下内容的调用将在内部调用startAudit()方法。
response = connector.sendAndWait(request);
我认为它不是调用模拟的startAudit()而是调用实际的startAudit()。
我
答案 0 :(得分:0)
当我直接将模拟的AuditProvider注入连接器时,它可以正常工作。谢谢大家。