<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>
*/
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;
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
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})
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})
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;
--- /dev/null
+/*-
+ * ========================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;
+
+}
--- /dev/null
+/*-
+ * ========================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;
+
+}
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;
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;
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;
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;
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;
HttpStatus.INTERNAL_SERVER_ERROR);
}
return new ResponseEntity<>(throwable.getClass().getName() + ": " + throwable.getMessage(),
- HttpStatus.INTERNAL_SERVER_ERROR);
+ HttpStatus.INTERNAL_SERVER_ERROR);
}
}
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());
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;
/**
* 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();
--- /dev/null
+/*-
+ * ========================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 "";
+ }
+ }
+}
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());
+++ /dev/null
-/*-
- * ========================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"));
- }
-}
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;
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);
@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);
public List<EiType> supported_ei_types();
- public String status();
+ public ProducerStatusInfo status();
}
// 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");
}
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) //
--- /dev/null
+/*-
+ * ========================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;
+ }
+
+}
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}")
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;
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;
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;