0
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()。
我
您是否驗證過連接器實際上使用TestAuditProvider?這就是人們不喜歡全系統單身類型的原因。使用[依賴注入](http://en.wikipedia.org/wiki/Dependency_injection)將清除此代碼。然後,您可以直接將您的模擬AuditProvider注入連接器。 – rmhartog
在這種情況下,連接器是**不使用TestAuditProvider **,它是**使用實際的AuditProvider **。這是我所關心的。 **如何使連接器使用TestAuditProvider?**。我如何**直接將**我的模擬AuditProvider注入連接器? – Ramesh
對startAudit()的實際調用在某種方法中稱爲** UpdateXMLObject **類。在調用** connector.sendAndWait(request)**之後,碰巧調用了很多內部類,方法和** finally **達到** UpdateXMLObject **。還有一個由* UpdateXMLObject **擴展的abstarct類** XDSBasedXMLStore **。再次有實用程序類** XMLStoreAuditManager **,其對象在** XDSBasedXMLStore **抽象類中聚合。因此,擴展** XDSBasedXMLStore **的所有類將具有** XMLStoreAuditManager **對象並調用startAudit()方法。 – Ramesh