Add getJobs and adapt getProducers 40/5140/10
authorelinuxhenrik <henrik.b.andersson@est.tech>
Mon, 23 Nov 2020 15:39:20 +0000 (16:39 +0100)
committerelinuxhenrik <henrik.b.andersson@est.tech>
Wed, 25 Nov 2020 08:20:02 +0000 (09:20 +0100)
Change-Id: I8bca2dc09b7af130c2d5d36bdd63b740e8e38a0b
Issue-ID: NONRTRIC-294
Signed-off-by: elinuxhenrik <henrik.b.andersson@est.tech>Add getJobs
19 files changed:
webapp-backend/pom.xml
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/controller/EnrichmentController.java
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/eiproducerapi/EiProducerApiImpl.java
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/model/JobInfo.java [new file with mode: 0644]
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/model/ProducerInfo.java [new file with mode: 0644]
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/policyagentapi/PolicyAgentApiImpl.java
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/util/AsyncRestClient.java
webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/util/ErrorResponseHandler.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/ControlPanelUserManagerTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/MockControlPanelBackEnd.java [moved from webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/ControlPanelTestServer.java with 86% similarity]
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/RestApiTest.java [new file with mode: 0644]
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/controller/AbstractControllerTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/controller/PortalRestCentralServiceTest.java [deleted file]
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/eiproducerapi/EiProducerApiImplTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/mock/EiProducer.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/mock/EnrichmentControllerMockConfiguration.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/mock/ProducerStatusInfo.java [new file with mode: 0644]
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/portalapi/PortalAuthManagerTest.java
webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/util/AsyncRestClientTest.java

index 95de721..240c9c4 100644 (file)
@@ -119,6 +119,11 @@ limitations under the License.
             <artifactId>axis2-kernel</artifactId>
             <version>${apache-axis2.version}</version>
         </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <scope>provided</scope>
+        </dependency>
         <!-- Bridge uses of Apache commons logging, like EPSDK-FW -->
         <dependency>
             <groupId>org.slf4j</groupId>
index 300def5..0037c33 100644 (file)
  */
 package org.oransc.portal.nonrtric.controlpanel.controller;
 
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+
 import io.swagger.annotations.ApiOperation;
 
 import java.lang.invoke.MethodHandles;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.oransc.portal.nonrtric.controlpanel.ControlPanelConstants;
 import org.oransc.portal.nonrtric.controlpanel.eiproducerapi.EiProducerApi;
+import org.oransc.portal.nonrtric.controlpanel.model.JobInfo;
+import org.oransc.portal.nonrtric.controlpanel.model.ProducerInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.security.access.annotation.Secured;
@@ -51,6 +61,8 @@ public class EnrichmentController {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
+    private static com.google.gson.Gson gson = new GsonBuilder().create();
+
     // Publish paths in constants so tests are easy to write
     public static final String CONTROLLER_PATH = ControlPanelConstants.ENDPOINT_PREFIX + "/enrichment";
     // Endpoints
@@ -91,14 +103,6 @@ public class EnrichmentController {
         return this.eiProducerApi.getEiType(eiTypeId);
     }
 
-    @ApiOperation(value = "Get the EI producer identifiers")
-    @GetMapping(EI_PRODUCERS)
-    @Secured({ControlPanelConstants.ROLE_ADMIN, ControlPanelConstants.ROLE_STANDARD})
-    public ResponseEntity<String> getAllEiProducerIds() {
-        logger.debug("getAllEiProducerIds");
-        return this.eiProducerApi.getAllEiProducerIds();
-    }
-
     @ApiOperation(value = "Get an individual EI producer")
     @GetMapping(EI_PRODUCERS + "/{" + EI_PRODUCER_ID + "}")
     @Secured({ControlPanelConstants.ROLE_ADMIN, ControlPanelConstants.ROLE_STANDARD})
@@ -115,6 +119,68 @@ public class EnrichmentController {
         return this.eiProducerApi.getEiJobsForOneEiProducer(eiProducerId);
     }
 
+    @ApiOperation(value = "Get the EI job definitions for one EI producer")
+    @GetMapping(EI_JOBS)
+    @Secured({ControlPanelConstants.ROLE_ADMIN, ControlPanelConstants.ROLE_STANDARD})
+    public ResponseEntity<List<JobInfo>> getEiJobs() {
+        logger.debug("getEiJobs");
+        ResponseEntity<String> response = this.eiProducerApi.getAllEiProducerIds();
+        JsonArray bodyJson = JsonParser.parseString(response.getBody()).getAsJsonArray();
+        List<JobInfo> allJobs = new ArrayList<>();
+        for (JsonElement producerId : bodyJson) {
+            allJobs.addAll(getJobs(producerId));
+        }
+        return new ResponseEntity<>(allJobs, HttpStatus.OK);
+    }
+
+    private List<JobInfo> getJobs(JsonElement producerId) {
+        List<JobInfo> jobs = new ArrayList<>();
+        ResponseEntity<String> jobsResponse = this.eiProducerApi.getEiJobsForOneEiProducer(producerId.getAsString());
+        JsonArray jobsJson = JsonParser.parseString(jobsResponse.getBody()).getAsJsonArray();
+        for (JsonElement jobJson : jobsJson) {
+            JobInfo jobInfo = gson.fromJson(jobJson, JobInfo.class);
+            jobs.add(jobInfo);
+        }
+        return jobs;
+    }
+
+    @ApiOperation(value = "Get EI producers")
+    @GetMapping(EI_PRODUCERS)
+    @Secured({ControlPanelConstants.ROLE_ADMIN, ControlPanelConstants.ROLE_STANDARD})
+    public ResponseEntity<List<ProducerInfo>> getEiProducers() {
+        logger.debug("getEiProducers");
+        ResponseEntity<String> response = this.eiProducerApi.getAllEiProducerIds();
+        JsonArray bodyJson = JsonParser.parseString(response.getBody()).getAsJsonArray();
+        List<ProducerInfo> producers = new ArrayList<>();
+        for (JsonElement producerId : bodyJson) {
+            ProducerInfo producerInfo = ProducerInfo.builder() //
+                .id(producerId.getAsString()) //
+                .types(getSupportedTypes(producerId)) //
+                .status(getProducerStatus(producerId)) //
+                .build();
+            producers.add(producerInfo);
+        }
+
+        return new ResponseEntity<>(producers, HttpStatus.OK);
+    }
+
+    private String[] getSupportedTypes(JsonElement producerId) {
+        ResponseEntity<String> producerResponse = this.eiProducerApi.getEiProducer(producerId.getAsString());
+        JsonArray supportedTypesJson = JsonParser.parseString(producerResponse.getBody()).getAsJsonObject()
+            .get("supported_ei_types").getAsJsonArray();
+        List<String> supportedTypes = new ArrayList<>();
+        for (JsonElement typeJson : supportedTypesJson) {
+            supportedTypes.add(typeJson.getAsJsonObject().get("ei_type_identity").getAsString());
+        }
+        return supportedTypes.toArray(new String[0]);
+    }
+
+    private String getProducerStatus(JsonElement producerId) {
+        ResponseEntity<String> statusResponse = this.eiProducerApi.getEiProducerStatus(producerId.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)
     @Secured({ControlPanelConstants.ROLE_ADMIN, ControlPanelConstants.ROLE_STANDARD})
index 381a35a..f544fe2 100644 (file)
@@ -20,6 +20,7 @@
 package org.oransc.portal.nonrtric.controlpanel.eiproducerapi;
 
 import java.lang.invoke.MethodHandles;
+
 import org.json.JSONArray;
 import org.json.JSONObject;
 import org.oransc.portal.nonrtric.controlpanel.util.AsyncRestClient;
diff --git a/webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/model/JobInfo.java b/webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/model/JobInfo.java
new file mode 100644 (file)
index 0000000..e8ec292
--- /dev/null
@@ -0,0 +1,57 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * 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.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.gson.annotations.SerializedName;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Builder;
+
+import org.immutables.gson.Gson;
+
+@Gson.TypeAdapters
+@ApiModel(value = "ei_job_request", description = "The EI job")
+@Builder
+public class JobInfo {
+
+    @ApiModelProperty(value = "Identity of the EI job", required = true)
+    @SerializedName("ei_job_identity")
+    @JsonProperty("ei_job_identity")
+    public String id;
+
+    @ApiModelProperty(value = "Type identity for the job")
+    @SerializedName("ei_type_identity")
+    @JsonProperty("ei_type_identity")
+    public String typeId;
+
+    @ApiModelProperty(value = "Json for the job data")
+    @SerializedName("ei_job_data")
+    @JsonProperty("ei_job_data")
+    public Object jobData;
+
+    @ApiModelProperty(value = "URI for the target of the EI")
+    @SerializedName("target_uri")
+    @JsonProperty("target_uri")
+    public String targetUri;
+
+}
diff --git a/webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/model/ProducerInfo.java b/webapp-backend/src/main/java/org/oransc/portal/nonrtric/controlpanel/model/ProducerInfo.java
new file mode 100644 (file)
index 0000000..6293871
--- /dev/null
@@ -0,0 +1,50 @@
+/*-
+ * ========================LICENSE_START=================================
+ * Copyright (C) 2020 Nordix Foundation. All rights reserved.
+ * ======================================================================
+ * 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.model;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.gson.annotations.SerializedName;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Builder;
+
+import org.immutables.gson.Gson;
+
+@Gson.TypeAdapters
+@ApiModel(value = "ei_producer", description = "The EI producer")
+@Builder
+public class ProducerInfo {
+
+    @ApiModelProperty(value = "Idenitity of the EI producer", required = true)
+    @SerializedName("ei_producer_id")
+    @JsonProperty("ei_producer_id")
+    public String id;
+
+    @ApiModelProperty(value = "Types provided by the EI producer", required = true)
+    @SerializedName("ei_producer_types")
+    @JsonProperty("ei_producer_types")
+    public String[] types;
+
+    @ApiModelProperty(value = "Status of the EI producer", required = true)
+    @SerializedName("status")
+    @JsonProperty("status")
+    public String status;
+
+}
index 25e604a..44f060e 100644 (file)
@@ -26,11 +26,13 @@ import com.google.gson.JsonElement;
 import com.google.gson.JsonObject;
 import com.google.gson.JsonParser;
 import com.google.gson.reflect.TypeToken;
+
 import java.lang.invoke.MethodHandles;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+
 import org.immutables.gson.Gson;
 import org.immutables.value.Value;
 import org.oransc.portal.nonrtric.controlpanel.model.ImmutablePolicyInfo;
index 0519700..ac99c58 100644 (file)
 
 package org.oransc.portal.nonrtric.controlpanel.util;
 
+import io.netty.channel.ChannelOption;
+import io.netty.handler.ssl.SslContext;
+import io.netty.handler.ssl.SslContextBuilder;
+import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
+import io.netty.handler.timeout.ReadTimeoutHandler;
+import io.netty.handler.timeout.WriteTimeoutHandler;
+
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.lang.invoke.MethodHandles;
@@ -33,6 +40,7 @@ import java.util.Collections;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
+
 import org.immutables.value.Value;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -44,12 +52,7 @@ import org.springframework.web.reactive.function.client.ExchangeStrategies;
 import org.springframework.web.reactive.function.client.WebClient;
 import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec;
 import org.springframework.web.reactive.function.client.WebClientResponseException;
-import io.netty.channel.ChannelOption;
-import io.netty.handler.ssl.SslContext;
-import io.netty.handler.ssl.SslContextBuilder;
-import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
-import io.netty.handler.timeout.ReadTimeoutHandler;
-import io.netty.handler.timeout.WriteTimeoutHandler;
+
 import reactor.core.publisher.Mono;
 import reactor.netty.http.client.HttpClient;
 import reactor.netty.resources.ConnectionProvider;
index 3dbfd04..09d4684 100644 (file)
@@ -20,6 +20,7 @@
 package org.oransc.portal.nonrtric.controlpanel.util;
 
 import javax.net.ssl.SSLException;
+
 import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.client.HttpClientErrorException;
@@ -44,6 +45,6 @@ public class ErrorResponseHandler {
                 HttpStatus.INTERNAL_SERVER_ERROR);
         }
         return new ResponseEntity<>(throwable.getClass().getName() + ": " + throwable.getMessage(),
-                HttpStatus.INTERNAL_SERVER_ERROR);
+            HttpStatus.INTERNAL_SERVER_ERROR);
     }
 }
index f6e72d6..1faf618 100644 (file)
@@ -31,9 +31,7 @@ import org.onap.portalsdk.core.restful.domain.EcompRole;
 import org.onap.portalsdk.core.restful.domain.EcompUser;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.test.context.ActiveProfiles;
 
-@ActiveProfiles("test")
 class ControlPanelUserManagerTest {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@@ -23,12 +23,12 @@ package org.oransc.portal.nonrtric.controlpanel;
 import java.lang.invoke.MethodHandles;
 
 import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
 import org.junit.jupiter.api.extension.ExtendWith;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.web.server.LocalServerPort;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 /**
@@ -39,26 +39,26 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
  * To launch a development server set the environment variable as listed below.
  * This runs a Spring-Boot server with mock back-end beans, and keeps the server
  * alive for manual testing. Supply this JVM argument:
- *
- * <pre>
- * -Dorg.org.oransc.portal.nonrtric.controlpanel=mock
- * </pre>
  */
+@SuppressWarnings("java:S3577") // Class name should start or end with Test. This is not a test class per se, but a mock
+                                // of the server.
 @ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
-class ControlPanelTestServer {
+class MockControlPanelBackEnd {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
 
+    @LocalServerPort
+    private int port;
+
     /*
      * Keeps the test server alive forever. Use a guard so this test is never run by
      * Jenkins.
      */
     @SuppressWarnings("squid:S2699") // To avoid warning about missing assertion.
-    @EnabledIfSystemProperty(named = "org.oransc.portal.nonrtric.controlpanel", matches = "mock")
     @Test
     void keepServerAlive() {
-        logger.warn("Keeping server alive!");
+        logger.warn("Keeping server alive! Port: " + this.port);
         try {
             synchronized (this) {
                 this.wait();
diff --git a/webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/RestApiTest.java b/webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/RestApiTest.java
new file mode 100644 (file)
index 0000000..b432b73
--- /dev/null
@@ -0,0 +1,134 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * 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;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonParser;
+
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.lang.invoke.MethodHandles;
+import java.util.stream.Collectors;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.oransc.portal.nonrtric.controlpanel.model.JobInfo;
+import org.oransc.portal.nonrtric.controlpanel.model.ProducerInfo;
+import org.oransc.portal.nonrtric.controlpanel.util.AsyncRestClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
+import org.springframework.boot.web.server.LocalServerPort;
+import org.springframework.context.ApplicationContext;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+@ExtendWith(SpringExtension.class)
+@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
+class RestApiTest {
+
+    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+    private static Gson gson = new GsonBuilder().setPrettyPrinting().create();
+
+    @Autowired
+    ApplicationContext context;
+
+    @LocalServerPort
+    private int port;
+
+    @Test
+    void createApiDoc() throws FileNotFoundException {
+        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"))) {
+            out.println(indented);
+        }
+    }
+
+    @Test
+    void getJobs() throws FileNotFoundException {
+        String url = "/api/enrichment/eijobs";
+        ResponseEntity<String> resp = restClient().getForEntity(url).block();
+        assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
+
+        JsonArray jobs = JsonParser.parseString(resp.getBody()).getAsJsonArray();
+        JobInfo wantedJobInfo = JobInfo.builder() //
+            .id("job1") //
+            .typeId("type1") //
+            .jobData(getStringFromFile("job-1.json")) //
+            .targetUri("http://example.com/") //
+            .build();
+        assertThat(jobs).hasSize(1) //
+            .contains(gson.toJsonTree(wantedJobInfo));
+    }
+
+    @Test
+    void getProducers() {
+        String url = "/api/enrichment/eiproducers";
+        ResponseEntity<String> resp = restClient().getForEntity(url).block();
+        assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.OK);
+
+        JsonArray producers = JsonParser.parseString(resp.getBody()).getAsJsonArray();
+
+        ProducerInfo wantedProducerInfo = ProducerInfo.builder() //
+            .id("prod-1") //
+            .types(new String[] {"type1", "type2"}) //
+            .status("ENABLED") //
+            .build();
+        assertThat(producers).hasSize(1) //
+            .contains(gson.toJsonTree(wantedProducerInfo));
+    }
+
+    private AsyncRestClient restClient() {
+        return new AsyncRestClient(baseUrl());
+    }
+
+    private String baseUrl() {
+        return "https://localhost:" + this.port;
+    }
+
+    private String getStringFromFile(String path) {
+        try {
+            InputStream inputStream = MethodHandles.lookup().lookupClass().getClassLoader().getResourceAsStream(path);
+            return new BufferedReader(new InputStreamReader(inputStream)).lines().collect(Collectors.joining("\n"));
+        } catch (Exception e) {
+            logger.error("Cannot read file :" + path, e);
+            return "";
+        }
+    }
+}
index f7f6336..504223b 100644 (file)
@@ -33,14 +33,12 @@ import org.slf4j.LoggerFactory;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
 import org.springframework.boot.web.server.LocalServerPort;
-import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 import org.springframework.web.util.UriComponentsBuilder;
 
 @ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
 // Need the fake answers from the backend
-@ActiveProfiles("test")
 class AbstractControllerTest {
 
     private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
diff --git a/webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/controller/PortalRestCentralServiceTest.java b/webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/controller/PortalRestCentralServiceTest.java
deleted file mode 100644 (file)
index d9919a5..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * ========================LICENSE_START=================================
- * O-RAN-SC
- * %%
- * Copyright (C) 2019 AT&T Intellectual Property
- * 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.controller;
-
-import static org.junit.jupiter.api.Assertions.assertThrows;
-
-import java.lang.invoke.MethodHandles;
-import java.net.URI;
-
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-import org.onap.portalsdk.core.onboarding.util.PortalApiConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.reactive.function.client.WebClientResponseException;
-import reactor.core.publisher.Mono;
-
-class PortalRestCentralServiceTest extends AbstractControllerTest {
-
-    private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
-
-    @Test
-    void getAnalyticsTest() {
-        // paths are hardcoded here exactly like the EPSDK-FW library :(
-        URI uri = buildUri(null, PortalApiConstants.API_PREFIX, "/analytics");
-        logger.info("Invoking {}", uri);
-        Mono<ResponseEntity<String>> forEntity = webClient.getForEntity(uri.toString());
-        WebClientResponseException e = assertThrows(WebClientResponseException.class, () -> {
-            forEntity.block();
-        });
-        // No Portal is available so this always fails
-        Assertions.assertTrue(e.getStatusCode().is4xxClientError());
-    }
-
-    @Test
-    void getErrorPageTest() {
-        // Send unauthorized request
-
-        URI uri = buildUri(null, "/favicon.ico");
-        logger.info("Invoking {}", uri);
-        Mono<ResponseEntity<String>> forEntity = webClient.getForEntity(uri.toString());
-        WebClientResponseException e = assertThrows(WebClientResponseException.class, () -> {
-            forEntity.block();
-        });
-        Assertions.assertTrue(e.getStatusCode().is4xxClientError());
-        Assertions.assertTrue(e.getResponseBodyAsString().contains("Static error page"));
-    }
-}
index d478d45..773bb54 100644 (file)
@@ -24,7 +24,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+
 import java.util.Arrays;
+
 import org.junit.jupiter.api.Test;
 import org.oransc.portal.nonrtric.controlpanel.util.AsyncRestClient;
 import org.springframework.http.HttpStatus;
@@ -37,24 +39,24 @@ class EiProducerApiImplTest {
     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\"}}";
+        "{\"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\"}}";
+        "{\"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 EI_PRODUCER_1_INFO_VALID =
-            "{\"supported_ei_types\":[{\"ei_type_identity\":\"eitype1\",\"ei_job_data_schema\":{\"title\":\"eijob1\"}}]}";
+        "{\"supported_ei_types\":[{\"ei_type_identity\":\"eitype1\",\"ei_job_data_schema\":{\"title\":\"eijob1\"}}]}";
     private static final String EI_PRODUCER_1_INFO_INVALID =
-            "{\"supported_ei_types\":[{\"ei_type_identity\":\"eitype1\",\"ei_job_data_schema\":\"title\":\"eijob1\"}}]}";
+        "{\"supported_ei_types\":[{\"ei_type_identity\":\"eitype1\",\"ei_job_data_schema\":\"title\":\"eijob1\"}}]}";
     private static final String URL_STATUS = "/status";
     private static final String EI_PRODUCER_1_STATUS_VALID = "{\"operational_state\":\"ENABLED\"}";
     private static final String EI_PRODUCER_1_STATUS_INVALID = "\"operational_state\":\"ENABLED\"}";
     private static final String URL_EI_JOBS = "/eijobs";
     private static final String EI_JOB_1_INFO =
-            "{\"ei_job_identity\":\"eijob1\",\"ei_job_data\":{},\"ei_type_identity\":\"eitype1\"}";
+        "{\"ei_job_identity\":\"eijob1\",\"ei_job_data\":{},\"ei_type_identity\":\"eitype1\"}";
     private static final String EI_JOB_2_INFO =
-            "{\"ei_job_identity\":\"eijob2\",\"ei_job_data\":{},\"ei_type_identity\":\"eitype2\"}";
+        "{\"ei_job_identity\":\"eijob2\",\"ei_job_data\":{},\"ei_type_identity\":\"eitype2\"}";
 
     AsyncRestClient restClientMock = mock(AsyncRestClient.class);
     EiProducerApiImpl apiUnderTest = new EiProducerApiImpl(restClientMock);
@@ -176,7 +178,8 @@ class EiProducerApiImplTest {
 
     @Test
     void testGetEiProducerStatusInvalidJson() {
-        whenGetReturnOK(URL_EI_PRODUCERS + "/" + EI_PRODUCER_1 + URL_STATUS, HttpStatus.OK, EI_PRODUCER_1_STATUS_INVALID);
+        whenGetReturnOK(URL_EI_PRODUCERS + "/" + EI_PRODUCER_1 + URL_STATUS, HttpStatus.OK,
+            EI_PRODUCER_1_STATUS_INVALID);
 
         ResponseEntity<String> returnedResp = apiUnderTest.getEiProducerStatus(EI_PRODUCER_1);
 
index 626f0c4..f407f9f 100644 (file)
@@ -152,7 +152,7 @@ public class EnrichmentControllerMockConfiguration {
 
             // Create EiProducer instance
             putEiProducerInstance("prod-1", "http://example.com/", "http://example.com/", "http://example.com/",
-                supported_types, "ENABLED");
+                supported_types, new ProducerStatusInfo(ProducerStatusInfo.OperationalState.ENABLED));
 
             // Create EiJob instance
             schema = getStringFromFile("job-1.json");
@@ -187,7 +187,7 @@ public class EnrichmentControllerMockConfiguration {
         }
 
         void putEiProducerInstance(String id, String creation_url, String deletion_url, String callback_url,
-            List<EiType> supported_types, String status) {
+            List<EiType> supported_types, ProducerStatusInfo status) {
             EiProducer eiProducer = ImmutableEiProducer.builder() //
                 .ei_producer_id(id) //
                 .ei_job_creation_callback_url(creation_url) //
diff --git a/webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/mock/ProducerStatusInfo.java b/webapp-backend/src/test/java/org/oransc/portal/nonrtric/controlpanel/mock/ProducerStatusInfo.java
new file mode 100644 (file)
index 0000000..0a26b65
--- /dev/null
@@ -0,0 +1,44 @@
+/*-
+ * ========================LICENSE_START=================================
+ * O-RAN-SC
+ * %%
+ * Copyright (C) 2019 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 com.fasterxml.jackson.annotation.JsonProperty;
+import com.google.gson.annotations.SerializedName;
+
+import org.immutables.gson.Gson;
+
+@Gson.TypeAdapters
+public class ProducerStatusInfo {
+
+    @Gson.TypeAdapters
+    public enum OperationalState {
+        ENABLED, DISABLED
+    }
+
+    @SerializedName("operational_state")
+    @JsonProperty(value = "operational_state", required = true)
+    public final OperationalState opState;
+
+    public ProducerStatusInfo(OperationalState state) {
+        this.opState = state;
+    }
+
+}
index fa8c86b..382198b 100644 (file)
@@ -39,12 +39,10 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockHttpServletResponse;
-import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit.jupiter.SpringExtension;
 
 @ExtendWith(SpringExtension.class)
 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
-@ActiveProfiles("test")
 class PortalAuthManagerTest {
 
     @Value("${portalapi.decryptor}")
index f898956..f668803 100644 (file)
 
 package org.oransc.portal.nonrtric.controlpanel.util;
 
+import io.netty.util.internal.logging.InternalLoggerFactory;
+import io.netty.util.internal.logging.JdkLoggerFactory;
+
 import java.io.IOException;
+
+import okhttp3.mockwebserver.MockResponse;
+import okhttp3.mockwebserver.MockWebServer;
+
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
@@ -28,10 +35,7 @@ import org.springframework.http.HttpHeaders;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.reactive.function.client.WebClientResponseException;
-import io.netty.util.internal.logging.InternalLoggerFactory;
-import io.netty.util.internal.logging.JdkLoggerFactory;
-import okhttp3.mockwebserver.MockResponse;
-import okhttp3.mockwebserver.MockWebServer;
+
 import reactor.core.publisher.Mono;
 import reactor.test.StepVerifier;
 import reactor.util.Loggers;
@@ -40,8 +44,6 @@ class AsyncRestClientTest {
     private static final String BASE_URL = "BaseUrl";
     private static final String REQUEST_URL = "/test";
     private static final String TEST_JSON = "{\"type\":\"type1\"}";
-    private static final String USERNAME = "user";
-    private static final String PASSWORD = "pass";
     private static final int SUCCESS_CODE = 200;
     private static final int ERROR_CODE = 500;