Remove RestconfOperationsService 25/107225/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 3 Aug 2023 13:36:55 +0000 (15:36 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 3 Aug 2023 14:47:41 +0000 (16:47 +0200)
This interface is not really useful, inline it into its sole
implementation. Also rename the test to match its name and refactor it a
bit to isolate state.

JIRA: NETCONF-1117
Change-Id: I81d92321bbc06b5aef32981a078565a02b4f2c33
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfOperationsService.java [deleted file]
restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImpl.java
restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceImplTest.java [moved from restconf/restconf-nb/src/test/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfOperationsServiceTest.java with 78% similarity]

diff --git a/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfOperationsService.java b/restconf/restconf-nb/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/api/RestconfOperationsService.java
deleted file mode 100644 (file)
index f6ddd5b..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * 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);
-}
index 0149d278671b55e2650d152be79f5bdb8ff3cf05..c8828d347917675a43368e3d26f0c5a3335b3cf6 100644 (file)
@@ -9,18 +9,22 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 
 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;
 
@@ -36,24 +40,54 @@ public class RestconfOperationsServiceImpl implements RestconfOperationsService
         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));
     }
@@ -10,25 +10,26 @@ package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 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";
@@ -51,20 +52,30 @@ public class RestconfOperationsServiceTest {
           <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