+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.restconf.nb.rfc8040.rests.services.api;
-
-import javax.ws.rs.GET;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
-
-/**
- * Container that provides access to the data-model specific operations supported by the server.
- */
-public interface RestconfOperationsService {
- /**
- * List RPC and action operations in RFC7951 format.
- *
- * @return A string containing a JSON document conforming to both RFC8040 and RFC7951.
- */
- @GET
- @Path("/operations")
- @Produces({ MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON })
- String getOperationsJSON();
-
- /**
- * Retrieve list of operations and actions supported by the server or device in JSON format.
- *
- * @param identifier path parameter to identify device and/or operation
- * @return A string containing a JSON document conforming to both RFC8040 and RFC7951.
- */
- @GET
- @Path("/operations/{identifier:.+}")
- @Produces({ MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON })
- String getOperationJSON(@PathParam("identifier") String identifier);
-
- /**
- * List RPC and action operations in RFC8040 XML format.
- *
- * @return A string containing an XML document conforming to both RFC8040 section 11.3.1 and page 84.
- */
- @GET
- @Path("/operations")
- @Produces({ MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
- String getOperationsXML();
-
- /**
- * Retrieve list of operations and actions supported by the server or device in XML format.
- *
- * @param identifier path parameter to identify device and/or operation
- * @return A string containing an XML document conforming to both RFC8040 section 11.3.1 and page 84.
- */
- @GET
- @Path("/operations/{identifier:.+}")
- @Produces({ MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
- String getOperationXML(@PathParam("identifier") String identifier);
-}
import static java.util.Objects.requireNonNull;
+import javax.ws.rs.GET;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
+import org.opendaylight.restconf.nb.rfc8040.MediaTypes;
import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfOperationsService;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
/**
- * Implementation of {@link RestconfOperationsService}.
+ * Container that provides access to the data-model specific operations supported by the server.
*/
@Path("/")
-public class RestconfOperationsServiceImpl implements RestconfOperationsService {
+public final class RestconfOperationsServiceImpl {
private final DatabindProvider databindProvider;
private final DOMMountPointService mountPointService;
this.mountPointService = requireNonNull(mountPointService);
}
- @Override
+ /**
+ * List RPC and action operations in RFC7951 format.
+ *
+ * @return A string containing a JSON document conforming to both RFC8040 and RFC7951.
+ */
+ @GET
+ @Path("/operations")
+ @Produces({ MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON })
public String getOperationsJSON() {
return OperationsContent.JSON.bodyFor(databindProvider.currentContext().modelContext());
}
- @Override
- public String getOperationJSON(final String identifier) {
+ /**
+ * Retrieve list of operations and actions supported by the server or device in JSON format.
+ *
+ * @param identifier path parameter to identify device and/or operation
+ * @return A string containing a JSON document conforming to both RFC8040 and RFC7951.
+ */
+ @GET
+ @Path("/operations/{identifier:.+}")
+ @Produces({ MediaTypes.APPLICATION_YANG_DATA_JSON, MediaType.APPLICATION_JSON })
+ public String getOperationJSON(@PathParam("identifier") final String identifier) {
return OperationsContent.JSON.bodyFor(ParserIdentifier.toInstanceIdentifier(identifier,
databindProvider.currentContext().modelContext(), mountPointService));
}
- @Override
+ /**
+ * List RPC and action operations in RFC8040 XML format.
+ *
+ * @return A string containing an XML document conforming to both RFC8040 section 11.3.1 and page 84.
+ */
+ @GET
+ @Path("/operations")
+ @Produces({ MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public String getOperationsXML() {
return OperationsContent.XML.bodyFor(databindProvider.currentContext().modelContext());
}
- @Override
- public String getOperationXML(final String identifier) {
+ /**
+ * Retrieve list of operations and actions supported by the server or device in XML format.
+ *
+ * @param identifier path parameter to identify device and/or operation
+ * @return A string containing an XML document conforming to both RFC8040 section 11.3.1 and page 84.
+ */
+ @GET
+ @Path("/operations/{identifier:.+}")
+ @Produces({ MediaTypes.APPLICATION_YANG_DATA_XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ public String getOperationXML(@PathParam("identifier") final String identifier) {
return OperationsContent.XML.bodyFor(ParserIdentifier.toInstanceIdentifier(identifier,
databindProvider.currentContext().modelContext(), mountPointService));
}
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.mock;
import java.util.Optional;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.opendaylight.mdsal.binding.runtime.spi.BindingRuntimeHelpers;
import org.opendaylight.mdsal.dom.api.DOMMountPoint;
import org.opendaylight.mdsal.dom.api.DOMMountPointService;
import org.opendaylight.mdsal.dom.api.DOMSchemaService;
import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
-import org.opendaylight.restconf.nb.rfc8040.rests.services.api.RestconfOperationsService;
import org.opendaylight.yang.gen.v1.module._1.rev140101.Module1Data;
import org.opendaylight.yang.gen.v1.module._2.rev140102.Module2Data;
import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class RestconfOperationsServiceTest {
+public class RestconfOperationsServiceImplTest {
private static final String DEVICE_ID = "network-topology:network-topology/topology=topology-netconf/"
+ "node=device/yang-ext:mount";
private static final String DEVICE_RPC1_MODULE1_ID = DEVICE_ID + "module1:dummy-rpc1-module1";
<ns1:dummy-rpc1-module2/>
<ns1:dummy-rpc2-module2/>
</operations>""";
- private static RestconfOperationsService opService;
+
+ private static EffectiveModelContext SCHEMA;
+
+ @Mock
+ private DOMMountPointService mountPointService;
+ @Mock
+ private DOMMountPoint mountPoint;
+ @Mock
+ private DOMSchemaService schemaService;
+
+ private RestconfOperationsServiceImpl opService;
@BeforeClass
- public static void startUp() {
- final var runtimeContext = BindingRuntimeHelpers.createRuntimeContext(Module1Data.class, Module2Data.class,
- NetworkTopology.class);
- final var context = runtimeContext.getEffectiveModelContext();
- final var mockMountPointService = mock(DOMMountPointService.class);
- final var mockDomMountPoint = mock(DOMMountPoint.class);
- final var mockDomSchemaService = mock(DOMSchemaService.class);
- doReturn(context).when(mockDomSchemaService).getGlobalContext();
- doReturn(Optional.of(mockDomSchemaService)).when(mockDomMountPoint).getService(DOMSchemaService.class);
- doReturn(Optional.of(mockDomMountPoint)).when(mockMountPointService).getMountPoint(any());
- opService = new RestconfOperationsServiceImpl(() -> DatabindContext.ofModel(context), mockMountPointService);
+ public static void beforeClass() {
+ SCHEMA = BindingRuntimeHelpers.createRuntimeContext(Module1Data.class, Module2Data.class, NetworkTopology.class)
+ .getEffectiveModelContext();
+ }
+
+ @Before
+ public void before() {
+ doReturn(SCHEMA).when(schemaService).getGlobalContext();
+ doReturn(Optional.of(schemaService)).when(mountPoint).getService(DOMSchemaService.class);
+ doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any());
+ opService = new RestconfOperationsServiceImpl(() -> DatabindContext.ofModel(SCHEMA), mountPointService);
}
@Test