Cleanup of EnrichmentController 75/5175/4
authorelinuxhenrik <henrik.b.andersson@est.tech>
Thu, 26 Nov 2020 14:53:28 +0000 (15:53 +0100)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Fri, 27 Nov 2020 15:37:01 +0000 (16:37 +0100)
Change-Id: Ie632cf37c9d8780bf62b8d00b7806fd675ee7a3b
Issue-ID: NONRTRIC-339
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/controller/EnrichmentController.java
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/eiproducerapi/EiProducerApi.java
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/eiproducerapi/EiProducerApiImpl.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/RestApiTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/eiproducerapi/EiProducerApiImplTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/mock/EiTypes.java [deleted file]
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/mock/EnrichmentControllerMockConfiguration.java

index 0845fcd..57019ce 100644 (file)
@@ -42,7 +42,6 @@ import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.util.Assert;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.http.ResponseEntity;
 import org.springframework.util.Assert;
 import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
@@ -82,37 +81,6 @@ public class EnrichmentController {
         logger.debug("enrichment: configured with client type {}", eiProducerApi.getClass().getName());
     }
 
         logger.debug("enrichment: configured with client type {}", eiProducerApi.getClass().getName());
     }
 
-    /*
-     * The fields are defined in the Enrichment Control Typescript interface.
-     */
-    @ApiOperation(value = "Get the EI type identifiers")
-    @GetMapping(EI_TYPES)
-    public ResponseEntity<String> getAllEiTypeIds() {
-        logger.debug("getAllEiTypeIds");
-        return this.eiProducerApi.getAllEiTypeIds();
-    }
-
-    @ApiOperation(value = "Get an individual EI type")
-    @GetMapping(EI_TYPES + "/{" + EI_TYPE_ID + "}")
-    public ResponseEntity<String> getEiType(@PathVariable(EI_TYPE_ID) String eiTypeId) {
-        logger.debug("getEiType {}", eiTypeId);
-        return this.eiProducerApi.getEiType(eiTypeId);
-    }
-
-    @ApiOperation(value = "Get an individual EI producer")
-    @GetMapping(EI_PRODUCERS + "/{" + EI_PRODUCER_ID + "}")
-    public ResponseEntity<String> getEiProducer(@PathVariable(EI_PRODUCER_ID) String eiProducerId) {
-        logger.debug("getEiProducer {}", eiProducerId);
-        return this.eiProducerApi.getEiProducer(eiProducerId);
-    }
-
-    @ApiOperation(value = "Get the EI job definitions for one EI producer")
-    @GetMapping(EI_PRODUCERS + "/{" + EI_PRODUCER_ID + "}/" + EI_JOBS)
-    public ResponseEntity<String> getEiJobsForOneEiProducer(@PathVariable(EI_PRODUCER_ID) String eiProducerId) {
-        logger.debug("getEiJobsForOneEiProducer {}", eiProducerId);
-        return this.eiProducerApi.getEiJobsForOneEiProducer(eiProducerId);
-    }
-
     @ApiOperation(value = "Get the EI job definitions for one EI producer")
     @GetMapping(EI_JOBS)
     public ResponseEntity<List<JobInfo>> getEiJobs() {
     @ApiOperation(value = "Get the EI job definitions for one EI producer")
     @GetMapping(EI_JOBS)
     public ResponseEntity<List<JobInfo>> getEiJobs() {
@@ -172,11 +140,4 @@ public class EnrichmentController {
         return JsonParser.parseString(statusResponse.getBody()).getAsJsonObject().get("operational_state")
             .getAsString();
     }
         return JsonParser.parseString(statusResponse.getBody()).getAsJsonObject().get("operational_state")
             .getAsString();
     }
-
-    @ApiOperation(value = "Get the status of an EI producer")
-    @GetMapping(EI_PRODUCERS + "/{" + EI_PRODUCER_ID + "}/" + STATUS)
-    public ResponseEntity<String> getEiProducerStatus(@PathVariable(EI_PRODUCER_ID) String eiProducerId) {
-        logger.debug("getEiProducerStatus {}", eiProducerId);
-        return this.eiProducerApi.getEiProducerStatus(eiProducerId);
-    }
 }
 }
index 0e6b5c4..943b9f9 100644 (file)
@@ -23,10 +23,6 @@ import org.springframework.http.ResponseEntity;
 
 public interface EiProducerApi {
 
 
 public interface EiProducerApi {
 
-    public ResponseEntity<String> getAllEiTypeIds();
-
-    public ResponseEntity<String> getEiType(String eiTypeId);
-
     public ResponseEntity<String> getAllEiProducerIds();
 
     public ResponseEntity<String> getEiProducer(String eiProducerId);
     public ResponseEntity<String> getAllEiProducerIds();
 
     public ResponseEntity<String> getEiProducer(String eiProducerId);
index f544fe2..51be42a 100644 (file)
@@ -35,7 +35,6 @@ import org.springframework.stereotype.Component;
 public class EiProducerApiImpl implements EiProducerApi {
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
 public class EiProducerApiImpl implements EiProducerApi {
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
-    private static final String EI_TYPES = "/eitypes";
     private static final String EI_PRODUCERS = "/eiproducers";
     private static final String EI_JOBS = "/eijobs";
     private static final String STATUS = "/status";
     private static final String EI_PRODUCERS = "/eiproducers";
     private static final String EI_JOBS = "/eijobs";
     private static final String STATUS = "/status";
@@ -53,16 +52,6 @@ public class EiProducerApiImpl implements EiProducerApi {
         this.webClient = webClient;
     }
 
         this.webClient = webClient;
     }
 
-    @Override
-    public ResponseEntity<String> getAllEiTypeIds() {
-        return getResponseArray(EI_TYPES);
-    }
-
-    @Override
-    public ResponseEntity<String> getEiType(String eiTypeId) {
-        return getResponseObject(EI_TYPES + "/" + eiTypeId);
-    }
-
     @Override
     public ResponseEntity<String> getAllEiProducerIds() {
         return getResponseArray(EI_PRODUCERS);
     @Override
     public ResponseEntity<String> getAllEiProducerIds() {
         return getResponseArray(EI_PRODUCERS);
index b432b73..4243c34 100644 (file)
@@ -72,7 +72,6 @@ class RestApiTest {
         String url = "/v2/api-docs";
         ResponseEntity<String> resp = restClient().getForEntity(url).block();
         assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
         String url = "/v2/api-docs";
         ResponseEntity<String> resp = restClient().getForEntity(url).block();
         assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
-
         JsonElement jsonElement = JsonParser.parseString(resp.getBody());
         String indented = gson.toJson(jsonElement);
         try (PrintStream out = new PrintStream(new FileOutputStream("../docs/api.json"))) {
         JsonElement jsonElement = JsonParser.parseString(resp.getBody());
         String indented = gson.toJson(jsonElement);
         try (PrintStream out = new PrintStream(new FileOutputStream("../docs/api.json"))) {
index 773bb54..a388d8b 100644 (file)
@@ -35,13 +35,6 @@ import org.springframework.web.client.HttpServerErrorException;
 import reactor.core.publisher.Mono;
 
 class EiProducerApiImplTest {
 import reactor.core.publisher.Mono;
 
 class EiProducerApiImplTest {
-    private static final String URL_EI_TYPES = "/eitypes";
-    private static final String EI_TYPE_1 = "eitype1";
-    private static final String EI_TYPE_2 = "eitype2";
-    private static final String EI_TYPE_1_INFO_VALID =
-        "{\"ei_producer_ids\":[\"eiprod1\",\"eiprod2\"],\"ei_job_data_schema\":{\"title\":\"eijob1\"}}";
-    private static final String EI_TYPE_1_INFO_INVALID =
-        "{\"ei_producer_ids\":[\"eiprod1\",\"eiprod2\"],\"ei_job_data_schema\":\"title\":\"eijob1\"}}";
     private static final String URL_EI_PRODUCERS = "/eiproducers";
     private static final String EI_PRODUCER_1 = "eiprod1";
     private static final String EI_PRODUCER_2 = "eiprod2";
     private static final String URL_EI_PRODUCERS = "/eiproducers";
     private static final String EI_PRODUCER_1 = "eiprod1";
     private static final String EI_PRODUCER_2 = "eiprod2";
@@ -71,44 +64,6 @@ class EiProducerApiImplTest {
         when(restClientMock.getForEntity(eq(url))).thenReturn(Mono.error(e));
     }
 
         when(restClientMock.getForEntity(eq(url))).thenReturn(Mono.error(e));
     }
 
-    @Test
-    void testGetAllEiTypeIdsFailure() {
-        whenGetReturnFailure(URL_EI_TYPES, HttpStatus.NOT_FOUND, "");
-        ResponseEntity<String> returnedResp = apiUnderTest.getAllEiTypeIds();
-        assertEquals(HttpStatus.NOT_FOUND, returnedResp.getStatusCode());
-    }
-
-    @Test
-    void testGetAllEiTypeIdsSuccess() {
-        String eiTypeIds = Arrays.asList(EI_TYPE_1, EI_TYPE_2).toString();
-
-        whenGetReturnOK(URL_EI_TYPES, HttpStatus.OK, eiTypeIds);
-
-        ResponseEntity<String> returnedResp = apiUnderTest.getAllEiTypeIds();
-        assertEquals("[\"" + EI_TYPE_1 + "\",\"" + EI_TYPE_2 + "\"]", returnedResp.getBody());
-        assertEquals(HttpStatus.OK, returnedResp.getStatusCode());
-    }
-
-    @Test
-    void testGetEiTypeValidJson() {
-        whenGetReturnOK(URL_EI_TYPES + "/" + EI_TYPE_1, HttpStatus.OK, EI_TYPE_1_INFO_VALID);
-
-        ResponseEntity<String> returnedResp = apiUnderTest.getEiType(EI_TYPE_1);
-
-        assertEquals(HttpStatus.OK, returnedResp.getStatusCode());
-        assertEquals(EI_TYPE_1_INFO_VALID, returnedResp.getBody());
-    }
-
-    @Test
-    void testGetEiTypeInvalidJson() {
-        whenGetReturnOK(URL_EI_TYPES + "/" + EI_TYPE_1, HttpStatus.OK, EI_TYPE_1_INFO_INVALID);
-
-        ResponseEntity<String> returnedResp = apiUnderTest.getEiType(EI_TYPE_1);
-
-        assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, returnedResp.getStatusCode());
-        assertTrue(returnedResp.getBody().contains("JSONException"));
-    }
-
     @Test
     void testGetAllEiProducerIdsFailure() {
         whenGetReturnFailure(URL_EI_PRODUCERS, HttpStatus.NOT_FOUND, "");
     @Test
     void testGetAllEiProducerIdsFailure() {
         whenGetReturnFailure(URL_EI_PRODUCERS, HttpStatus.NOT_FOUND, "");
diff --git a/webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/mock/EiTypes.java b/webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/mock/EiTypes.java
deleted file mode 100644 (file)
index 8fc9eaf..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*-
- * ========================LICENSE_START=================================
- * O-RAN-SC
- * %%
- * Copyright (C) 2019 Nordix Foundation
- * Modifications Copyright (C) 2020 Nordix Foundation
- * %%
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ========================LICENSE_END===================================
- */
-package org.oransc.portal.nonrtric.controlpanel.mock;
-
-import java.util.ArrayList;
-
-public class EiTypes extends ArrayList<EiType> {
-
-    private static final long serialVersionUID = -928428052502491021L;
-
-}
index f407f9f..43be49f 100644 (file)
@@ -66,25 +66,6 @@ public class EnrichmentControllerMockConfiguration {
     class MockEiProducerApi implements EiProducerApi {
         private final Database database = new Database();
 
     class MockEiProducerApi implements EiProducerApi {
         private final Database database = new Database();
 
-        @Override
-        public ResponseEntity<String> getAllEiTypeIds() {
-            List<String> result = new ArrayList<>();
-            result.addAll(database.getAllEiTypeIds());
-            return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);
-        }
-
-        public ResponseEntity<String> getAllEiTypes() {
-            EiTypes result = new EiTypes();
-            result.addAll(database.getAllEiTypes());
-            return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);
-        }
-
-        @Override
-        public ResponseEntity<String> getEiType(String eiTypeId) {
-            EiType result = database.getEiTypeInstance(eiTypeId);
-            return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);
-        }
-
         @Override
         public ResponseEntity<String> getAllEiProducerIds() {
             List<String> result = new ArrayList<>();
         @Override
         public ResponseEntity<String> getAllEiProducerIds() {
             List<String> result = new ArrayList<>();
@@ -117,21 +98,6 @@ public class EnrichmentControllerMockConfiguration {
             EiProducer result = database.getEiProducerInstance(eiProducerId);
             return new ResponseEntity<>(gson.toJson(result.status()), HttpStatus.OK);
         }
             EiProducer result = database.getEiProducerInstance(eiProducerId);
             return new ResponseEntity<>(gson.toJson(result.status()), HttpStatus.OK);
         }
-
-        public ResponseEntity<String> deleteEiProducerInstance(String eiProducerId) {
-            database.deleteEiProducerInstance(eiProducerId);
-            return new ResponseEntity<>(HttpStatus.OK);
-        }
-
-        public ResponseEntity<String> deleteEiTypeInstance(String eiTypeId) {
-            database.deleteEiTypeInstance(eiTypeId);
-            return new ResponseEntity<>(HttpStatus.OK);
-        }
-
-        public ResponseEntity<String> deleteEiJobInstance(String eiJobId) {
-            database.deleteEiJobInstance(eiJobId);
-            return new ResponseEntity<>(HttpStatus.OK);
-        }
     }
 
     class Database {
     }
 
     class Database {
@@ -142,12 +108,12 @@ public class EnrichmentControllerMockConfiguration {
 
             // Create EiType instance
             String schema = getStringFromFile("ei-type-1.json");
 
             // Create EiType instance
             String schema = getStringFromFile("ei-type-1.json");
-            EiType eiType1 = putEiTypeInstance("type1", schema, Arrays.asList("prod-1"));
+            EiType eiType1 = getEiTypeInstance("type1", schema, Arrays.asList("prod-1"));
             supported_types.add(eiType1);
 
             // Create EiType instance
             schema = getStringFromFile("ei-type-2.json");
             supported_types.add(eiType1);
 
             // Create EiType instance
             schema = getStringFromFile("ei-type-2.json");
-            EiType eiType2 = putEiTypeInstance("type2", schema, Arrays.asList("prod-1"));
+            EiType eiType2 = getEiTypeInstance("type2", schema, Arrays.asList("prod-1"));
             supported_types.add(eiType2);
 
             // Create EiProducer instance
             supported_types.add(eiType2);
 
             // Create EiProducer instance
@@ -198,18 +164,12 @@ public class EnrichmentControllerMockConfiguration {
             eiProducers.put(id, eiProducer);
         }
 
             eiProducers.put(id, eiProducer);
         }
 
-        EiType putEiTypeInstance(String id, Object data, List<String> producer_ids) {
-            EiType i = ImmutableEiType.builder() //
+        EiType getEiTypeInstance(String id, Object data, List<String> producer_ids) {
+            return ImmutableEiType.builder() //
                 .ei_type_identity(id) //
                 .ei_job_data_schema(data) //
                 .ei_producer_ids(producer_ids) //
                 .build(); //
                 .ei_type_identity(id) //
                 .ei_job_data_schema(data) //
                 .ei_producer_ids(producer_ids) //
                 .build(); //
-            eiTypes.put(id, i);
-            return eiTypes.get(id);
-        }
-
-        public void deleteEiTypeInstance(String id) {
-            eiTypes.remove(id);
         }
 
         public void deleteEiProducerInstance(String id) {
         }
 
         public void deleteEiProducerInstance(String id) {
@@ -220,14 +180,6 @@ public class EnrichmentControllerMockConfiguration {
             eiJobs.remove(id);
         }
 
             eiJobs.remove(id);
         }
 
-        EiType getEiTypeInstance(String id) throws RestClientException {
-            EiType i = eiTypes.get(id);
-            if (i == null) {
-                throw new RestClientException("Type not found: " + id);
-            }
-            return i;
-        }
-
         EiProducer getEiProducerInstance(String id) throws RestClientException {
             EiProducer i = eiProducers.get(id);
             if (i == null) {
         EiProducer getEiProducerInstance(String id) throws RestClientException {
             EiProducer i = eiProducers.get(id);
             if (i == null) {
@@ -236,14 +188,6 @@ public class EnrichmentControllerMockConfiguration {
             return i;
         }
 
             return i;
         }
 
-        public Collection<String> getAllEiTypeIds() {
-            return Collections.unmodifiableCollection(eiTypes.keySet());
-        }
-
-        public Collection<EiType> getAllEiTypes() {
-            return eiTypes.values();
-        }
-
         public Collection<String> getAllEiProducerIds() {
             return Collections.unmodifiableCollection(eiProducers.keySet());
         }
         public Collection<String> getAllEiProducerIds() {
             return Collections.unmodifiableCollection(eiProducers.keySet());
         }
@@ -271,10 +215,7 @@ public class EnrichmentControllerMockConfiguration {
             return result;
         }
 
             return result;
         }
 
-        private Map<String, EiType> eiTypes = new HashMap<>();
         private Map<String, EiProducer> eiProducers = new HashMap<>();
         private Map<String, EiJob> eiJobs = new HashMap<>();
         private Map<String, EiProducer> eiProducers = new HashMap<>();
         private Map<String, EiJob> eiJobs = new HashMap<>();
-
     }
     }
-
 }
 }