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;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.opendaylight.controller.config.util.xml.XmlUtil.readXmlToElement;
import static org.opendaylight.controller.netconf.util.test.XmlUnitUtil.assertContainsElement;
import static org.opendaylight.controller.netconf.util.test.XmlUnitUtil.assertContainsElementWithText;
-import static org.opendaylight.controller.netconf.util.xml.XmlUtil.readXmlToElement;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import org.opendaylight.controller.config.api.ValidationException;
import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface;
import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation;
+import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade;
+import org.opendaylight.controller.config.facade.xml.osgi.EnumResolver;
+import org.opendaylight.controller.config.facade.xml.osgi.YangStoreService;
+import org.opendaylight.controller.config.facade.xml.transactions.TransactionProvider;
import org.opendaylight.controller.config.manager.impl.AbstractConfigTest;
import org.opendaylight.controller.config.manager.impl.factoriesresolver.HardcodedModuleFactoriesResolver;
import org.opendaylight.controller.config.util.ConfigTransactionJMXClient;
+import org.opendaylight.controller.config.util.xml.DocumentedException;
+import org.opendaylight.controller.config.util.xml.XmlMappingConstants;
+import org.opendaylight.controller.config.util.xml.XmlUtil;
import org.opendaylight.controller.config.yang.test.impl.ComplexDtoBInner;
import org.opendaylight.controller.config.yang.test.impl.ComplexList;
import org.opendaylight.controller.config.yang.test.impl.Deep;
import org.opendaylight.controller.config.yang.test.impl.Peers;
import org.opendaylight.controller.config.yang.test.impl.TestImplModuleFactory;
import org.opendaylight.controller.config.yangjmxgenerator.ModuleMXBeanEntry;
-import org.opendaylight.controller.netconf.api.NetconfDocumentedException;
-import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.Commit;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.DiscardChanges;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.Lock;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.get.Get;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.getconfig.GetConfig;
import org.opendaylight.controller.netconf.confignetconfconnector.operations.runtimerpc.RuntimeRpc;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.EnumResolver;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreContext;
-import org.opendaylight.controller.netconf.confignetconfconnector.osgi.YangStoreService;
-import org.opendaylight.controller.netconf.confignetconfconnector.transactions.TransactionProvider;
import org.opendaylight.controller.netconf.impl.NetconfServerSession;
import org.opendaylight.controller.netconf.impl.NetconfServerSessionListener;
import org.opendaylight.controller.netconf.impl.mapping.operations.DefaultCloseSession;
import org.opendaylight.controller.netconf.util.messages.NetconfHelloMessageAdditionalHeader;
import org.opendaylight.controller.netconf.util.messages.NetconfMessageUtil;
import org.opendaylight.controller.netconf.util.test.XmlFileLoader;
-import org.opendaylight.controller.netconf.util.xml.XmlUtil;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity1;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.test.types.rev131127.TestIdentity2;
import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
private TestImplModuleFactory factory4;
@Mock
- YangStoreContext yangStoreSnapshot;
+ YangStoreService yangStoreSnapshot;
@Mock
NetconfOperationRouter netconfOperationRouter;
@Mock
private TransactionProvider transactionProvider;
+ private ConfigSubsystemFacade configSubsystemFacade;
+
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
doNothing().when(mockedContext).addServiceListener(any(ServiceListener.class), anyString());
doReturn(new ServiceReference<?>[]{}).when(mockedContext).getServiceReferences(anyString(), anyString());
+ doReturn(yangStoreSnapshot).when(yangStoreSnapshot).getCurrentSnapshot();
doReturn(getMbes()).when(this.yangStoreSnapshot).getModuleMXBeanEntryMap();
doReturn(getModules()).when(this.yangStoreSnapshot).getModules();
doReturn(new EnumResolver() {
this.factory3, factory4));
transactionProvider = new TransactionProvider(this.configRegistryClient, NETCONF_SESSION_ID);
+
+ configSubsystemFacade = new ConfigSubsystemFacade(configRegistryClient, configRegistryClient, yangStoreSnapshot, "mapping-test");
}
private ObjectName createModule(final String instanceName) throws InstanceAlreadyExistsException, InstanceNotFoundException, URISyntaxException, ValidationException, ConflictingVersionException {
"ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
"ref_from_code_to_instance-from-code_1", "ref_dep_user_another"));
+ edit("netconfMessages/editConfig_removeServiceNameOnTest.xml");
+ config = getConfigCandidate();
+ assertCorrectServiceNames(config, Sets.newHashSet("user_to_instance_from_code", "ref_dep_user",
+ "ref_dep_user_two", "ref_from_code_to_instance-from-code_dep_1",
+ "ref_from_code_to_instance-from-code_1"));
+
+ try {
+ edit("netconfMessages/editConfig_removeServiceNameOnTest.xml");
+ fail("Should've failed, non-existing service instance");
+ } catch (DocumentedException e) {
+ assertEquals(e.getErrorSeverity(), DocumentedException.ErrorSeverity.error);
+ assertEquals(e.getErrorTag(), DocumentedException.ErrorTag.operation_failed);
+ assertEquals(e.getErrorType(), DocumentedException.ErrorType.application);
+ }
+
edit("netconfMessages/editConfig_replace_default.xml");
config = getConfigCandidate();
assertCorrectServiceNames(config, Collections.<String>emptySet());
}
- private void closeSession() throws NetconfDocumentedException, ParserConfigurationException, SAXException,
- IOException {
+ private void closeSession() throws ParserConfigurationException, SAXException,
+ IOException, DocumentedException {
final Channel channel = mock(Channel.class);
doReturn("channel").when(channel).toString();
final NetconfServerSessionListener listener = mock(NetconfServerSessionListener.class);
}
private void edit(String resource) throws ParserConfigurationException, SAXException, IOException,
- NetconfDocumentedException {
- EditConfig editOp = new EditConfig(yangStoreSnapshot, transactionProvider, configRegistryClient,
- NETCONF_SESSION_ID);
+ DocumentedException {
+ EditConfig editOp = new EditConfig(configSubsystemFacade, NETCONF_SESSION_ID);
executeOp(editOp, resource);
}
- private void commit() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
- Commit commitOp = new Commit(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
+ private void commit() throws ParserConfigurationException, SAXException, IOException, DocumentedException {
+ Commit commitOp = new Commit(configSubsystemFacade, NETCONF_SESSION_ID);
executeOp(commitOp, "netconfMessages/commit.xml");
}
- private Document lockCandidate() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
+ private Document lockCandidate() throws ParserConfigurationException, SAXException, IOException, DocumentedException {
Lock commitOp = new Lock(NETCONF_SESSION_ID);
return executeOp(commitOp, "netconfMessages/lock.xml");
}
- private Document unlockCandidate() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
+ private Document unlockCandidate() throws ParserConfigurationException, SAXException, IOException, DocumentedException {
UnLock commitOp = new UnLock(NETCONF_SESSION_ID);
return executeOp(commitOp, "netconfMessages/unlock.xml");
}
private Document getConfigCandidate() throws ParserConfigurationException, SAXException, IOException,
- NetconfDocumentedException {
- GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
- configRegistryClient, NETCONF_SESSION_ID);
+ DocumentedException {
+ GetConfig getConfigOp = new GetConfig(configSubsystemFacade, Optional.<String> absent(), NETCONF_SESSION_ID);
return executeOp(getConfigOp, "netconfMessages/getConfig_candidate.xml");
}
private Document getConfigRunning() throws ParserConfigurationException, SAXException, IOException,
- NetconfDocumentedException {
- GetConfig getConfigOp = new GetConfig(yangStoreSnapshot, Optional.<String> absent(), transactionProvider,
- configRegistryClient, NETCONF_SESSION_ID);
+ DocumentedException {
+ GetConfig getConfigOp = new GetConfig(configSubsystemFacade, Optional.<String> absent(), NETCONF_SESSION_ID);
return executeOp(getConfigOp, "netconfMessages/getConfig.xml");
}
@Ignore("second edit message corrupted")
- @Test(expected = NetconfDocumentedException.class)
+ @Test(expected = DocumentedException.class)
public void testConfigNetconfReplaceDefaultEx() throws Exception {
createModule(INSTANCE_NAME);
try {
edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespaces.xml");
fail();
- } catch (NetconfDocumentedException e) {
+ } catch (DocumentedException e) {
String message = e.getMessage();
assertContainsString(message, "Element simpleInt present multiple times with different namespaces");
assertContainsString(message, TEST_NAMESPACE);
- assertContainsString(message, XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
+ assertContainsString(message, XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
}
}
try {
edit("netconfMessages/namespaces/editConfig_differentNamespaceTO.xml");
fail();
- } catch (NetconfDocumentedException e) {
+ } catch (DocumentedException e) {
String message = e.getMessage();
assertContainsString(message, "Unrecognised elements");
assertContainsString(message, "simple-int2");
try {
edit("netconfMessages/namespaces/editConfig_sameAttrDifferentNamespacesList.xml");
fail();
- } catch (NetconfDocumentedException e) {
+ } catch (DocumentedException e) {
String message = e.getMessage();
assertContainsString(message, "Element allow-user present multiple times with different namespaces");
assertContainsString(message, TEST_NAMESPACE);
- assertContainsString(message, XmlNetconfConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
+ assertContainsString(message, XmlMappingConstants.URN_OPENDAYLIGHT_PARAMS_XML_NS_YANG_CONTROLLER_CONFIG);
}
}
}
// TODO add <modules operation="replace"> functionality
- @Test(expected = NetconfDocumentedException.class)
+ @Test(expected = DocumentedException.class)
public void testConfigNetconfReplaceModuleEx() throws Exception {
createModule(INSTANCE_NAME);
LOG.info("Reading {}", file);
try {
edit(file);
- } catch (NetconfDocumentedException e) {
+ } catch (DocumentedException e) {
assertContainsString(e.getMessage(), "Unrecognised elements");
assertContainsString(e.getMessage(), "unknownAttribute");
continue;
assertEquals(3 + 3, afterReplace);
}
- @Test(expected = NetconfDocumentedException.class)
+ @Test(expected = DocumentedException.class)
public void testEx() throws Exception {
commit();
@Test
public void testEx2() throws Exception {
+ //check abort before tx creation
assertContainsElement(discard(), readXmlToElement("<ok xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
+
+ //check abort after tx creation
+ edit("netconfMessages/editConfig.xml");
+ assertContainsElement(discard(), readXmlToElement("<ok xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"/>"));
+ }
+
+ @Test
+ public void testFailedDiscardChangesAbort() throws Exception {
+ final ConfigSubsystemFacade facade = mock(ConfigSubsystemFacade.class);
+ doThrow(new RuntimeException("Mocked runtime exception, Abort has to fail")).when(facade).abortConfiguration();
+
+ DiscardChanges discardOp = new DiscardChanges(facade, NETCONF_SESSION_ID);
+
+ try {
+ executeOp(discardOp, "netconfMessages/discardChanges.xml");
+ fail("Should've failed, abort on mocked is supposed to throw RuntimeException");
+ } catch (DocumentedException e) {
+ assertTrue(e.getErrorTag() == DocumentedException.ErrorTag.operation_failed);
+ assertTrue(e.getErrorSeverity() == DocumentedException.ErrorSeverity.error);
+ assertTrue(e.getErrorType() == DocumentedException.ErrorType.application);
+ }
}
- private Document discard() throws ParserConfigurationException, SAXException, IOException, NetconfDocumentedException {
- DiscardChanges discardOp = new DiscardChanges(transactionProvider, configRegistryClient, NETCONF_SESSION_ID);
+ private Document discard() throws ParserConfigurationException, SAXException, IOException, DocumentedException {
+ DiscardChanges discardOp = new DiscardChanges(configSubsystemFacade, NETCONF_SESSION_ID);
return executeOp(discardOp, "netconfMessages/discardChanges.xml");
}
public SchemaContext getSchemaContext() {
return schemaContext ;
}
- }, mockedContext);
+ });
final BindingRuntimeContext bindingRuntimeContext = mock(BindingRuntimeContext.class);
doReturn(getEnumMapping()).when(bindingRuntimeContext).getEnumMapping(any(Class.class));
yangStoreService.refresh(bindingRuntimeContext);
assertEquals(8, getElementsSize(response, "deep4"));
// TODO assert keys
- RuntimeRpc netconf = new RuntimeRpc(yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
+ RuntimeRpc netconf = new RuntimeRpc(configSubsystemFacade, NETCONF_SESSION_ID);
response = executeOp(netconf, "netconfMessages/rpc.xml");
assertContainsElementWithText(response, "testarg1");
assertContainsElementWithText(response, "2");
}
- private Document get() throws NetconfDocumentedException, ParserConfigurationException, SAXException, IOException {
- Get getOp = new Get(transactionProvider, yangStoreSnapshot, configRegistryClient, NETCONF_SESSION_ID);
+ private Document get() throws ParserConfigurationException, SAXException, IOException, DocumentedException {
+ Get getOp = new Get(configSubsystemFacade, NETCONF_SESSION_ID);
return executeOp(getOp, "netconfMessages/get.xml");
}
}
private Document executeOp(final NetconfOperation op, final String filename) throws ParserConfigurationException,
- SAXException, IOException, NetconfDocumentedException {
+ SAXException, IOException, DocumentedException {
final Document request = XmlFileLoader.xmlFileToDocument(filename);