X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fnetconf%2Fconfig-persister-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fnetconf%2Fpersist%2Fimpl%2Fosgi%2FConfigPersisterTest.java;h=493ecd9250262959e78523c4ed1dc49c7d177474;hp=b722496142e4f2014b82e776317488e02ddb4527;hb=721b580748cb93b3dac952ff1f111d0ab0da0c79;hpb=88f3fac27f5dbc4043cdeadacaca34bd6f57c854 diff --git a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterTest.java b/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterTest.java index b722496142..493ecd9250 100644 --- a/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterTest.java +++ b/opendaylight/netconf/config-persister-impl/src/test/java/org/opendaylight/controller/netconf/persist/impl/osgi/ConfigPersisterTest.java @@ -33,6 +33,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; public class ConfigPersisterTest { @@ -113,26 +114,29 @@ public class ConfigPersisterTest { @Test public void testPersisterConflictingVersionException() throws Exception { setUpContextAndStartPersister("cap1"); - NetconfOperationService service = getWorkingService(getConflictVersionDocument()); - doReturn(service).when(ctx.serviceFactory).createService(anyString()); + + doReturn(getConflictingService()).when(ctx.serviceFactory).createService(anyString()); Thread.sleep(2000); handler.assertException(IllegalStateException.class, "Max wait for conflicting version stabilization timeout"); } - private Document getConflictVersionDocument() throws SAXException, IOException { - return XmlUtil.readXmlToDocument( - "\n" + - "" + - ConflictingVersionException.class.getCanonicalName() + - "\n" + - "" - ); + private NetconfOperationService getConflictingService() throws Exception { + NetconfOperationService service = getWorkingService(getOKDocument()); + ConflictingVersionException cve = new ConflictingVersionException(""); + try { + NetconfDocumentedException.wrap(cve); + throw new AssertionError("Should throw an exception"); + }catch(NetconfDocumentedException e) { + NetconfOperation mockedOperation = service.getNetconfOperations().iterator().next(); + doThrow(e).when(mockedOperation).handle(any(Document.class), any(NetconfOperationChainedExecution.class)); + return service; + } } @Test public void testSuccessConflictingVersionException() throws Exception { setUpContextAndStartPersister("cap1"); - doReturn(getWorkingService(getConflictVersionDocument())).when(ctx.serviceFactory).createService(anyString()); + doReturn(getConflictingService()).when(ctx.serviceFactory).createService(anyString()); Thread.sleep(500); // working service: logger.info("Switching to working service **");