Merge "Fix race conditions between config-manager and persister."
[controller.git] / opendaylight / netconf / config-persister-impl / src / test / java / org / opendaylight / controller / netconf / persist / impl / ConfigPersisterNotificationHandlerTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.netconf.persist.impl;
9
10 import org.junit.Test;
11 import org.opendaylight.controller.config.api.ConflictingVersionException;
12 import org.opendaylight.controller.netconf.api.NetconfMessage;
13 import org.opendaylight.controller.netconf.util.xml.XmlElement;
14 import org.opendaylight.controller.netconf.util.xml.XmlUtil;
15 import org.w3c.dom.Document;
16
17 import static org.junit.Assert.assertThat;
18 import static org.junit.Assert.fail;
19 import static org.junit.matchers.JUnitMatchers.containsString;
20
21 public class ConfigPersisterNotificationHandlerTest {
22
23     @Test
24     public void testConflictingVersionDetection() throws Exception {
25         Document document = XmlUtil.readXmlToDocument(getClass().getResourceAsStream("/conflictingVersionResponse.xml"));
26         try{
27             ConfigPersisterNotificationHandler.checkIsOk(XmlElement.fromDomDocument(document).getOnlyChildElement(), new NetconfMessage(document));
28             fail();
29         }catch(ConflictingVersionException e){
30             assertThat(e.getMessage(), containsString("Optimistic lock failed. Expected parent version 21, was 18"));
31         }
32     }
33
34 }