@BeforeClass public static void initialization() { schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext); final DOMMountPoint mockMountPoint = mock(DOMMountPoint.class); when(mockMountPoint.getSchemaContext()).thenReturn(schemaContext); final DOMMountPointService mockMountPointService = mock(DOMMountPointService.class); when(mockMountPointService.getMountPoint(any(YangInstanceIdentifier.class))) .thenReturn(Optional.of(mockMountPoint)); controllerContext.setMountService(mockMountPointService); controllerContext.setSchemas(schemaContext); }
public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataPost( final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) { final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class); if (domDataBrokerService.isPresent()) { return postDataViaTransaction( domDataBrokerService.get().newReadWriteTransaction(), CONFIGURATION, path, payload, mountPoint.getSchemaContext()); } final String errMsg = "DOM data broker service isn't available for mount point " + path; LOG.warn(errMsg); throw new RestconfDocumentedException(errMsg); }
@Test public void postDataViaUrlMountPoint() throws UnsupportedEncodingException { controllerContext.setSchemas(schemaContextYangsIetf); when(brokerFacade.commitConfigurationDataPost( any(DOMMountPoint.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class))) .thenReturn(mock(CheckedFuture.class)); DOMMountPoint mountInstance = mock(DOMMountPoint.class); when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule); DOMMountPointService mockMountService = mock(DOMMountPointService.class); when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))) .thenReturn(Optional.of(mountInstance)); ControllerContext.getInstance().setMountService(mockMountService); String uri = "/config/ietf-interfaces:interfaces/interface/0/"; assertEquals(204, post(uri, Draft02.MediaTypes.DATA + XML, xmlData4)); uri = "/config/ietf-interfaces:interfaces/interface/0/yang-ext:mount/test-module:cont"; assertEquals(204, post(uri, Draft02.MediaTypes.DATA + XML, xmlData3)); assertEquals(400, post(uri, MediaType.APPLICATION_JSON, "")); }