-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
package org.onap.dcaegen2.services.prh.config;
-
import java.io.Serializable;
+
import java.util.Map;
import org.immutables.gson.Gson;
@Value.Immutable(prehash = true)
@Value.Style(builder = "new")
@Gson.TypeAdapters
-public abstract class AAIClientConfiguration implements Serializable {
+public abstract class AaiClientConfiguration implements Serializable {
private static final long serialVersionUID = 1L;
public abstract String aaiUserPassword();
@Value.Parameter
- public abstract Boolean aaiIgnoreSSLCertificateErrors();
+ public abstract Boolean aaiIgnoreSslCertificateErrors();
@Value.Parameter
public abstract String aaiBasePath();
public abstract String aaiPnfPath();
@Value.Parameter
- public abstract Map<String,String> aaiHeaders();
+ public abstract Map<String, String> aaiHeaders();
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
import org.apache.http.impl.client.CloseableHttpClient;
@FunctionalInterface
-public interface AAIClient {
- CloseableHttpClient getAAIHttpClient();
+public interface AaiClient {
+ CloseableHttpClient getAaiHttpClient();
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
package org.onap.dcaegen2.services.prh.service;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.TrustStrategy;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-public class AAIClientImpl implements AAIClient {
+public class AaiClientImpl implements AaiClient {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
- private AAIClientConfiguration aaiClientConfig;
+ private AaiClientConfiguration aaiClientConfig;
- public AAIClientImpl(AAIClientConfiguration aaiClientConfiguration) {
+ AaiClientImpl(AaiClientConfiguration aaiClientConfiguration) {
this.aaiClientConfig = aaiClientConfiguration;
}
@Override
- public CloseableHttpClient getAAIHttpClient() {
+ public CloseableHttpClient getAaiHttpClient() {
final HttpClientBuilder httpClientBuilder = HttpClients.custom().useSystemProperties();
- final boolean aaiIgnoreSSLCertificateErrors = aaiClientConfig.aaiIgnoreSSLCertificateErrors();
+ final boolean aaiIgnoreSslCertificateErrors = aaiClientConfig.aaiIgnoreSslCertificateErrors();
TrustStrategy acceptingTrustStrategy = (cert, authType) -> true;
- if (aaiIgnoreSSLCertificateErrors) {
+ if (aaiIgnoreSslCertificateErrors) {
try {
logger.info("Setting SSL Context for AAI HTTP Client");
httpClientBuilder.setSSLContext(new SSLContextBuilder()
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
package org.onap.dcaegen2.services.prh.service;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Optional;
+
import org.apache.http.HttpEntity;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.utils.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Optional;
-public class AAIConsumerClient {
+public class AaiConsumerClient {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final String aaiProtocol;
private final Integer aaiHostPortNumber;
private final String aaiPath;
- private final Map<String,String> aaiHeaders;
-
-
- public AAIConsumerClient(AAIClientConfiguration aaiClientConfiguration) {
- closeableHttpClient = new AAIClientImpl(aaiClientConfiguration).getAAIHttpClient();
+ private final Map<String, String> aaiHeaders;
+
+ /**
+ * AAI client for consuming data.
+ *
+ * @param aaiClientConfiguration - client config
+ */
+ public AaiConsumerClient(AaiClientConfiguration aaiClientConfiguration) {
+ closeableHttpClient = new AaiClientImpl(aaiClientConfiguration).getAaiHttpClient();
aaiHost = aaiClientConfiguration.aaiHost();
aaiProtocol = aaiClientConfiguration.aaiProtocol();
aaiHostPortNumber = aaiClientConfiguration.aaiHostPortNumber();
aaiHeaders = aaiClientConfiguration.aaiHeaders();
}
+ /**
+ * Function which call http client for getting object from AAI.
+ *
+ * @param consumerDmaapModel - helper object for uri generation
+ * @return - status code of operation
+ * @throws IOException - Apache HTTP client exception
+ */
public Optional<String> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws IOException {
Optional<HttpRequestBase> request = createRequest(consumerDmaapModel);
try {
}
}
- private URI createAAIExtendedURI(String pnfName) {
+ private URI createAaiExtendedUri(String pnfName) {
- URI extendedURI = null;
+ URI extendedUri = null;
final URIBuilder uriBuilder = new URIBuilder()
- .setScheme(aaiProtocol)
- .setHost(aaiHost)
- .setPort(aaiHostPortNumber)
- .setPath(aaiPath + "/" + pnfName);
+ .setScheme(aaiProtocol)
+ .setHost(aaiHost)
+ .setPort(aaiHostPortNumber)
+ .setPath(aaiPath + "/" + pnfName);
try {
- extendedURI = uriBuilder.build();
- logger.trace("Building extended URI: {}", extendedURI);
+ extendedUri = uriBuilder.build();
+ logger.trace("Building extended URI: {}", extendedUri);
} catch (URISyntaxException e) {
logger.warn("Exception while building extended URI: {}", e);
}
- return extendedURI;
+ return extendedUri;
}
private ResponseHandler<Optional<String>> aaiResponseHandler() {
- return httpResponse -> {
+ return httpResponse -> {
final int responseCode = httpResponse.getStatusLine().getStatusCode();
logger.info("Status code of operation: {}", responseCode);
final HttpEntity responseEntity = httpResponse.getEntity();
- if (HttpUtils.isSuccessfulResponseCode(responseCode) ) {
+ if (HttpUtils.isSuccessfulResponseCode(responseCode)) {
logger.trace("HTTP response successful.");
final String aaiResponse = EntityUtils.toString(responseEntity);
return Optional.of(aaiResponse);
};
}
- private HttpRequestBase createHttpRequest(URI extendedURI) {
- return isExtendedURINotNull(extendedURI) ? new HttpGet(extendedURI) : null;
+ private HttpRequestBase createHttpRequest(URI extendedUri) {
+ return isExtendedUriNotNull(extendedUri) ? new HttpGet(extendedUri) : null;
}
- private Boolean isExtendedURINotNull(URI extendedURI) {
- return extendedURI != null;
+ private Boolean isExtendedUriNotNull(URI extendedUri) {
+ return extendedUri != null;
}
private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) {
- final URI extendedURI = createAAIExtendedURI(consumerDmaapModel.getPnfName());
- HttpRequestBase request = createHttpRequest(extendedURI);
+ final URI extendedUri = createAaiExtendedUri(consumerDmaapModel.getPnfName());
+ HttpRequestBase request = createHttpRequest(extendedUri);
aaiHeaders.forEach(Objects.requireNonNull(request)::addHeader);
Objects.requireNonNull(request).addHeader("Content-Type", "application/json");
return Optional.of(request);
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.prh.service;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+package org.onap.dcaegen2.services.prh.service;
import java.net.URISyntaxException;
import java.util.Optional;
+import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+
@FunctionalInterface
-public interface AAIExtendedHttpClient {
+public interface AaiExtendedHttpClient {
+
Optional<Integer> getHttpResponse(ConsumerDmaapModel consumerDmaapModel) throws URISyntaxException;
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
package org.onap.dcaegen2.services.prh.service;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Base64;
+import java.util.Map;
+import java.util.Optional;
+
import java.util.function.Predicate;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.model.CommonFunctions;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.utils.HttpUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.Base64;
-import java.util.Map;
-import java.util.Optional;
-
-public class AAIProducerClient implements AAIExtendedHttpClient {
+public class AaiProducerClient implements AaiExtendedHttpClient {
private static final String EXCEPTION_MESSAGE = "Exception while executing http client: ";
private static Predicate<String> isEmpty = String::isEmpty;
private final String aaiUserPassword;
- public AAIProducerClient(AAIClientConfiguration aaiClientConfiguration) {
- closeableHttpClient = new AAIClientImpl(aaiClientConfiguration).getAAIHttpClient();
+ public AaiProducerClient(AaiClientConfiguration aaiClientConfiguration) {
+ closeableHttpClient = new AaiClientImpl(aaiClientConfiguration).getAaiHttpClient();
aaiHost = aaiClientConfiguration.aaiHost();
aaiProtocol = aaiClientConfiguration.aaiProtocol();
aaiHostPortNumber = aaiClientConfiguration.aaiHostPortNumber();
}
private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) throws URISyntaxException {
- final URI extendedURI = createAAIExtendedURI(consumerDmaapModel.getPnfName());
- return createHttpRequest(extendedURI, consumerDmaapModel);
+ final URI extendedUri = createAaiExtendedUri(consumerDmaapModel.getPnfName());
+ return createHttpRequest(extendedUri, consumerDmaapModel);
}
- private URI createAAIExtendedURI(final String pnfName) throws URISyntaxException {
+ private URI createAaiExtendedUri(final String pnfName) throws URISyntaxException {
return new URIBuilder()
.setScheme(aaiProtocol)
.setHost(aaiHost)
.setPath(aaiPath + "/" + pnfName).build();
}
- Optional<HttpRequestBase> createHttpRequest(URI extendedURI, ConsumerDmaapModel consumerDmaapModel) {
+ private Optional<HttpRequestBase> createHttpRequest(URI extendedUri, ConsumerDmaapModel consumerDmaapModel) {
return Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)).filter(isEmpty.negate())
.flatMap(myJson -> {
try {
logger.info("AAI: sending json {}", myJson);
- return Optional.of(createHttpPatch(extendedURI, myJson));
+ return Optional.of(createHttpPatch(extendedUri, myJson));
} catch (UnsupportedEncodingException e) {
logger.warn(EXCEPTION_MESSAGE, e);
}
});
}
- HttpPatch createHttpPatch(URI extendedURI, String jsonBody) throws UnsupportedEncodingException {
- HttpPatch httpPatch = new HttpPatch(extendedURI);
+ HttpPatch createHttpPatch(URI extendedUri, String jsonBody) throws UnsupportedEncodingException {
+ HttpPatch httpPatch = new HttpPatch(extendedUri);
httpPatch.setEntity(new StringEntity(jsonBody));
aaiHeaders.forEach(httpPatch::addHeader);
httpPatch.addHeader("Content-Type", "application/merge-patch+json");
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
package org.onap.dcaegen2.services.prh.service;
-import org.apache.http.client.ResponseHandler;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.impl.client.CloseableHttpClient;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Optional;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import org.apache.http.client.ResponseHandler;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
+import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-public class AAIConsumerClientTest {
+class AaiConsumerClientTest {
- private static AAIConsumerClient testedObject;
- private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
+ private static AaiConsumerClient testedObject;
+ private static AaiClientConfiguration aaiHttpClientConfigurationMock = mock(AaiClientConfiguration.class);
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
- private static final String JSON_MESSAGE = "{ \"pnf-id\": \"example-pnf-id-val-22343\", \"regional-resource-zone\":null, \"ipaddress-v4-oam\": \"11.22.33.44\" }";
- private static ConsumerDmaapModel consumerDmaapModelMock = mock(ConsumerDmaapModel.class);
+ private static final String JSON_MESSAGE = "{ \"pnf-id\": \"example-pnf-id-val-22343\", "
+ + "\"regional-resource-zone\":null, \"ipaddress-v4-oam\": \"11.22.33.44\" }";
+ private static ConsumerDmaapModel consumerDmaapModelMock = mock(ConsumerDmaapModel.class);
private static final String PNF_NAME = "nokia-pnf-nhfsadhff";
@BeforeAll
- public static void setup() throws NoSuchFieldException, IllegalAccessException {
+ static void setup() throws NoSuchFieldException, IllegalAccessException {
Map<String, String> aaiHeaders = new HashMap<>();
aaiHeaders.put("X-FromAppId", "prh");
when(consumerDmaapModelMock.getPnfName()).thenReturn(PNF_NAME);
- testedObject = new AAIConsumerClient(aaiHttpClientConfigurationMock);
+ testedObject = new AaiConsumerClient(aaiHttpClientConfigurationMock);
setField();
}
@Test
- public void getExtendedDetails_returnsSuccess() throws IOException {
+ void getExtendedDetails_returnsSuccess() throws IOException {
- when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class))).
- thenReturn(Optional.of(JSON_MESSAGE));
- Optional<String> actualResult = testedObject.getHttpResponse(consumerDmaapModelMock);
- Assertions.assertEquals(Optional.of(JSON_MESSAGE),actualResult);
+ when(closeableHttpClientMock.execute(any(HttpGet.class), any(ResponseHandler.class)))
+ .thenReturn(Optional.of(JSON_MESSAGE));
+ Optional<String> actualResult = testedObject.getHttpResponse(consumerDmaapModelMock);
+ Assertions.assertEquals(Optional.of(JSON_MESSAGE), actualResult);
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.prh.service;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+package org.onap.dcaegen2.services.prh.service;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
-public class AAIHttpClientImplTest {
+class AaiHttpClientImplTest {
- private static AAIClientImpl testedObject;
- private static AAIClientConfiguration aaiHttpClientConfigurationMock;
+ private static AaiClientImpl testedObject;
@BeforeAll
public static void setup() {
- aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
+ AaiClientConfiguration aaiHttpClientConfigurationMock = mock(AaiClientConfiguration.class);
when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
when(aaiHttpClientConfigurationMock.aaiProtocol()).thenReturn("https");
when(aaiHttpClientConfigurationMock.aaiHostPortNumber()).thenReturn(1234);
when(aaiHttpClientConfigurationMock.aaiUserName()).thenReturn("PNF");
when(aaiHttpClientConfigurationMock.aaiUserPassword()).thenReturn("PNF");
- when(aaiHttpClientConfigurationMock.aaiIgnoreSSLCertificateErrors()).thenReturn(true);
+ when(aaiHttpClientConfigurationMock.aaiIgnoreSslCertificateErrors()).thenReturn(true);
- testedObject = new AAIClientImpl(aaiHttpClientConfigurationMock);
+ testedObject = new AaiClientImpl(aaiHttpClientConfigurationMock);
}
@Test
- public void getAAIHttpClientObject_shouldNotBeNull() {
- testedObject.getAAIHttpClient();
- assertNotNull(testedObject.getAAIHttpClient());
+ public void getAaiHttpClientObject_shouldNotBeNull() {
+ assertNotNull(testedObject.getAaiHttpClient());
}
}
package org.onap.dcaegen2.services.prh.service;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Field;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.impl.client.CloseableHttpClient;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.prh.model.CommonFunctions;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModelForUnitTest;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Field;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-class AAIProducerClientTest {
+class AaiProducerClientTest {
private static final Integer SUCCESS = 200;
- private static AAIProducerClient testedObject;
- private static AAIClientConfiguration aaiHttpClientConfigurationMock = mock(AAIClientConfiguration.class);
+ private static final HttpResponse httpResponseMock = mock(HttpResponse.class);
+ private static final HttpEntity httpEntityMock = mock(HttpEntity.class);
+ private static final StatusLine statusLineMock = mock(StatusLine.class);
+
+ private static AaiProducerClient testedObject;
+ private static AaiClientConfiguration aaiHttpClientConfigurationMock = mock(AaiClientConfiguration.class);
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
- private final static HttpResponse httpResponseMock = mock(HttpResponse.class);
- private final static HttpEntity httpEntityMock = mock(HttpEntity.class);
- private final static StatusLine statusLineMock = mock(StatusLine.class);
-
-
-
@BeforeAll
static void setup() throws NoSuchFieldException, IllegalAccessException {
when(aaiHttpClientConfigurationMock.aaiHost()).thenReturn("eucalyptus.es-si-eu-dhn-20.eecloud.nsn-net.net");
when(aaiHttpClientConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf");
when(aaiHttpClientConfigurationMock.aaiHeaders()).thenReturn(setupHeaders());
- testedObject = new AAIProducerClient(aaiHttpClientConfigurationMock);
+ testedObject = new AaiProducerClient(aaiHttpClientConfigurationMock);
setField();
}
void getHttpResponse_shouldReturnSuccessStatusCode() throws IOException, URISyntaxException {
// when
when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class)))
- .thenReturn(Optional.of(SUCCESS));
+ .thenReturn(Optional.of(SUCCESS));
Optional<Integer> actualResult = testedObject.getHttpResponse(consumerDmaapModel);
// then
assertEquals(SUCCESS, actualResult.get());
}
@Test
- void getHttpResponse_shouldHandleIOException() throws IOException, URISyntaxException {
+ void getHttpResponse_shouldHandleIoException() throws IOException, URISyntaxException {
// when
when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class)))
- .thenThrow(new IOException("Error occur"));
+ .thenThrow(new IOException("Error occur"));
- testedObject.getHttpResponse(consumerDmaapModel);
// then
assertNotNull(testedObject.getHttpResponse(consumerDmaapModel));
}
void createHttpRequest_shouldCatchUnsupportedEncodingException() throws URISyntaxException, IOException {
// when
when(closeableHttpClientMock.execute(any(HttpPatch.class), any(ResponseHandler.class)))
- .thenThrow(new UnsupportedEncodingException("A new Error"));
- testedObject.getHttpResponse(consumerDmaapModel);
+ .thenThrow(new UnsupportedEncodingException("A new Error"));
// then
assertNotNull(testedObject.getHttpResponse(consumerDmaapModel));
}
field.set(testedObject, closeableHttpClientMock);
}
- private static Map<String,String> setupHeaders() {
+ private static Map<String, String> setupHeaders() {
Map<String, String> aaiHeaders = new HashMap<>();
aaiHeaders.put("X-FromAppId", "prh");
aaiHeaders.put("X-TransactionId", "vv-temp");
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh;
import org.springframework.boot.SpringApplication;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.configuration;
+import java.util.Optional;
+
import java.util.function.Predicate;
-import org.onap.dcaegen2.services.prh.config.*;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
+import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
+import org.onap.dcaegen2.services.prh.config.ImmutableAaiClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration;
+import org.onap.dcaegen2.services.prh.config.ImmutableDmaapPublisherConfiguration;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
-import java.util.Optional;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
@Value("${dmaap.dmaapConsumerConfiguration.consumerGroup:}")
public String consumerGroup;
- @Value("${dmaap.dmaapConsumerConfiguration.timeoutMS:}")
- public Integer consumerTimeoutMS;
+ @Value("${dmaap.dmaapConsumerConfiguration.timeoutMs:}")
+ public Integer consumerTimeoutMs;
@Value("${dmaap.dmaapConsumerConfiguration.message-limit:}")
public Integer consumerMessageLimit;
@Value("${aai.aaiClientConfiguration.aaiUserPassword:}")
public String aaiUserPassword;
- @Value("${aai.aaiClientConfiguration.aaiIgnoreSSLCertificateErrors:}")
- public Boolean aaiIgnoreSSLCertificateErrors;
+ @Value("${aai.aaiClientConfiguration.aaiIgnoreSslCertificateErrors:}")
+ public Boolean aaiIgnoreSslCertificateErrors;
@Value("${aai.aaiClientConfiguration.aaiBasePath:}")
public String aaiBasePath;
.messageLimit(
Optional.ofNullable(consumerMessageLimit).filter(p -> !p.toString().isEmpty())
.orElse(dmaapConsumerConfiguration.messageLimit()))
- .timeoutMS(Optional.ofNullable(consumerTimeoutMS).filter(p -> !p.toString().isEmpty())
- .orElse(dmaapConsumerConfiguration.timeoutMS()))
+ .timeoutMs(Optional.ofNullable(consumerTimeoutMs).filter(p -> !p.toString().isEmpty())
+ .orElse(dmaapConsumerConfiguration.timeoutMs()))
.consumerGroup(Optional.ofNullable(consumerGroup).filter(isEmpty.negate())
.orElse(dmaapConsumerConfiguration.consumerGroup()))
.consumerId(Optional.ofNullable(consumerId).filter(isEmpty.negate())
}
@Override
- public AAIClientConfiguration getAAIClientConfiguration() {
- return new ImmutableAAIClientConfiguration.Builder()
+ public AaiClientConfiguration getAaiClientConfiguration() {
+ return new ImmutableAaiClientConfiguration.Builder()
.aaiHost(Optional.ofNullable(aaiHost).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiHost()))
.aaiHostPortNumber(
Optional.ofNullable(aaiHostPortNumber).filter(p -> !p.toString().isEmpty())
.orElse(aaiClientConfiguration.aaiHostPortNumber()))
- .aaiIgnoreSSLCertificateErrors(
- Optional.ofNullable(aaiIgnoreSSLCertificateErrors).filter(p -> !p.toString().isEmpty())
- .orElse(aaiClientConfiguration.aaiIgnoreSSLCertificateErrors()))
+ .aaiIgnoreSslCertificateErrors(
+ Optional.ofNullable(aaiIgnoreSslCertificateErrors).filter(p -> !p.toString().isEmpty())
+ .orElse(aaiClientConfiguration.aaiIgnoreSslCertificateErrors()))
.aaiProtocol(
Optional.ofNullable(aaiProtocol).filter(isEmpty.negate()).orElse(aaiClientConfiguration.aaiProtocol()))
.aaiUserName(
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.configuration;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
DmaapConsumerConfiguration getDmaapConsumerConfiguration();
- AAIClientConfiguration getAAIClientConfiguration();
+ AaiClientConfiguration getAaiClientConfiguration();
DmaapPublisherConfiguration getDmaapPublisherConfiguration();
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.configuration;
-import com.google.gson.*;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonSyntaxException;
+import com.google.gson.TypeAdapterFactory;
+
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+import java.util.ServiceLoader;
+import javax.validation.constraints.NotEmpty;
+import javax.validation.constraints.NotNull;
+
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
import org.slf4j.Logger;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Configuration;
-import javax.validation.constraints.NotEmpty;
-import javax.validation.constraints.NotNull;
-import java.io.*;
-import java.util.ServiceLoader;
-
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
*/
private final Logger logger = LoggerFactory.getLogger(this.getClass());
- AAIClientConfiguration aaiClientConfiguration;
+ AaiClientConfiguration aaiClientConfiguration;
DmaapConsumerConfiguration dmaapConsumerConfiguration;
}
@Override
- public AAIClientConfiguration getAAIClientConfiguration() {
+ public AaiClientConfiguration getAaiClientConfiguration() {
return aaiClientConfiguration;
}
jsonObject = rootElement.getAsJsonObject();
aaiClientConfiguration = deserializeType(gsonBuilder,
jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(AAI).getAsJsonObject(AAI_CONFIG),
- AAIClientConfiguration.class);
+ AaiClientConfiguration.class);
dmaapConsumerConfiguration = deserializeType(gsonBuilder,
jsonObject.getAsJsonObject(CONFIG).getAsJsonObject(DMAAP).getAsJsonObject(DMAAP_CONSUMER),
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.configuration;
import io.swagger.annotations.ApiOperation;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.configuration;
import org.springframework.context.annotation.Bean;
@Profile("prod")
public class SwaggerConfig extends WebMvcConfigurationSupport {
- private static final String PACKAGE_PATH = "org.onap.dcaegen2.services.prh";
- private static final String API_TITLE = "PRH app server";
- private static final String DESCRIPTION = "This page lists all the rest apis for PRH app server.";
- private static final String VERSION = "1.0";
- private static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
- private static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
- private static final String SWAGGER_UI = "swagger-ui.html";
- private static final String WEBJARS = "/webjars/**";
+ private static final String PACKAGE_PATH = "org.onap.dcaegen2.services.prh";
+ private static final String API_TITLE = "PRH app server";
+ private static final String DESCRIPTION = "This page lists all the rest apis for PRH app server.";
+ private static final String VERSION = "1.0";
+ private static final String RESOURCES_PATH = "classpath:/META-INF/resources/";
+ private static final String WEBJARS_PATH = RESOURCES_PATH + "webjars/";
+ private static final String SWAGGER_UI = "swagger-ui.html";
+ private static final String WEBJARS = "/webjars/**";
- @Bean
- public Docket api() {
- return new Docket(DocumentationType.SWAGGER_2)
- .apiInfo(apiInfo())
- .select()
- .apis(RequestHandlerSelectors.basePackage(PACKAGE_PATH))
- .paths(PathSelectors.any())
- .build();
- }
+ @Bean
+ public Docket api() {
+ return new Docket(DocumentationType.SWAGGER_2)
+ .apiInfo(apiInfo())
+ .select()
+ .apis(RequestHandlerSelectors.basePackage(PACKAGE_PATH))
+ .paths(PathSelectors.any())
+ .build();
+ }
- private ApiInfo apiInfo() {
- return new ApiInfoBuilder()
- .title(API_TITLE)
- .description(DESCRIPTION)
- .version(VERSION)
- .build();
- }
+ private ApiInfo apiInfo() {
+ return new ApiInfoBuilder()
+ .title(API_TITLE)
+ .description(DESCRIPTION)
+ .version(VERSION)
+ .build();
+ }
- @Override
- protected void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler(SWAGGER_UI)
- .addResourceLocations(RESOURCES_PATH);
+ @Override
+ protected void addResourceHandlers(ResourceHandlerRegistry registry) {
+ registry.addResourceHandler(SWAGGER_UI)
+ .addResourceLocations(RESOURCES_PATH);
- registry.addResourceHandler(WEBJARS)
- .addResourceLocations(WEBJARS_PATH);
- }
+ registry.addResourceHandler(WEBJARS)
+ .addResourceLocations(WEBJARS_PATH);
+ }
}
\ No newline at end of file
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.configuration;
import org.apache.catalina.connector.Connector;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.controllers;
import io.swagger.annotations.Api;
@ApiResponse(code = 401, message = "You are not authorized to view the resource"),
@ApiResponse(code = 403, message = "Accessing the resource you were trying to reach is forbidden"),
@ApiResponse(code = 404, message = "The resource you were trying to reach is not found")
- }
+ }
)
public Mono<ResponseEntity<String>> heartbeat() {
logger.trace("Receiving heartbeat request");
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.controllers;
import io.swagger.annotations.Api;
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.exceptions;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
*/
-public class AAINotFoundException extends PrhTaskException {
+public class AaiNotFoundException extends PrhTaskException {
- public AAINotFoundException(String message) {
+ public AaiNotFoundException(String message) {
super(message);
}
}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.exceptions;
/**
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.exceptions;
/**
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.exceptions;
/**
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
package org.onap.dcaegen2.services.prh.tasks;
import java.util.Optional;
-import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
+import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.service.AAIConsumerClient;
+import org.onap.dcaegen2.services.prh.service.AaiConsumerClient;
-public abstract class AAIConsumerTask {
+public abstract class AaiConsumerTask {
- abstract Optional<String> consume(ConsumerDmaapModel message) throws AAINotFoundException;
+ abstract Optional<String> consume(ConsumerDmaapModel message) throws AaiNotFoundException;
- abstract AAIConsumerClient resolveClient();
+ abstract AaiConsumerClient resolveClient();
- protected abstract String execute(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException;
+ protected abstract String execute(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException;
}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import java.io.IOException;
import java.util.Optional;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
-import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
+import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.service.AAIConsumerClient;
+import org.onap.dcaegen2.services.prh.service.AaiConsumerClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
-public class AAIConsumerTaskImpl extends AAIConsumerTask {
+public class AaiConsumerTaskImpl extends AaiConsumerTask {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Config prhAppConfig;
- private AAIConsumerClient aaiConsumerClient;
+ private AaiConsumerClient aaiConsumerClient;
@Autowired
- public AAIConsumerTaskImpl(AppConfig prhAppConfig) {
+ public AaiConsumerTaskImpl(AppConfig prhAppConfig) {
this.prhAppConfig = prhAppConfig;
}
@Override
- Optional<String> consume(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
+ Optional<String> consume(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException {
logger.trace("Method called with arg {}", consumerDmaapModel);
try {
return aaiConsumerClient.getHttpResponse(consumerDmaapModel);
} catch (IOException e) {
logger.warn("Get request not successful", e);
- throw new AAINotFoundException("Get request not successful");
+ throw new AaiNotFoundException("Get request not successful");
}
}
@Override
- public String execute(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
+ public String execute(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException {
consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
- .orElseThrow(() -> new AAINotFoundException("Invoked null object to AAI task"));
+ .orElseThrow(() -> new AaiNotFoundException("Invoked null object to AAI task"));
logger.trace("Method called with arg {}", consumerDmaapModel);
aaiConsumerClient = resolveClient();
- return consume(consumerDmaapModel).orElseThrow(() -> new AAINotFoundException("Null response code"));
+ return consume(consumerDmaapModel).orElseThrow(() -> new AaiNotFoundException("Null response code"));
}
- protected AAIClientConfiguration resolveConfiguration() {
- return prhAppConfig.getAAIClientConfiguration();
+ protected AaiClientConfiguration resolveConfiguration() {
+ return prhAppConfig.getAaiClientConfiguration();
}
@Override
- AAIConsumerClient resolveClient() {
- return Optional.ofNullable(aaiConsumerClient).orElseGet(() -> new AAIConsumerClient(resolveConfiguration()));
+ AaiConsumerClient resolveClient() {
+ return Optional.ofNullable(aaiConsumerClient).orElseGet(() -> new AaiConsumerClient(resolveConfiguration()));
}
}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
-import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
+import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.service.AAIProducerClient;
+import org.onap.dcaegen2.services.prh.service.AaiProducerClient;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
*/
-public abstract class AAIProducerTask {
+public abstract class AaiProducerTask {
- abstract ConsumerDmaapModel publish(ConsumerDmaapModel message) throws AAINotFoundException;
+ abstract ConsumerDmaapModel publish(ConsumerDmaapModel message) throws AaiNotFoundException;
- abstract AAIProducerClient resolveClient();
+ abstract AaiProducerClient resolveClient();
protected abstract ConsumerDmaapModel execute(ConsumerDmaapModel consumerDmaapModel) throws PrhTaskException;
}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import java.net.URISyntaxException;
import java.util.Optional;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
-import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
+import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.utils.HttpUtils;
-import org.onap.dcaegen2.services.prh.service.AAIProducerClient;
+import org.onap.dcaegen2.services.prh.service.AaiProducerClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
*/
@Component
-public class AAIProducerTaskImpl extends
- AAIProducerTask {
+public class AaiProducerTaskImpl extends
+ AaiProducerTask {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Config prhAppConfig;
- private AAIProducerClient aaiProducerClient;
+ private AaiProducerClient aaiProducerClient;
@Autowired
- public AAIProducerTaskImpl(AppConfig prhAppConfig) {
+ public AaiProducerTaskImpl(AppConfig prhAppConfig) {
this.prhAppConfig = prhAppConfig;
}
@Override
- ConsumerDmaapModel publish(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
+ ConsumerDmaapModel publish(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException {
logger.info("Sending PNF model to AAI {}", consumerDmaapModel);
try {
return aaiProducerClient.getHttpResponse(consumerDmaapModel)
.filter(HttpUtils::isSuccessfulResponseCode).map(response -> consumerDmaapModel).orElseThrow(() ->
- new AAINotFoundException("Incorrect response code for continuation of tasks workflow"));
+ new AaiNotFoundException("Incorrect response code for continuation of tasks workflow"));
} catch (URISyntaxException e) {
logger.warn("Patch request not successful", e);
- throw new AAINotFoundException("Patch request not successful");
+ throw new AaiNotFoundException("Patch request not successful");
}
}
@Override
- public ConsumerDmaapModel execute(ConsumerDmaapModel consumerDmaapModel) throws AAINotFoundException {
+ public ConsumerDmaapModel execute(ConsumerDmaapModel consumerDmaapModel) throws AaiNotFoundException {
consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
- .orElseThrow(() -> new AAINotFoundException("Invoked null object to AAI task"));
+ .orElseThrow(() -> new AaiNotFoundException("Invoked null object to AAI task"));
logger.trace("Method called with arg {}", consumerDmaapModel);
aaiProducerClient = resolveClient();
return publish(consumerDmaapModel);
}
- protected AAIClientConfiguration resolveConfiguration() {
- return prhAppConfig.getAAIClientConfiguration();
+ protected AaiClientConfiguration resolveConfiguration() {
+ return prhAppConfig.getAaiClientConfiguration();
}
@Override
- AAIProducerClient resolveClient() {
- return Optional.ofNullable(aaiProducerClient).orElseGet(() -> new AAIProducerClient(resolveConfiguration()));
+ AaiProducerClient resolveClient() {
+ return Optional.ofNullable(aaiProducerClient).orElseGet(() -> new AaiProducerClient(resolveConfiguration()));
}
}
\ No newline at end of file
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Config prhAppConfig;
private DmaapConsumerJsonParser dmaapConsumerJsonParser;
- private DMaaPConsumerReactiveHttpClient dMaaPConsumerReactiveHttpClient;
+ private DMaaPConsumerReactiveHttpClient dmaaPConsumerReactiveHttpClient;
@Autowired
public DmaapConsumerTaskImpl(AppConfig prhAppConfig) {
@Override
public Mono<ConsumerDmaapModel> execute(String object) {
- dMaaPConsumerReactiveHttpClient = resolveClient();
+ dmaaPConsumerReactiveHttpClient = resolveClient();
logger.trace("Method called with arg {}", object);
- return consume((dMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()));
+ return consume((dmaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()));
}
@Override
@Override
DMaaPConsumerReactiveHttpClient resolveClient() {
- return dMaaPConsumerReactiveHttpClient == null
+ return dmaaPConsumerReactiveHttpClient == null
? new DMaaPConsumerReactiveHttpClient(resolveConfiguration()).createDMaaPWebClient(buildWebClient())
- : dMaaPConsumerReactiveHttpClient;
+ : dmaaPConsumerReactiveHttpClient;
}
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import java.util.Optional;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
private final Config prhAppConfig;
- private DMaaPProducerReactiveHttpClient dMaaPProducerReactiveHttpClient;
+ private DMaaPProducerReactiveHttpClient dmaapProducerReactiveHttpClient;
@Autowired
public DmaapPublisherTaskImpl(AppConfig prhAppConfig) {
Mono<String> publish(Mono<ConsumerDmaapModel> consumerDmaapModel) {
logger.info("Publishing on DMaaP topic {} object {}", resolveConfiguration().dmaapTopicName(),
consumerDmaapModel);
- return dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(consumerDmaapModel);
+ return dmaapProducerReactiveHttpClient.getDMaaPProducerResponse(consumerDmaapModel);
}
@Override
public Mono<String> execute(Mono<ConsumerDmaapModel> consumerDmaapModel) throws DmaapNotFoundException {
consumerDmaapModel = Optional.ofNullable(consumerDmaapModel)
.orElseThrow(() -> new DmaapNotFoundException("Invoked null object to DMaaP task"));
- dMaaPProducerReactiveHttpClient = resolveClient();
+ dmaapProducerReactiveHttpClient = resolveClient();
logger.trace("Method called with arg {}", consumerDmaapModel);
return publish(consumerDmaapModel);
}
@Override
DMaaPProducerReactiveHttpClient resolveClient() {
- return dMaaPProducerReactiveHttpClient == null
+ return dmaapProducerReactiveHttpClient == null
? new DMaaPProducerReactiveHttpClient(resolveConfiguration()).createDMaaPWebClient(buildWebClient())
- : dMaaPProducerReactiveHttpClient;
+ : dmaapProducerReactiveHttpClient;
}
}
\ No newline at end of file
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import java.util.Optional;
private final DmaapConsumerTask dmaapConsumerTask;
private final DmaapPublisherTask dmaapProducerTask;
- private final AAIProducerTask aaiProducerTask;
+ private final AaiProducerTask aaiProducerTask;
@Autowired
public ScheduledTasks(DmaapConsumerTask dmaapConsumerTask, DmaapPublisherTask dmaapPublisherTask,
- AAIProducerTask aaiPublisherTask) {
+ AaiProducerTask aaiPublisherTask) {
this.dmaapConsumerTask = dmaapConsumerTask;
this.dmaapProducerTask = dmaapPublisherTask;
this.aaiProducerTask = aaiPublisherTask;
Mono<String> dmaapProducerResponse = Mono.fromCallable(consumeFromDMaaPMessage())
.doOnError(DmaapEmptyResponseException.class, error -> logger.warn("Nothing to consume from DMaaP"))
- .map(this::publishToAAIConfiguration)
- .flatMap(this::publishToDMaaPConfiguration)
+ .map(this::publishToAaiConfiguration)
+ .flatMap(this::publishToDmaapConfiguration)
.subscribeOn(Schedulers.elastic());
dmaapProducerResponse.subscribe(this::onSuccess, this::onError, this::onComplete);
}
private Callable<Mono<ConsumerDmaapModel>> consumeFromDMaaPMessage() {
- return () ->
- {
+ return () -> {
dmaapConsumerTask.initConfigs();
return dmaapConsumerTask.execute("");
};
}
- private Mono<ConsumerDmaapModel> publishToAAIConfiguration(Mono<ConsumerDmaapModel> monoDMaaPModel) {
+ private Mono<ConsumerDmaapModel> publishToAaiConfiguration(Mono<ConsumerDmaapModel> monoDMaaPModel) {
return monoDMaaPModel.flatMap(dmaapModel -> {
try {
return Mono.just(aaiProducerTask.execute(dmaapModel));
});
}
- private Mono<String> publishToDMaaPConfiguration(Mono<ConsumerDmaapModel> monoAAIModel) {
+ private Mono<String> publishToDmaapConfiguration(Mono<ConsumerDmaapModel> monoAaiModel) {
try {
- return dmaapProducerTask.execute(monoAAIModel);
+ return dmaapProducerTask.execute(monoAaiModel);
} catch (PrhTaskException e) {
return Mono.error(e);
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.configuration;
import static org.mockito.ArgumentMatchers.any;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.onap.dcaegen2.services.prh.IT.junit5.mockito.MockitoExtension;
+import org.onap.dcaegen2.services.prh.integration.junit5.mockito.MockitoExtension;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/9/18
class PrhAppConfigTest {
private static final String PRH_ENDPOINTS = "prh_endpoints.json";
- private static final String jsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":\"localhost\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSSLCertificateErrors\":true,\"aaiProtocol\":\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\",\"aaiPnfPath\":\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\",\"Accept\":\"application/json\",\"Real-Time\":\"true\",\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}";
- private static final String incorrectJsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":\"localhost\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSSLCertificateErrors\":true,\"aaiProtocol\":\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\",\"aaiPnfPath\":\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\",\"Accept\":\"application/json\",\"Real-Time\":\"true\",\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\":1000,\"timeoutMS\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaaptopicName\":\"temp\",\"dmaapuserName\":\"admin\",\"dmaapuserPassword\":\"admin\"}}}}";
+ private static final String jsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":"
+ + "\"localhost\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSslCertificateErrors\":true,\"aaiProtocol\":"
+ + "\"https\",\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\","
+ + "\"aaiPnfPath\":\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\","
+ + "\"Accept\":\"application/json\",\"Real-Time\":\"true\",\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},"
+ + "\"dmaap\":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\","
+ + "\"dmaapContentType\":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,"
+ + "\"dmaapProtocol\":\"http\",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\""
+ + ":\"admin\",\"messageLimit\":1000,\"timeoutMs\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":"
+ + "\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\","
+ + "\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\"}}}}";
+
+ private static final String incorrectJsonString = "{\"configs\":{\"aai\":{\"aaiClientConfiguration\":{\"aaiHost\":"
+ + "\"localhost\",\"aaiHostPortNumber\":8080,\"aaiIgnoreSslCertificateErrors\":true,\"aaiProtocol\":\"https\","
+ + "\"aaiUserName\":\"admin\",\"aaiUserPassword\":\"admin\",\"aaiBasePath\":\"/aai/v11\",\"aaiPnfPath\":"
+ + "\"/network/pnfs/pnf\",\"aaiHeaders\":{\"X-FromAppId\":\"prh\",\"X-TransactionId\":\"9999\",\"Accept\":"
+ + "\"application/json\",\"Real-Time\":\"true\",\"Authorization\":\"Basic QUFJOkFBSQ==\"}}},\"dmaap\""
+ + ":{\"dmaapConsumerConfiguration\":{\"consumerGroup\":\"other\",\"consumerId\":\"1\",\"dmaapContentType\""
+ + ":\"application/json\",\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2222,\"dmaapProtocol\":\"http\""
+ + ",\"dmaapTopicName\":\"temp\",\"dmaapUserName\":\"admin\",\"dmaapUserPassword\":\"admin\",\"messageLimit\""
+ + ":1000,\"timeoutMs\":1000},\"dmaapProducerConfiguration\":{\"dmaapContentType\":\"application/json\","
+ + "\"dmaapHostName\":\"localhost\",\"dmaapPortNumber\":2223,\"dmaapProtocol\":\"http\",\"dmaaptopicName\""
+ + ":\"temp\",\"dmaapuserName\":\"admin\",\"dmaapuserPassword\":\"admin\"}}}}";
+
private static PrhAppConfig prhAppConfig;
private static AppConfig appConfig;
.requireNonNull(PrhAppConfigTest.class.getClassLoader().getResource(PRH_ENDPOINTS)).getFile();
@BeforeEach
- public void setUp() {
+ void setUp() {
prhAppConfig = spy(PrhAppConfig.class);
appConfig = spy(new AppConfig());
}
@Test
- public void whenApplicationWasStarted_FilePathIsSet() {
+ void whenApplicationWasStarted_FilePathIsSet() {
//
// When
//
}
@Test
- public void whenTheConfigurationFits_GetAaiAndDmaapObjectRepresentationConfiguration()
+ void whenTheConfigurationFits_GetAaiAndDmaapObjectRepresentationConfiguration()
throws IOException {
//
// Given
prhAppConfig.initFileStreamReader();
appConfig.dmaapConsumerConfiguration = prhAppConfig.getDmaapConsumerConfiguration();
appConfig.dmaapPublisherConfiguration = prhAppConfig.getDmaapPublisherConfiguration();
- appConfig.aaiClientConfiguration = prhAppConfig.getAAIClientConfiguration();
+ appConfig.aaiClientConfiguration = prhAppConfig.getAaiClientConfiguration();
//
// Then
//
verify(prhAppConfig, times(1)).setFilepath(anyString());
verify(prhAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNotNull(prhAppConfig.getAAIClientConfiguration());
+ Assertions.assertNotNull(prhAppConfig.getAaiClientConfiguration());
Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
Assertions.assertNotNull(prhAppConfig.getDmaapPublisherConfiguration());
Assertions
Assertions
.assertEquals(appConfig.getDmaapConsumerConfiguration(), prhAppConfig.getDmaapConsumerConfiguration());
Assertions
- .assertEquals(appConfig.getAAIClientConfiguration(), prhAppConfig.getAAIClientConfiguration());
+ .assertEquals(appConfig.getAaiClientConfiguration(), prhAppConfig.getAaiClientConfiguration());
}
@Test
- public void whenFileIsNotExist_ThrowIOException() {
+ void whenFileIsNotExist_ThrowIoException() {
//
// Given
//
//
verify(prhAppConfig, times(1)).setFilepath(anyString());
verify(prhAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNull(prhAppConfig.getAAIClientConfiguration());
+ Assertions.assertNull(prhAppConfig.getAaiClientConfiguration());
Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration());
Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration());
}
@Test
- public void whenFileIsExistsButJsonIsIncorrect() throws IOException {
+ void whenFileIsExistsButJsonIsIncorrect() throws IOException {
//
// Given
//
//
verify(prhAppConfig, times(1)).setFilepath(anyString());
verify(prhAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNotNull(prhAppConfig.getAAIClientConfiguration());
+ Assertions.assertNotNull(prhAppConfig.getAaiClientConfiguration());
Assertions.assertNotNull(prhAppConfig.getDmaapConsumerConfiguration());
Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration());
@Test
- public void whenTheConfigurationFits_ButRootElementIsNotAJsonObject()
+ void whenTheConfigurationFits_ButRootElementIsNotAJsonObject()
throws IOException {
// Given
InputStream inputStream = new ByteArrayInputStream((jsonString.getBytes(
prhAppConfig.initFileStreamReader();
appConfig.dmaapConsumerConfiguration = prhAppConfig.getDmaapConsumerConfiguration();
appConfig.dmaapPublisherConfiguration = prhAppConfig.getDmaapPublisherConfiguration();
- appConfig.aaiClientConfiguration = prhAppConfig.getAAIClientConfiguration();
+ appConfig.aaiClientConfiguration = prhAppConfig.getAaiClientConfiguration();
// Then
verify(prhAppConfig, times(1)).setFilepath(anyString());
verify(prhAppConfig, times(1)).initFileStreamReader();
- Assertions.assertNull(prhAppConfig.getAAIClientConfiguration());
+ Assertions.assertNull(prhAppConfig.getAaiClientConfiguration());
Assertions.assertNull(prhAppConfig.getDmaapConsumerConfiguration());
Assertions.assertNull(prhAppConfig.getDmaapPublisherConfiguration());
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PROJECT
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.prh.IT;
+
+package org.onap.dcaegen2.services.prh.integration;
import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
-import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.IT.junit5.mockito.MockitoExtension;
-import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig;
+import org.onap.dcaegen2.services.prh.integration.junit5.mockito.MockitoExtension;
import org.onap.dcaegen2.services.prh.tasks.ScheduledTasks;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ContextConfiguration;
}
}
-@Configuration
-class ServiceMockProvider {
-
- @Bean
- public PrhAppConfig getPrhAppConfig() {
- return mock(PrhAppConfig.class);
- }
-
- @Bean
- public ConsumerDmaapModel getRequestDetails() {
- return mock(ConsumerDmaapModel.class);
- }
-}
-
/*
* ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
+ * PROJECT
* ================================================================================
* Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.prh.response;
-import java.util.List;
+package org.onap.dcaegen2.services.prh.integration;
+
+import static org.mockito.Mockito.mock;
+
+import org.onap.dcaegen2.services.prh.configuration.PrhAppConfig;
+import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/17/18
+ * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/10/18
*/
-public interface DMaaPConsumerResponse extends DMaaPResponse {
-
+@Configuration
+class ServiceMockProvider {
- List<String> getFetchedMessages();
+ @Bean
+ public PrhAppConfig getPrhAppConfig() {
+ return mock(PrhAppConfig.class);
+ }
+ @Bean
+ public ConsumerDmaapModel getRequestDetails() {
+ return mock(ConsumerDmaapModel.class);
+ }
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PROJECT
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.prh.IT.junit5.mockito;
+
+package org.onap.dcaegen2.services.prh.integration.junit5.mockito;
import static org.mockito.Mockito.mock;
import org.junit.jupiter.api.extension.ParameterContext;
import org.junit.jupiter.api.extension.ParameterResolver;
import org.junit.jupiter.api.extension.TestInstancePostProcessor;
-import org.mockito.MockitoAnnotations;
import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/27/18
*
- * {@code MockitoExtension} showcases the {@link TestInstancePostProcessor} and {@link ParameterResolver} extension APIs
- * of JUnit 5 by providing dependency injection support at the field level and at the method parameter level via Mockito
- * 2.x's {@link Mock @Mock} annotation.
+ * {@code MockitoExtension } showcases the {@link TestInstancePostProcessor} and {@link ParameterResolver} extension
+ * APIs of JUnit 5 by providing dependency injection support at the field level and at the method parameter level
+ * viaMockito 2.x's {@link Mock @Mock} annotation.
*/
public class MockitoExtension implements TestInstancePostProcessor, ParameterResolver {
void whenPassingCorrectJson_validationNotThrowingAnException() {
//given
String message =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
- + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
+ + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\""
+ + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},"
- + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
- + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\","
- + "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\","
- + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]";
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":"
+ + "3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400"
+ + ",\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
+ + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":"
+ + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":"
+ + "\"Nokia\"}}}]";
String parsed =
"{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
+ ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
+ "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},"
- + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
- + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\","
- + "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\","
- + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":"
+ + "3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":"
+ + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
+ + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":"
+ + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":"
+ + "\"Nokia\"}}}";
ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
.ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.pnfName("NOKQTFCOC540002E").build();
}
@Test
- void whenPassingCorrectJsonWithoutIPV4_validationNotThrowingAnException() {
+ void whenPassingCorrectJsonWithoutIpv4_validationNotThrowingAnException() {
//given
String message =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
- + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
+ + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":"
+ + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}"
+ ",\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
+ "\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\""
+ ":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
- ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("")
- .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
- .pnfName("NOKQTFCOC540002E").build();
//when
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsed);
ConsumerDmaapModel consumerDmaapModel = dmaapConsumerJsonParser.getJsonObject(Mono.just((message)))
.block();
//then
+ ConsumerDmaapModel expectedObject = ImmutableConsumerDmaapModel.builder().ipv4("")
+ .ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
+ .pnfName("NOKQTFCOC540002E").build();
Assertions.assertNotNull(consumerDmaapModel);
Assertions.assertEquals(expectedObject, consumerDmaapModel);
}
@Test
- void whenPassingCorrectJsonWihoutIPV6_validationNotThrowingAnException() {
+ void whenPassingCorrectJsonWihoutIpv6_validationNotThrowingAnException() {
//given
String message =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
- + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
+ + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":"
+ + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,"
+ "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate"
}
@Test
- void whenPassingCorrectJsonWihoutIPV4andIPV6_validationThrowingAnException() {
+ void whenPassingCorrectJsonWihoutIpv4andIpv6_validationThrowingAnException() {
String message =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
- + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
+ + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":"
+ + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\""
+ ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\""
.when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
String incorrectMessage =
"[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\""
- + ",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\",\"priority\""
- + ":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"<<SerialNumber>>\","
- + "\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3}}}]";
+ + ",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":"
+ + "{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3"
+ + "}}}]";
StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(incorrectMessage)))
.expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
void whenPassingJsonWithoutPnfSerialNumberOrPnfVendorName_validationThrowingAnException() {
String parsed = "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":"
+ "\"<<SerialNumber>>-reg\",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\""
- + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\""
- + ":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\""
- + "<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,\"version\":3},"
- + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
- + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
- + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSoftwareVersion\":\"v4.5.0.1\","
- + "\"pnfType\":\"AirScale\"}}}";
+ + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\","
+ + "\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,"
+ + "\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,\""
+ + "version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\""
+ + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
+ + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSoftwareVersion\":"
+ + "\"v4.5.0.1\",\"pnfType\":\"AirScale\"}}}";
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsed);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
String jsonWithoutPnfVendorAndSerialNumber =
"[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":"
+ "\"<<SerialNumber>>-reg\",\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\""
- + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\""
- + ":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\""
- + "<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,\"version\":3},"
- + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
- + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
- + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSoftwareVersion\":\"v4.5.0.1\","
- + "\"pnfType\":\"AirScale\"}}}]";
+ + "internalHeaderFields\":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\","
+ + "\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\",reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,"
+ + "\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",startEpochMicrosec\":1519837825682,"
+ + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\","
+ + "\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\","
+ + "\"pnfOamIpv4Address\":\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\","
+ + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\"}}}]";
StepVerifier
.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutPnfVendorAndSerialNumber)))
.expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
@Test
- void whenPassingJsonWithoutIPInformation_validationThrowingAnException() {
+ void whenPassingJsonWithoutIpInformation_validationThrowingAnException() {
String parsed =
- "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\":"
- + "\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},\"lastEpochMicrosec\""
- + ":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\","
- + "\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":"
- + "\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,"
- + "\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":"
- + "\"AJ02\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\","
- + "\"pnfVendorName\":\"Nokia\"}}}";
+ "{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
+ + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\""
+ + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\""
+ + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":"
+ + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":"
+ + "\"AJ02\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":"
+ + "\"AirScale\"," + "\"pnfVendorName\":\"Nokia\"}}}";
DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
JsonElement jsonElement = new JsonParser().parse(parsed);
Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
.when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
- String jsonWithoutIPInformation =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\":"
- + "\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},\"lastEpochMicrosec\""
- + ":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\",\"priority\":\"Normal\","
- + "\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":\"<<SerialNumber>>\",\"sourceName\":"
- + "\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,"
- + "\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":"
- + "\"AJ02\",\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\","
+ String jsonWithoutIpInformation =
+ "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
+ + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\""
+ + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ + "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\""
+ + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\""
+ + ":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfSerialNumber\""
+ + ":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\","
+ "\"pnfVendorName\":\"Nokia\"}}}]";
- StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIPInformation)))
+ StepVerifier.create(dmaapConsumerJsonParser.getJsonObject(Mono.just(jsonWithoutIpInformation)))
.expectSubscription().expectError(DmaapNotFoundException.class).verify();
}
}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import static org.mockito.ArgumentMatchers.any;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.prh.config.ImmutableAAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.ImmutableAaiClientConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
-import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
+import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.service.AAIConsumerClient;
+import org.onap.dcaegen2.services.prh.service.AaiConsumerClient;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/17/18
*/
-class AAIConsumerTaskImplTest {
+class AaiConsumerTaskImplTest {
private static ConsumerDmaapModel consumerDmaapModel;
- private static AAIConsumerTaskImpl aaiConsumerTask;
+ private static AaiConsumerTaskImpl aaiConsumerTask;
private static final String AAI_HOST = "/aai/v12/network/pnfs/pnf/NOKQTFCOC540002E";
private static final Integer PORT = 1234;
private static final String BASE_PATH = "/aai/v12";
private static final String PNF_PATH = "/network/pnfs/pnf";
- private static AAIClientConfiguration aaiClientConfiguration;
- private static AAIConsumerClient aaiConsumerClient;
+ private static AaiClientConfiguration aaiClientConfiguration;
+ private static AaiConsumerClient aaiConsumerClient;
private static AppConfig appConfig;
@BeforeAll
- public static void setUp() {
- aaiClientConfiguration = new ImmutableAAIClientConfiguration.Builder()
+ static void setUp() {
+ aaiClientConfiguration = new ImmutableAaiClientConfiguration.Builder()
.aaiHost(AAI_HOST)
.aaiHostPortNumber(PORT)
.aaiProtocol(PROTOCOL)
.aaiUserName(USER_NAME_PASSWORD)
.aaiUserPassword(USER_NAME_PASSWORD)
- .aaiIgnoreSSLCertificateErrors(true)
+ .aaiIgnoreSslCertificateErrors(true)
.aaiBasePath(BASE_PATH)
.aaiPnfPath(PNF_PATH)
.build();
}
@Test
- public void whenPassedObjectDoesntFit_ThrowsPrhTaskException() {
+ void whenPassedObjectDoesntFit_ThrowsPrhTaskException() {
//given/when
- when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiConsumerTask = new AAIConsumerTaskImpl(appConfig);
+ when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
+ aaiConsumerTask = new AaiConsumerTaskImpl(appConfig);
Executable executableCode = () -> aaiConsumerTask.execute(null);
//then
Assertions
}
@Test
- public void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException, IOException {
+ void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException, IOException {
//given/when
- getAAIConsumerTask_WhenMockingHttpResponseCode("200", false);
+ getAaiConsumerTask_WhenMockingHttpResponseCode("200", false);
String response = aaiConsumerTask.execute(consumerDmaapModel);
//then
}
@Test
- public void whenPassedObjectFits_butIncorrectResponseReturns() throws IOException, AAINotFoundException {
+ void whenPassedObjectFits_butIncorrectResponseReturns() throws IOException, AaiNotFoundException {
//given/when
- getAAIConsumerTask_WhenMockingHttpResponseCode("400", false);
+ getAaiConsumerTask_WhenMockingHttpResponseCode("400", false);
String response = aaiConsumerTask.execute(consumerDmaapModel);
//then
}
@Test
- public void whenPassedObjectFits_ThrowsIOExceptionAndHandleIt() throws IOException {
+ void whenPassedObjectFits_ThrowsIoExceptionAndHandleIt() throws IOException {
//given/when
- getAAIConsumerTask_WhenMockingHttpResponseCode(null, true);
+ getAaiConsumerTask_WhenMockingHttpResponseCode(null, true);
Executable executableCode = () -> aaiConsumerTask.execute(any(ConsumerDmaapModel.class));
Assertions
.assertThrows(PrhTaskException.class, executableCode, "HttpClient throws IOException");
}
- private static void getAAIConsumerTask_WhenMockingHttpResponseCode(String httpResponseCode, boolean throwsException)
+ private static void getAaiConsumerTask_WhenMockingHttpResponseCode(String httpResponseCode, boolean throwsException)
throws IOException {
- aaiConsumerClient = mock(AAIConsumerClient.class);
+ aaiConsumerClient = mock(AaiConsumerClient.class);
if (throwsException) {
when(aaiConsumerClient.getHttpResponse(consumerDmaapModel)).thenThrow(IOException.class);
} else {
when(aaiConsumerClient.getHttpResponse(consumerDmaapModel)).thenReturn(Optional.of(httpResponseCode));
}
- when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiConsumerTask = spy(new AAIConsumerTaskImpl(appConfig));
+ when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
+ aaiConsumerTask = spy(new AaiConsumerTaskImpl(appConfig));
when(aaiConsumerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration);
doReturn(aaiConsumerClient).when(aaiConsumerTask).resolveClient();
}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
-import static org.mockito.Mockito.*;
-
-
@Configuration
-public class AAIConsumerTaskSpy {
+public class AaiConsumerTaskSpy {
@Bean
@Primary
- public AAIConsumerTask registerSimpleAAIPublisherTask() {
+ public AaiConsumerTask registerSimpleAaiPublisherTask() {
AppConfig appConfig = mock(AppConfig.class);
- when(appConfig.getAAIClientConfiguration()).thenReturn(mock(AAIClientConfiguration.class));
- return spy(new AAIConsumerTaskImpl(appConfig));
+ when(appConfig.getAaiClientConfiguration()).thenReturn(mock(AaiClientConfiguration.class));
+ return spy(new AaiConsumerTaskImpl(appConfig));
}
}
\ No newline at end of file
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
-import org.onap.dcaegen2.services.prh.config.ImmutableAAIClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
+import org.onap.dcaegen2.services.prh.config.ImmutableAaiClientConfiguration;
+
+import org.onap.dcaegen2.services.prh.configuration.AppConfig;
+import org.onap.dcaegen2.services.prh.exceptions.AaiNotFoundException;
+
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.configuration.AppConfig;
-import org.onap.dcaegen2.services.prh.exceptions.AAINotFoundException;
-import org.onap.dcaegen2.services.prh.service.AAIProducerClient;
+
+import org.onap.dcaegen2.services.prh.service.AaiProducerClient;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/14/18
*/
-class AAIProducerTaskImplTest {
+class AaiProducerTaskImplTest {
private static final String AAI_HOST = "/aai/v11/network/pnfs/pnf/NOKQTFCOC540002E";
private static final String PNF_PATH = "/network/pnfs/pnf";
private static ConsumerDmaapModel consumerDmaapModel;
- private static AAIProducerTaskImpl aaiProducerTask;
- private static AAIClientConfiguration aaiClientConfiguration;
- private static AAIProducerClient aaiProducerClient;
+ private static AaiProducerTaskImpl aaiProducerTask;
+ private static AaiClientConfiguration aaiClientConfiguration;
+ private static AaiProducerClient aaiProducerClient;
private static AppConfig appConfig;
@BeforeAll
- public static void setUp() {
- aaiClientConfiguration = new ImmutableAAIClientConfiguration.Builder()
+ static void setUp() {
+ aaiClientConfiguration = new ImmutableAaiClientConfiguration.Builder()
.aaiHost(AAI_HOST)
.aaiHostPortNumber(PORT)
.aaiProtocol(PROTOCOL)
.aaiUserName(USER_NAME_PASSWORD)
.aaiUserPassword(USER_NAME_PASSWORD)
- .aaiIgnoreSSLCertificateErrors(true)
+ .aaiIgnoreSslCertificateErrors(true)
.aaiBasePath(BASE_PATH)
.aaiPnfPath(PNF_PATH)
.build();
}
@Test
- public void whenPassedObjectDoesntFit_ThrowsPrhTaskException() {
+ void whenPassedObjectDoesntFit_ThrowsPrhTaskException() {
//given/when/
- when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiProducerTask = new AAIProducerTaskImpl(appConfig);
+ when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
+ aaiProducerTask = new AaiProducerTaskImpl(appConfig);
Executable executableCode = () -> aaiProducerTask.execute(null);
//then
}
@Test
- public void whenPassedObjectFits_ReturnsCorrectStatus() throws AAINotFoundException, URISyntaxException {
+ void whenPassedObjectFits_ReturnsCorrectStatus() throws AaiNotFoundException, URISyntaxException {
//given/when
- getAAIProducerTask_whenMockingResponseObject(200, false);
+ getAaiProducerTask_whenMockingResponseObject(200, false);
ConsumerDmaapModel response = aaiProducerTask.execute(consumerDmaapModel);
//then
@Test
- public void whenPassedObjectFits_butIncorrectResponseReturns() throws IOException, URISyntaxException {
+ void whenPassedObjectFits_butIncorrectResponseReturns() throws URISyntaxException {
//given/when
- getAAIProducerTask_whenMockingResponseObject(400, false);
+ getAaiProducerTask_whenMockingResponseObject(400, false);
Executable executableCode = () -> aaiProducerTask.execute(consumerDmaapModel);
Assertions
.assertThrows(PrhTaskException.class, executableCode, "Incorrect status code in response message");
}
@Test
- public void whenPassedObjectFits_butHTTPClientThrowsIOExceptionHandleIt() throws URISyntaxException {
+ void whenPassedObjectFits_butHttpClientThrowsIoExceptionHandleIt() throws URISyntaxException {
//given/when
- getAAIProducerTask_whenMockingResponseObject(0, true);
+ getAaiProducerTask_whenMockingResponseObject(0, true);
Executable executableCode = () -> aaiProducerTask.execute(consumerDmaapModel);
Assertions
}
- private static void getAAIProducerTask_whenMockingResponseObject(int statusCode, boolean throwsException)
+ private static void getAaiProducerTask_whenMockingResponseObject(int statusCode, boolean throwsException)
throws URISyntaxException {
//given
- aaiProducerClient = mock(AAIProducerClient.class);
+ aaiProducerClient = mock(AaiProducerClient.class);
if (throwsException) {
when(aaiProducerClient.getHttpResponse(consumerDmaapModel)).thenThrow(URISyntaxException.class);
} else {
when(aaiProducerClient.getHttpResponse(consumerDmaapModel)).thenReturn(Optional.of(statusCode));
}
- when(appConfig.getAAIClientConfiguration()).thenReturn(aaiClientConfiguration);
- aaiProducerTask = spy(new AAIProducerTaskImpl(appConfig));
+ when(appConfig.getAaiClientConfiguration()).thenReturn(aaiClientConfiguration);
+ aaiProducerTask = spy(new AaiProducerTaskImpl(appConfig));
when(aaiProducerTask.resolveConfiguration()).thenReturn(aaiClientConfiguration);
doReturn(aaiProducerClient).when(aaiProducerTask).resolveClient();
}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
-import org.onap.dcaegen2.services.prh.config.AAIClientConfiguration;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+
+import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
-import org.onap.dcaegen2.services.prh.service.AAIProducerClient;
+import org.onap.dcaegen2.services.prh.service.AaiProducerClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
-import static org.mockito.Mockito.*;
-
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/13/18
*/
@Configuration
-public class AAIPublisherTaskSpy {
+public class AaiPublisherTaskSpy {
@Bean
@Primary
- public AAIProducerTask registerSimpleAAIPublisherTask() {
+ public AaiProducerTask registerSimpleAaiPublisherTask() {
AppConfig appConfig = spy(AppConfig.class);
- doReturn(mock(AAIClientConfiguration.class)).when(appConfig).getAAIClientConfiguration();
- AAIProducerTaskImpl aaiProducerTask = spy(new AAIProducerTaskImpl(appConfig));
- AAIProducerClient aaiProducerClient = mock(AAIProducerClient.class);
- doReturn(mock(AAIClientConfiguration.class)).when(aaiProducerTask).resolveConfiguration();
+ doReturn(mock(AaiClientConfiguration.class)).when(appConfig).getAaiClientConfiguration();
+ AaiProducerTaskImpl aaiProducerTask = spy(new AaiProducerTaskImpl(appConfig));
+ AaiProducerClient aaiProducerClient = mock(AaiProducerClient.class);
+ doReturn(mock(AaiClientConfiguration.class)).when(aaiProducerTask).resolveConfiguration();
doReturn(aaiProducerClient).when(aaiProducerTask).resolveClient();
return aaiProducerTask;
}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import static org.junit.jupiter.api.Assertions.assertEquals;
import com.google.gson.JsonElement;
import com.google.gson.JsonParser;
import java.util.Optional;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.exceptions.DmaapEmptyResponseException;
-import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser;
private static String parsed;
@BeforeAll
- public static void setUp() {
+ static void setUp() {
dmaapConsumerConfiguration = new ImmutableDmaapConsumerConfiguration.Builder().consumerGroup("OpenDCAE-c12")
.consumerId("c12").dmaapContentType("application/json").dmaapHostName("54.45.33.2").dmaapPortNumber(1234)
.dmaapProtocol("https").dmaapUserName("PRH").dmaapUserPassword("PRH")
- .dmaapTopicName("unauthenticated.SEC_OTHER_OUTPUT").timeoutMS(-1).messageLimit(-1).build();
+ .dmaapTopicName("unauthenticated.SEC_OTHER_OUTPUT").timeoutMs(-1).messageLimit(-1).build();
consumerDmaapModel = ImmutableConsumerDmaapModel.builder().ipv4("10.16.123.234")
.ipv6("0:0:0:0:0:FFFF:0A10:7BEA")
.pnfName("NOKQTFCOC540002E").build();
appConfig = mock(AppConfig.class);
message =
- "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
- + ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
- + "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "[{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\","
+ + "\"eventName\":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\""
+ + ":{},\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},"
- + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
- + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\","
- + "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\","
- + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}]";
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\""
+ + ":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":"
+ + "1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":"
+ + "\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":"
+ + "\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":"
+ + "\"Nokia\"}}}]";
parsed =
"{\"event\":{\"commonEventHeader\":{\"domain\":\"other\",\"eventId\":\"<<SerialNumber>>-reg\",\"eventName\""
+ ":\"pnfRegistration_5GDU\",\"eventType\":\"pnfRegistration\",\"internalHeaderFields\":{},"
+ "\"lastEpochMicrosec\":1519837825682,\"nfNamingCode\":\"5GRAN\",\"nfcNamingCode\":\"5DU\","
+ "\"priority\":\"Normal\",\"reportingEntityName\":\"5GRAN_DU\",\"sequence\":0,\"sourceId\":"
- + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,\"version\":3},"
- + "\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\",\"pnfLastServiceDate\":1517206400,"
- + "\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\",\"pnfOamIpv4Address\":\"10.16.123.234\","
- + "\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\",\"pnfSerialNumber\":\"QTFCOC540002E\","
- + "\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\",\"pnfVendorName\":\"Nokia\"}}}";
+ + "\"<<SerialNumber>>\",\"sourceName\":\"5GRAN_DU\",\"startEpochMicrosec\":1519837825682,"
+ + "\"version\":3},\"otherFields\":{\"otherFieldsVersion\":1,\"pnfFamily\":\"BBU\","
+ + "\"pnfLastServiceDate\":1517206400,\"pnfManufactureDate\":1516406400,\"pnfModelNumber\":\"AJ02\","
+ + "\"pnfOamIpv4Address\":\"10.16.123.234\",\"pnfOamIpv6Address\":\"0:0:0:0:0:FFFF:0A10:7BEA\","
+ + "\"pnfSerialNumber\":\"QTFCOC540002E\",\"pnfSoftwareVersion\":\"v4.5.0.1\",\"pnfType\":\"AirScale\","
+ + "\"pnfVendorName\":\"Nokia\"}}}";
}
@Test
- public void whenPassedObjectDoesntFit_DoesNotThrowPrhTaskException() throws PrhTaskException {
+ void whenPassedObjectDoesntFit_DoesNotThrowPrhTaskException() {
//given
prepareMocksForDmaapConsumer(Optional.empty());
}
@Test
- public void whenPassedObjectFits_ReturnsCorrectResponse() throws PrhTaskException {
+ void whenPassedObjectFits_ReturnsCorrectResponse() {
//given
prepareMocksForDmaapConsumer(Optional.of(message));
//when
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import static org.mockito.Mockito.doReturn;
AppConfig appConfig = spy(AppConfig.class);
doReturn(mock(DmaapConsumerConfiguration.class)).when(appConfig).getDmaapConsumerConfiguration();
DmaapConsumerTaskImpl dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig));
- DMaaPConsumerReactiveHttpClient DMaaPConsumerReactiveHttpClient = mock(
+ DMaaPConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient = mock(
DMaaPConsumerReactiveHttpClient.class);
doReturn(mock(DmaapConsumerConfiguration.class)).when(dmaapConsumerTask).resolveConfiguration();
- doReturn(DMaaPConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient();
+ doReturn(dmaapConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient();
return dmaapConsumerTask;
}
}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import static org.mockito.Mockito.doReturn;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import static org.junit.jupiter.api.Assertions.assertThrows;
private static DmaapPublisherConfiguration dmaapPublisherConfiguration;
@BeforeAll
- public static void setUp() {
+ static void setUp() {
dmaapPublisherConfiguration = new ImmutableDmaapPublisherConfiguration.Builder()
.dmaapContentType("application/json").dmaapHostName("54.45.33.2").dmaapPortNumber(1234)
.dmaapProtocol("https").dmaapUserName("PRH").dmaapUserPassword("PRH")
}
@Test
- public void whenPassedObjectDoesntFit_ThrowsPrhTaskException() {
+ void whenPassedObjectDoesntFit_ThrowsPrhTaskException() {
//given
when(appConfig.getDmaapPublisherConfiguration()).thenReturn(dmaapPublisherConfiguration);
dmaapPublisherTask = new DmaapPublisherTaskImpl(appConfig);
}
@Test
- public void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException {
+ void whenPassedObjectFits_ReturnsCorrectStatus() throws PrhTaskException {
//given
prepareMocksForTests(HttpStatus.OK.value());
@Test
- public void whenPassedObjectFits_butIncorrectResponseReturns() throws DmaapNotFoundException {
+ void whenPassedObjectFits_butIncorrectResponseReturns() throws DmaapNotFoundException {
//given
prepareMocksForTests(HttpStatus.UNAUTHORIZED.value());
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.tasks;
import static org.mockito.Mockito.spy;
private DmaapPublisherTask dmaapPublisherTaskImplSpy;
@Autowired
- private AAIProducerTask aaiPublisherTaskImplSpy;
+ private AaiProducerTask aaiPublisherTaskImplSpy;
@Bean
@Primary
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.model;
import com.google.gson.annotations.SerializedName;
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.model.utils;
import org.apache.http.HttpStatus;
package org.onap.dcaegen2.services.prh.model;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
-import org.apache.http.HttpStatus;
import org.apache.http.StatusLine;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import java.io.IOException;
-import java.util.Optional;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
class CommonFunctionsTest {
+
// Given
private ConsumerDmaapModel model = new ConsumerDmaapModelForUnitTest();
- private final static HttpResponse httpResponseMock = mock(HttpResponse.class);
- private final static HttpEntity httpEntityMock = mock(HttpEntity.class);
- private final static StatusLine statusLineMock = mock(StatusLine.class);
+ private static final HttpResponse httpResponseMock = mock(HttpResponse.class);
+ private static final HttpEntity httpEntityMock = mock(HttpEntity.class);
+ private static final StatusLine statusLineMock = mock(StatusLine.class);
@BeforeAll
static void setup() {
@Test
void createJsonBody_shouldReturnJsonInString() {
- String expectedResult = "{\"pnf-name\":\"NOKnhfsadhff\",\"ipaddress-v4-oam\":\"256.22.33.155\",\"ipaddress-v6-oam\":\"2001:0db8:85a3:0000:0000:8a2e:0370:7334\"}";
+ String expectedResult = "{\"pnf-name\":\"NOKnhfsadhff\",\"ipaddress-v4-oam\":\"256.22.33.155\""
+ + ",\"ipaddress-v6-oam\":\"2001:0db8:85a3:0000:0000:8a2e:0370:7334\"}";
assertEquals(expectedResult, CommonFunctions.createJsonBody(model));
}
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
-public class ConsumerDmaapModelTest {
-
- // Given
- private ConsumerDmaapModel consumerDmaapModel;
- private String pnfName = "NOKnhfsadhff";
- private String ipv4 = "11.22.33.155";
- private String ipv6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
+class ConsumerDmaapModelTest {
@Test
- public void consumerDmaapModelBuilder_shouldBuildAnObject() {
+ void consumerDmaapModelBuilder_shouldBuildAnObject() {
// When
- consumerDmaapModel = ImmutableConsumerDmaapModel.builder()
- .pnfName(pnfName)
- .ipv4(ipv4)
- .ipv6(ipv6)
- .build();
+ // Given
+ String pnfName = "NOKnhfsadhff";
+ String ipv4 = "11.22.33.155";
+ String ipv6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334";
+ ConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel.builder()
+ .pnfName(pnfName)
+ .ipv4(ipv4)
+ .ipv6(ipv6)
+ .build();
// Then
Assertions.assertNotNull(consumerDmaapModel);
- Assertions.assertEquals(pnfName,consumerDmaapModel.getPnfName());
- Assertions.assertEquals(ipv4,consumerDmaapModel.getIpv4());
- Assertions.assertEquals(ipv6,consumerDmaapModel.getIpv6());
+ Assertions.assertEquals(pnfName, consumerDmaapModel.getPnfName());
+ Assertions.assertEquals(ipv4, consumerDmaapModel.getIpv4());
+ Assertions.assertEquals(ipv6, consumerDmaapModel.getIpv6());
}
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
package org.onap.dcaegen2.services.prh.model.utils;
-import org.apache.http.HttpStatus;
-import org.junit.jupiter.api.Test;
-
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import org.apache.http.HttpStatus;
+import org.junit.jupiter.api.Test;
-public class HttpUtilsTest {
+class HttpUtilsTest {
@Test
- public void isSuccessfulResponseCode_shouldReturnTrue() {
+ void isSuccessfulResponseCode_shouldReturnTrue() {
assertTrue(HttpUtils.isSuccessfulResponseCode(HttpUtils.SC_ACCEPTED));
}
@Test
- public void isSuccessfulResponseCode_shouldReturnFalse() {
+ void isSuccessfulResponseCode_shouldReturnFalse() {
assertFalse(HttpUtils.isSuccessfulResponseCode(HttpStatus.SC_BAD_GATEWAY));
}
}
\ No newline at end of file
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.config;
import org.immutables.gson.Gson;
public abstract String consumerGroup();
@Value.Parameter
- public abstract Integer timeoutMS();
+ public abstract Integer timeoutMs();
@Value.Parameter
public abstract Integer messageLimit();
Builder consumerGroup(String consumerGroup);
- Builder timeoutMS(Integer timeoutMS);
+ Builder timeoutMs(Integer timeoutMs);
Builder messageLimit(Integer messageLimit);
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.config;
import java.io.Serializable;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.config;
import org.immutables.gson.Gson;
+++ /dev/null
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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.onap.dcaegen2.services.prh.response;
-
-import static java.util.Collections.unmodifiableList;
-
-import java.util.Collections;
-import java.util.List;
-import java.util.Optional;
-import java.util.StringJoiner;
-import org.springframework.lang.NonNull;
-import org.springframework.lang.Nullable;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/17/18
- */
-public class DMaaPConsumerResponseImpl implements DMaaPConsumerResponse {
-
-
- private final Integer responseCode;
- private final String responseMessage;
- private final List<String> fetchedMessage;
-
- public DMaaPConsumerResponseImpl(@NonNull Integer responseCode, @NonNull String responseMessage,
- @Nullable List<String> fetchedMessage) {
- this.responseCode = responseCode;
- this.responseMessage = responseMessage;
- this.fetchedMessage = Optional.ofNullable(fetchedMessage).orElse(Collections.emptyList());
- }
-
-
- @Override
- public String getResponseMessage() {
- return responseMessage;
- }
-
- @Override
- public Integer getResponseCode() {
- return responseCode;
- }
-
- @Override
- public List<String> getFetchedMessages() {
- return unmodifiableList(fetchedMessage);
- }
-
- @Override
- public String toString() {
- return new StringJoiner(", ", this.getClass().getSimpleName() + "[", "]")
- .add("responseCode=" + responseCode)
- .add("responseMessage=" + responseMessage)
- .add("fetchedMessage=" + fetchedMessage)
- .toString();
- }
-}
+++ /dev/null
-/*
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. 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.onap.dcaegen2.services.prh.response;
-
-/**
- * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 4/17/18
- */
-public interface DMaaPResponse {
-
- Integer getResponseCode();
-
-
- String getResponseMessage();
-}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.service;
import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
private final Logger logger = LoggerFactory.getLogger(this.getClass());
- private String dMaaPContentType;
- private String dMaaPUserName;
- private String dMaaPUserPassword;
+ private String dmaaPContentType;
+ private String dmaaPUserName;
+ private String dmaaPUserPassword;
public DMaaPReactiveWebClient fromConfiguration(DmaapCustomConfig dmaapCustomConfig) {
- this.dMaaPUserName = dmaapCustomConfig.dmaapUserName();
- this.dMaaPUserPassword = dmaapCustomConfig.dmaapUserPassword();
- this.dMaaPContentType = dmaapCustomConfig.dmaapContentType();
+ this.dmaaPUserName = dmaapCustomConfig.dmaapUserName();
+ this.dmaaPUserPassword = dmaapCustomConfig.dmaapUserPassword();
+ this.dmaaPContentType = dmaapCustomConfig.dmaapContentType();
return this;
}
public WebClient build() {
return WebClient.builder()
- .defaultHeader(HttpHeaders.CONTENT_TYPE, dMaaPContentType)
- .filter(basicAuthentication(dMaaPUserName, dMaaPUserPassword))
+ .defaultHeader(HttpHeaders.CONTENT_TYPE, dmaaPContentType)
+ .filter(basicAuthentication(dmaaPUserName, dmaaPUserPassword))
.filter(logRequest())
.filter(logResponse())
.build();
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.service.consumer;
import java.net.URI;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.service.producer;
import java.net.URI;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.service;
import static org.mockito.Mockito.mock;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/5/18
*/
-public class DMaaPReactiveWebClientTest {
+class DMaaPReactiveWebClientTest {
@Test
- public void builder_shouldBuildDMaaPReactiveWebClient() {
+ void builder_shouldBuildDMaaPReactiveWebClient() {
//given
DmaapConsumerConfiguration dmaapConsumerConfiguration = mock(DmaapConsumerConfiguration.class);
- WebClient dMaaPReactiveWebClient;
- String dMaaPContentType = "*/*";
- String dMaaPUserName = "DMaaP";
- String dMaaPUserPassword = "DMaaP";
+ String dmaaPContentType = "*/*";
+ String dmaaPUserName = "DMaaP";
+ String dmaaPUserPassword = "DMaaP";
//when
- when(dmaapConsumerConfiguration.dmaapContentType()).thenReturn(dMaaPContentType);
- when(dmaapConsumerConfiguration.dmaapUserName()).thenReturn(dMaaPUserName);
- when(dmaapConsumerConfiguration.dmaapUserPassword()).thenReturn(dMaaPUserPassword);
- dMaaPReactiveWebClient = new DMaaPReactiveWebClient()
+ when(dmaapConsumerConfiguration.dmaapContentType()).thenReturn(dmaaPContentType);
+ when(dmaapConsumerConfiguration.dmaapUserName()).thenReturn(dmaaPUserName);
+ when(dmaapConsumerConfiguration.dmaapUserPassword()).thenReturn(dmaaPUserPassword);
+ WebClient dmaapreactiveWebClient = new DMaaPReactiveWebClient()
.fromConfiguration(dmaapConsumerConfiguration)
.build();
//then
- Assertions.assertNotNull(dMaaPReactiveWebClient);
+ Assertions.assertNotNull(dmaapreactiveWebClient);
}
}
\ No newline at end of file
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.config.ImmutableDmaapConsumerConfiguration;
-public class DmaapConsumerConfigurationTest {
+class DmaapConsumerConfigurationTest {
@Test
- public void builder_shouldBuildConfigurationObject() {
+ void builder_shouldBuildConfigurationObject() {
// Given
DmaapConsumerConfiguration configuration;
.dmaapUserPassword(dmaapUserPassword)
.dmaapContentType(dmaapContentType)
.consumerGroup(consumerGroup)
- .timeoutMS(timeoutMs)
+ .timeoutMs(timeoutMs)
.messageLimit(messageLimit)
.build();
Assertions.assertEquals(dmaapUserName, configuration.dmaapUserName());
Assertions.assertEquals(dmaapUserPassword, configuration.dmaapUserPassword());
Assertions.assertEquals(consumerGroup, configuration.consumerGroup());
- Assertions.assertEquals(timeoutMs, configuration.timeoutMS());
+ Assertions.assertEquals(timeoutMs, configuration.timeoutMs());
Assertions.assertEquals(messageLimit, configuration.messageLimit());
}
}
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.prh.config.ImmutableDmaapPublisherConfiguration;
-public class DmaapPublisherConfigurationTest {
+class DmaapPublisherConfigurationTest {
@Test
- public void builder_shouldBuildConfigurationObject() {
+ void builder_shouldBuildConfigurationObject() {
// Given
DmaapPublisherConfiguration configuration;
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.service.consumer;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import java.net.URI;
import java.net.URISyntaxException;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec;
import org.springframework.web.reactive.function.client.WebClient.ResponseSpec;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 6/27/18
*/
-public class DMaaPConsumerReactiveHttpClientTest {
+class DMaaPConsumerReactiveHttpClientTest {
- private static DMaaPConsumerReactiveHttpClient DMaaPConsumerReactiveHttpClient;
+ private DMaaPConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient;
- private static DmaapConsumerConfiguration consumerConfigurationMock = mock(DmaapConsumerConfiguration.class);
+ private DmaapConsumerConfiguration consumerConfigurationMock = mock(DmaapConsumerConfiguration.class);
private static final String JSON_MESSAGE = "{ \"responseFromDmaap\": \"Success\"}";
- private static Mono<String> expectedResult = Mono.empty();
- private static WebClient webClient = mock(WebClient.class);
- private static RequestHeadersUriSpec requestHeadersSpec;
- private static ResponseSpec responseSpec;
+ private Mono<String> expectedResult = Mono.empty();
+ private WebClient webClient = mock(WebClient.class);
+ private RequestHeadersUriSpec requestHeadersSpec;
+ private ResponseSpec responseSpec;
- @BeforeAll
- public static void setUp() {
+ @BeforeEach
+ void setUp() {
when(consumerConfigurationMock.dmaapHostName()).thenReturn("54.45.33.2");
when(consumerConfigurationMock.dmaapProtocol()).thenReturn("https");
when(consumerConfigurationMock.dmaapPortNumber()).thenReturn(1234);
when(consumerConfigurationMock.consumerGroup()).thenReturn("OpenDCAE-c12");
when(consumerConfigurationMock.consumerId()).thenReturn("c12");
- DMaaPConsumerReactiveHttpClient = new DMaaPConsumerReactiveHttpClient(consumerConfigurationMock);
+ dmaapConsumerReactiveHttpClient = new DMaaPConsumerReactiveHttpClient(consumerConfigurationMock);
webClient = spy(WebClient.builder()
.defaultHeader(HttpHeaders.CONTENT_TYPE, consumerConfigurationMock.dmaapContentType())
.filter(basicAuthentication(consumerConfigurationMock.dmaapUserName(),
@Test
- public void getHttpResponse_Success() {
+ void getHttpResponse_Success() {
//given
expectedResult = Mono.just(JSON_MESSAGE);
//when
mockDependantObjects();
doReturn(expectedResult).when(responseSpec).bodyToMono(String.class);
- DMaaPConsumerReactiveHttpClient.createDMaaPWebClient(webClient);
- Mono<String> response = DMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse();
+ dmaapConsumerReactiveHttpClient.createDMaaPWebClient(webClient);
+ Mono<String> response = dmaapConsumerReactiveHttpClient.getDMaaPConsumerResponse();
//then
StepVerifier.create(response).expectSubscription()
}
@Test
- public void getHttpResponse_whenURISyntaxExceptionHasBeenThrown() throws URISyntaxException {
+ void getHttpResponse_whenUriSyntaxExceptionHasBeenThrown() throws URISyntaxException {
//given
- DMaaPConsumerReactiveHttpClient = spy(DMaaPConsumerReactiveHttpClient);
+ dmaapConsumerReactiveHttpClient = spy(dmaapConsumerReactiveHttpClient);
//when
when(webClient.get()).thenReturn(requestHeadersSpec);
- DMaaPConsumerReactiveHttpClient.createDMaaPWebClient(webClient);
- when(DMaaPConsumerReactiveHttpClient.getUri()).thenThrow(URISyntaxException.class);
+ dmaapConsumerReactiveHttpClient.createDMaaPWebClient(webClient);
+ when(dmaapConsumerReactiveHttpClient.getUri()).thenThrow(URISyntaxException.class);
//then
- StepVerifier.create(DMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()).expectSubscription()
+ StepVerifier.create(dmaapConsumerReactiveHttpClient.getDMaaPConsumerResponse()).expectSubscription()
.expectError(Exception.class).verify();
}
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcaegen2.services.prh.service.producer;
import static org.mockito.ArgumentMatchers.any;
import java.net.URI;
import java.net.URISyntaxException;
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18
*/
-public class DMaaPProducerReactiveHttpClientTest {
+class DMaaPProducerReactiveHttpClientTest {
- private static DMaaPProducerReactiveHttpClient dMaaPProducerReactiveHttpClient;
+ private DMaaPProducerReactiveHttpClient dmaapProducerReactiveHttpClient;
- private static DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock(
+ private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock(
DmaapPublisherConfiguration.class);
- private static final Integer RESPONSE_SUCCESS = 200;
- private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
- private static WebClient webClient = mock(WebClient.class);
- private static RequestBodyUriSpec requestBodyUriSpec;
- private static ResponseSpec responseSpec;
+ private ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
+ private WebClient webClient = mock(WebClient.class);
+ private RequestBodyUriSpec requestBodyUriSpec;
+ private ResponseSpec responseSpec;
- @BeforeAll
- public static void setUp() {
+ @BeforeEach
+ void setUp() {
when(dmaapPublisherConfigurationMock.dmaapHostName()).thenReturn("54.45.33.2");
when(dmaapPublisherConfigurationMock.dmaapProtocol()).thenReturn("https");
when(dmaapPublisherConfigurationMock.dmaapPortNumber()).thenReturn(1234);
when(dmaapPublisherConfigurationMock.dmaapContentType()).thenReturn("application/json");
when(dmaapPublisherConfigurationMock.dmaapTopicName()).thenReturn("pnfReady");
- dMaaPProducerReactiveHttpClient = new DMaaPProducerReactiveHttpClient(dmaapPublisherConfigurationMock);
+ dmaapProducerReactiveHttpClient = new DMaaPProducerReactiveHttpClient(dmaapPublisherConfigurationMock);
webClient = spy(WebClient.builder()
.defaultHeader(HttpHeaders.CONTENT_TYPE, dmaapPublisherConfigurationMock.dmaapContentType())
}
@Test
- public void getHttpResponse_Success() {
+ void getHttpResponse_Success() {
//given
- Mono<Integer> expectedResult = Mono.just(RESPONSE_SUCCESS);
+ Integer responseSuccess = 200;
+ Mono<Integer> expectedResult = Mono.just(responseSuccess);
//when
mockWebClientDependantObject();
doReturn(expectedResult).when(responseSpec).bodyToMono(String.class);
- dMaaPProducerReactiveHttpClient.createDMaaPWebClient(webClient);
- Mono<String> response = dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(Mono.just(consumerDmaapModel));
+ dmaapProducerReactiveHttpClient.createDMaaPWebClient(webClient);
+ Mono<String> response = dmaapProducerReactiveHttpClient.getDMaaPProducerResponse(Mono.just(consumerDmaapModel));
//then
Assertions.assertEquals(response.block(), expectedResult.block());
}
@Test
- public void getHttpResponse_whenURISyntaxExceptionHasBeenThrown() throws URISyntaxException {
+ void getHttpResponse_whenUriSyntaxExceptionHasBeenThrown() throws URISyntaxException {
//given
- dMaaPProducerReactiveHttpClient = spy(dMaaPProducerReactiveHttpClient);
+ dmaapProducerReactiveHttpClient = spy(dmaapProducerReactiveHttpClient);
//when
when(webClient.post()).thenReturn(requestBodyUriSpec);
- dMaaPProducerReactiveHttpClient.createDMaaPWebClient(webClient);
- when(dMaaPProducerReactiveHttpClient.getUri()).thenThrow(URISyntaxException.class);
+ dmaapProducerReactiveHttpClient.createDMaaPWebClient(webClient);
+ when(dmaapProducerReactiveHttpClient.getUri()).thenThrow(URISyntaxException.class);
//then
- StepVerifier.create(dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(any())).expectSubscription()
+ StepVerifier.create(dmaapProducerReactiveHttpClient.getDMaaPProducerResponse(any())).expectSubscription()
.expectError(Exception.class).verify();
}