summaryrefslogtreecommitdiffstats
path: root/adapters
diff options
context:
space:
mode:
Diffstat (limited to 'adapters')
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml2
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java4
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/AbstractPkgNotificationConverter.java15
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/PkgChangeNotificationConverter.java10
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/PkgOnboardingNotificationConverter.java8
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java11
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/OAuthNotificationServiceProvider.java1
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java61
-rw-r--r--adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java119
9 files changed, 144 insertions, 87 deletions
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml
index 54f05859d9..093dab3fd2 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-adapter-api/pom.xml
@@ -66,6 +66,7 @@
<withXml>true</withXml>
<useRxJava2>true</useRxJava2>
<serializableModel>true</serializableModel>
+ <dateLibrary>java8-localdatetime</dateLibrary>
</configOptions>
</configuration>
</execution>
@@ -86,6 +87,7 @@
<withXml>true</withXml>
<useRxJava2>true</useRxJava2>
<serializableModel>true</serializableModel>
+ <dateLibrary>java8-localdatetime</dateLibrary>
</configOptions>
</configuration>
</execution>
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java
index bb2730bd2b..e3166447e6 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/MessageConverterConfiguration.java
@@ -56,8 +56,8 @@ public class MessageConverterConfiguration {
final DefaultConversionService service = new DefaultConversionService();
service.addConverter(new VnfPkgInfoConverter(vnfmAdapterUrlProvider));
service.addConverter(new PkgmSubscriptionRequestConverter());
- service.addConverter(new PkgChangeNotificationConverter());
- service.addConverter(new PkgOnboardingNotificationConverter());
+ service.addConverter(new PkgChangeNotificationConverter(vnfmAdapterUrlProvider));
+ service.addConverter(new PkgOnboardingNotificationConverter(vnfmAdapterUrlProvider));
return service;
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/AbstractPkgNotificationConverter.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/AbstractPkgNotificationConverter.java
index e1c43098f8..b8a6fb9560 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/AbstractPkgNotificationConverter.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/AbstractPkgNotificationConverter.java
@@ -20,6 +20,7 @@
package org.onap.so.adapters.vnfmadapter.converters.etsicatalog.sol003;
+import org.onap.so.adapters.vnfmadapter.VnfmAdapterUrlProvider;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgmLinks;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinks;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinksVnfPackage;
@@ -30,20 +31,26 @@ import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notifi
*
* @author andrew.a.lamb@est.tech
*/
-abstract public class AbstractPkgNotificationConverter {
+public abstract class AbstractPkgNotificationConverter {
+
+ private final VnfmAdapterUrlProvider vnfmAdapterUrlProvider;
+
+ public AbstractPkgNotificationConverter(final VnfmAdapterUrlProvider vnfmAdapterUrlProvider) {
+ this.vnfmAdapterUrlProvider = vnfmAdapterUrlProvider;
+ }
protected URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinks convert(
- final PkgmLinks pkgmLinks) {
+ final PkgmLinks pkgmLinks, final String vnfPkgId, final String subscriptionId) {
final URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinksVnfPackage linksVnfPackage =
new URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinksVnfPackage();
if (pkgmLinks.getVnfPackage() != null) {
- linksVnfPackage.setHref(pkgmLinks.getVnfPackage().getHref());
+ linksVnfPackage.setHref(vnfmAdapterUrlProvider.getVnfPackageUrl(vnfPkgId));
}
final URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinksVnfPackage linksSubscription =
new URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinksVnfPackage();
if (pkgmLinks.getSubscription() != null) {
- linksSubscription.setHref(pkgmLinks.getSubscription().getHref());
+ linksSubscription.setHref(vnfmAdapterUrlProvider.getSubscriptionUriString(subscriptionId));
}
final URIisprovidedbytheclientwhencreatingthesubscriptionVnfPackageOnboardingNotificationLinks links =
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/PkgChangeNotificationConverter.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/PkgChangeNotificationConverter.java
index 8c4168632b..055f96b8a2 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/PkgChangeNotificationConverter.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/PkgChangeNotificationConverter.java
@@ -21,6 +21,7 @@
package org.onap.so.adapters.vnfmadapter.converters.etsicatalog.sol003;
import static org.slf4j.LoggerFactory.getLogger;
+import org.onap.so.adapters.vnfmadapter.VnfmAdapterUrlProvider;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgChangeNotification;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.VnfPackageChangeNotification;
import org.slf4j.Logger;
@@ -38,6 +39,11 @@ public class PkgChangeNotificationConverter extends AbstractPkgNotificationConve
implements Converter<PkgChangeNotification, VnfPackageChangeNotification> {
private static final Logger logger = getLogger(PkgChangeNotificationConverter.class);
+
+ public PkgChangeNotificationConverter(final VnfmAdapterUrlProvider vnfmAdapterUrlProvider) {
+ super(vnfmAdapterUrlProvider);
+ }
+
/**
* Convert a {@link PkgChangeNotification} Object to an {@link VnfPackageChangeNotification} Object
*
@@ -71,9 +77,11 @@ public class PkgChangeNotificationConverter extends AbstractPkgNotificationConve
.fromValue(pkgChangeNotification.getOperationalState().getValue()));
}
- vnfPackageChangeNotification.setLinks(convert((pkgChangeNotification.getLinks())));
+ vnfPackageChangeNotification.setLinks(convert(pkgChangeNotification.getLinks(),
+ pkgChangeNotification.getVnfPkgId(), pkgChangeNotification.getSubscriptionId()));
return vnfPackageChangeNotification;
}
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/PkgOnboardingNotificationConverter.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/PkgOnboardingNotificationConverter.java
index 836acb6d36..50f95c6353 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/PkgOnboardingNotificationConverter.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/converters/etsicatalog/sol003/PkgOnboardingNotificationConverter.java
@@ -21,6 +21,7 @@
package org.onap.so.adapters.vnfmadapter.converters.etsicatalog.sol003;
import static org.slf4j.LoggerFactory.getLogger;
+import org.onap.so.adapters.vnfmadapter.VnfmAdapterUrlProvider;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgOnboardingNotification;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.notification.model.VnfPackageOnboardingNotification;
import org.slf4j.Logger;
@@ -38,6 +39,10 @@ public class PkgOnboardingNotificationConverter extends AbstractPkgNotificationC
implements Converter<PkgOnboardingNotification, VnfPackageOnboardingNotification> {
private static final Logger logger = getLogger(PkgOnboardingNotificationConverter.class);
+ public PkgOnboardingNotificationConverter(final VnfmAdapterUrlProvider vnfmAdapterUrlProvider) {
+ super(vnfmAdapterUrlProvider);
+ }
+
/**
* Convert a {@link PkgOnboardingNotification} Object to an {@link VnfPackageOnboardingNotification} Object
*
@@ -61,7 +66,8 @@ public class PkgOnboardingNotificationConverter extends AbstractPkgNotificationC
vnfPackageOnboardingNotification.setVnfPkgId(pkgOnboardingNotification.getVnfPkgId());
vnfPackageOnboardingNotification.setVnfdId(pkgOnboardingNotification.getVnfdId());
- vnfPackageOnboardingNotification.setLinks(convert((pkgOnboardingNotification.getLinks())));
+ vnfPackageOnboardingNotification.setLinks(convert(pkgOnboardingNotification.getLinks(),
+ pkgOnboardingNotification.getVnfPkgId(), pkgOnboardingNotification.getSubscriptionId()));
return vnfPackageOnboardingNotification;
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java
index 8f6d853997..2e99658400 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/AbstractServiceProviderConfiguration.java
@@ -20,13 +20,16 @@
package org.onap.so.adapters.vnfmadapter.extclients;
+import java.time.LocalDateTime;
import com.google.gson.Gson;
import java.util.Iterator;
-import org.onap.vnfmadapter.v1.JSON;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.JSON;
+import org.onap.so.adapters.vnfmadapter.rest.EtsiSubscriptionNotificationController;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;
+import org.threeten.bp.OffsetDateTime;
/**
* A base class that can be extended by classes for configuring HttpRestServiceProvider classes. Provides common methods
@@ -35,6 +38,7 @@ import org.springframework.web.client.RestTemplate;
* @author gareth.roper@est.tech
*/
public abstract class AbstractServiceProviderConfiguration {
+ private final JSON.OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new JSON.OffsetDateTimeTypeAdapter();
public void setGsonMessageConverter(final RestTemplate restTemplate) {
final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator();
@@ -43,7 +47,10 @@ public abstract class AbstractServiceProviderConfiguration {
iterator.remove();
}
}
- final Gson gson = new JSON().getGson();
+ final Gson gson = JSON.createGson().registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
+ .registerTypeAdapter(LocalDateTime.class,
+ new EtsiSubscriptionNotificationController.LocalDateTimeTypeAdapter())
+ .create();
restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson));
}
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/OAuthNotificationServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/OAuthNotificationServiceProvider.java
index c065203cd8..c30c74daf8 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/OAuthNotificationServiceProvider.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/OAuthNotificationServiceProvider.java
@@ -45,6 +45,7 @@ public class OAuthNotificationServiceProvider extends AbstractNotificationServic
public boolean send(final Object notification, final SubscriptionsAuthentication subscriptionsAuthentication,
final String callbackUri) {
logger.info("Sending notification to uri: {}", callbackUri);
+ logger.info("Object: {}", notification);
final String token = getAccessToken(subscriptionsAuthentication);
if (token == null) {
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java
index a97f04bcc8..92176215bf 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationController.java
@@ -20,11 +20,13 @@
package org.onap.so.adapters.vnfmadapter.rest;
-import static org.onap.so.adapters.vnfmadapter.Constants.ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL;
-import static org.slf4j.LoggerFactory.getLogger;
-import java.util.AbstractMap;
-import java.util.Map.Entry;
-import javax.ws.rs.core.MediaType;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import com.google.gson.TypeAdapter;
+import com.google.gson.stream.JsonReader;
+import com.google.gson.stream.JsonWriter;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgChangeNotification;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgOnboardingNotification;
import org.onap.so.adapters.vnfmadapter.packagemanagement.subscriptionmanagement.NotificationManager;
@@ -38,10 +40,14 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonParser;
+import javax.ws.rs.core.MediaType;
+import java.io.IOException;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.AbstractMap;
+import java.util.Map.Entry;
+import static org.onap.so.adapters.vnfmadapter.Constants.ETSI_SUBSCRIPTION_NOTIFICATION_CONTROLLER_BASE_URL;
+import static org.slf4j.LoggerFactory.getLogger;
/**
* This controller handles the ETSI Subscription Notification Endpoints.
@@ -61,7 +67,7 @@ public class EtsiSubscriptionNotificationController {
@Autowired
public EtsiSubscriptionNotificationController(final NotificationManager notificationManager) {
this.notificationManager = notificationManager;
- this.gson = new GsonBuilder().create();
+ this.gson = new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeTypeAdapter()).create();
}
@GetMapping(value = "/notification")
@@ -77,10 +83,11 @@ public class EtsiSubscriptionNotificationController {
* @return Response Code: 204 No Content if Successful, ProblemDetails Object if not.
*/
@PostMapping(value = "/notification", consumes = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON)
- public ResponseEntity<?> postSubscriptionNotification(@RequestBody final String notification) {
- logger.info("Posting subscription notification \n{}", notification);
+ public ResponseEntity<?> postSubscriptionNotification(@RequestBody final Object notification) {
+ logger.info("Posting subscription notification class: {} \n{}", notification.getClass(), notification);
+ final String notificationString = gson.toJson(notification);
- final Entry<String, Object> notificationObject = getNotificationObject(notification);
+ final Entry<String, Object> notificationObject = getNotificationObject(notificationString);
if (notificationManager.processSubscriptionNotification(notificationObject.getValue(),
notificationObject.getKey())) {
logger.info("Notification Delivered Successfully");
@@ -92,6 +99,7 @@ public class EtsiSubscriptionNotificationController {
}
private Entry<String, Object> getNotificationObject(final String notification) {
+ logger.info("getNotificationObject() notification: {}", notification);
final String notificationType = getNotificationType(notification);
if (PkgOnboardingNotification.NotificationTypeEnum.VNFPACKAGEONBOARDINGNOTIFICATION.getValue()
.equals(notificationType)) {
@@ -118,6 +126,7 @@ public class EtsiSubscriptionNotificationController {
private String getNotificationType(final String notification) {
try {
+ logger.info("getNotificationType() notification: {}", notification);
final JsonParser parser = new JsonParser();
final JsonObject element = (JsonObject) parser.parse(notification);
return element.get("notificationType").getAsString();
@@ -128,4 +137,30 @@ public class EtsiSubscriptionNotificationController {
"Unable to parse notification type in object \n" + notification);
}
+ public static class LocalDateTimeTypeAdapter extends TypeAdapter<LocalDateTime> {
+
+ private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
+ @Override
+ public void write(final JsonWriter out, final LocalDateTime localDateTime) throws IOException {
+ if (localDateTime == null) {
+ out.nullValue();
+ } else {
+ out.value(FORMATTER.format(localDateTime));
+ }
+ }
+
+ @Override
+ public LocalDateTime read(final JsonReader in) throws IOException {
+ switch (in.peek()) {
+ case NULL:
+ in.nextNull();
+ return null;
+ default:
+ final String dateTime = in.nextString();
+ return LocalDateTime.parse(dateTime, FORMATTER);
+ }
+ }
+ }
+
}
diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java
index 29afa8c549..069bfac032 100644
--- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java
+++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java
@@ -43,6 +43,7 @@ import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.mode
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgChangeNotification;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgOnboardingNotification;
import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.notification.model.PkgmLinks;
+import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.JSON;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthentication;
import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthenticationParamsBasic;
@@ -54,18 +55,18 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.boot.web.client.RestTemplateBuilder;
import org.springframework.boot.web.server.LocalServerPort;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.http.*;
+import org.springframework.http.converter.json.GsonHttpMessageConverter;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.client.MockRestServiceServer;
import org.springframework.web.client.RestTemplate;
-import org.threeten.bp.LocalDateTime;
-import org.threeten.bp.OffsetDateTime;
-import org.threeten.bp.ZoneOffset;
+import java.time.LocalDateTime;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
@@ -95,13 +96,18 @@ public class EtsiSubscriptionNotificationControllerTest {
private static final String EXPECTED_OAUTH_AUTHORIZATION = "Bearer " + TOKEN;
private static final String NOTIFICATION_ID = "NOTIFICATION_ID";
private static final String SUBSCRIPTION_ID = "SUBSCRIPTION_ID";
- private static final OffsetDateTime TIMESTAMP =
- OffsetDateTime.of(LocalDateTime.of(2020, 1, 1, 1, 1, 1, 1), ZoneOffset.ofHours(1));
+ private static final String TIME_STAMP_STRING_EXPECTED_FROM_ETSI_CATALOG = "2020-01-01 01:01:01";
+ private static final java.time.LocalDateTime TIMESTAMP = java.time.LocalDateTime.of(2020, 1, 1, 1, 1, 1, 1);
private static final String VNFPKG_ID = UUID.randomUUID().toString();
private static final String VNFD_ID = UUID.randomUUID().toString();
+ private static final String EXPECTED_VNF_PACKAGE_HREF =
+ "https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/vnfpkgm/v1/vnf_packages/" + VNFPKG_ID;
+ private static final String EXPECTED_SUBSCRIPTION_HREF =
+ "https://so-vnfm-adapter.onap:30406/so/vnfm-adapter/v1/vnfpkgm/v1/subscriptions/" + SUBSCRIPTION_ID;
private BasicHttpHeadersProvider basicHttpHeadersProvider;
- private final Gson gson = new GsonBuilder().create();;
+ private final Gson gson = new GsonBuilder().registerTypeAdapter(LocalDateTime.class,
+ new EtsiSubscriptionNotificationController.LocalDateTimeTypeAdapter()).create();
@Autowired
@Qualifier(CONFIGURABLE_REST_TEMPLATE)
@@ -121,6 +127,11 @@ public class EtsiSubscriptionNotificationControllerTest {
basicHttpHeadersProvider = new BasicHttpHeadersProvider();
cache = cacheServiceProvider.getCache(Constants.PACKAGE_MANAGEMENT_SUBSCRIPTION_CACHE);
cache.clear();
+
+ final Gson gson = JSON.createGson().registerTypeAdapter(LocalDateTime.class,
+ new EtsiSubscriptionNotificationController.LocalDateTimeTypeAdapter()).create();
+ testRestTemplate = new TestRestTemplate(
+ new RestTemplateBuilder().additionalMessageConverters(new GsonHttpMessageConverter(gson)));
}
@After
@@ -140,7 +151,6 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
@@ -148,13 +158,13 @@ public class EtsiSubscriptionNotificationControllerTest {
.value(VnfPackageOnboardingNotification.NotificationTypeEnum.VNFPACKAGEONBOARDINGNOTIFICATION
.toString()))
.andExpect(jsonPath("$.subscriptionId").value(SUBSCRIPTION_ID))
- .andExpect(jsonPath("$.timeStamp").value(TIMESTAMP.toString()))
- .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID.toString()))
- .andExpect(jsonPath("$.vnfdId").value(VNFD_ID.toString()))
- .andExpect(jsonPath("$._links").value(buildPkgmLinks()))
+ .andExpect(jsonPath("$.timeStamp").value(TIME_STAMP_STRING_EXPECTED_FROM_ETSI_CATALOG))
+ .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID)).andExpect(jsonPath("$.vnfdId").value(VNFD_ID))
+ .andExpect(jsonPath("$._links")
+ .value(buildPkgmLinks(EXPECTED_VNF_PACKAGE_HREF, EXPECTED_SUBSCRIPTION_HREF)))
.andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess());
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
}
@@ -162,8 +172,7 @@ public class EtsiSubscriptionNotificationControllerTest {
@Test
public void testOnboardingNotificationNotSentOnToVnfmCallbackUri_SubscriptionRequestNotInCache_Fail() {
final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
- final String notificationString = gson.toJson(notification);
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -181,12 +190,11 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.BAD_REQUEST));
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -204,12 +212,11 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.MOVED_PERMANENTLY));
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -226,12 +233,11 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.NOT_FOUND));
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -249,12 +255,11 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -273,24 +278,23 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgChangeNotification notification = buildPkgChangeNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
.andExpect(jsonPath("$.notificationType").value(
VnfPackageChangeNotification.NotificationTypeEnum.VNFPACKAGECHANGENOTIFICATION.getValue()))
.andExpect(jsonPath("$.subscriptionId").value(SUBSCRIPTION_ID))
- .andExpect(jsonPath("$.timeStamp").value(TIMESTAMP.toString()))
- .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID.toString()))
- .andExpect(jsonPath("$.vnfdId").value(VNFD_ID.toString()))
+ .andExpect(jsonPath("$.timeStamp").value(TIME_STAMP_STRING_EXPECTED_FROM_ETSI_CATALOG))
+ .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID)).andExpect(jsonPath("$.vnfdId").value(VNFD_ID))
.andExpect(
jsonPath("$.changeType").value(PkgChangeNotification.ChangeTypeEnum.OP_STATE_CHANGE.toString()))
.andExpect(jsonPath("$.operationalState")
.value(PkgChangeNotification.OperationalStateEnum.ENABLED.toString()))
- .andExpect(jsonPath("$._links").value(buildPkgmLinks()))
+ .andExpect(jsonPath("$._links")
+ .value(buildPkgmLinks(EXPECTED_VNF_PACKAGE_HREF, EXPECTED_SUBSCRIPTION_HREF)))
.andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess());
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
}
@@ -298,8 +302,7 @@ public class EtsiSubscriptionNotificationControllerTest {
@Test
public void testChangeNotificationNotSentOnToVnfmCallbackUri_SubscriptionRequestNotInCache_Fail() {
final PkgChangeNotification notification = buildPkgChangeNotification();
- final String notificationString = gson.toJson(notification);
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -317,12 +320,11 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgChangeNotification notification = buildPkgChangeNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.BAD_REQUEST));
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -340,12 +342,11 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgChangeNotification notification = buildPkgChangeNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.NOT_FOUND));
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -363,12 +364,11 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgChangeNotification notification = buildPkgChangeNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -387,7 +387,6 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgOnboardingNotification notification = buildPkgOnboardingNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andExpect(jsonPath("$.id").value(NOTIFICATION_ID))
@@ -395,13 +394,13 @@ public class EtsiSubscriptionNotificationControllerTest {
.value(VnfPackageOnboardingNotification.NotificationTypeEnum.VNFPACKAGEONBOARDINGNOTIFICATION
.toString()))
.andExpect(jsonPath("$.subscriptionId").value(SUBSCRIPTION_ID))
- .andExpect(jsonPath("$.timeStamp").value(TIMESTAMP.toString()))
- .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID.toString()))
- .andExpect(jsonPath("$.vnfdId").value(VNFD_ID.toString()))
- .andExpect(jsonPath("$._links").value(buildPkgmLinks()))
+ .andExpect(jsonPath("$.timeStamp").value(TIME_STAMP_STRING_EXPECTED_FROM_ETSI_CATALOG))
+ .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID)).andExpect(jsonPath("$.vnfdId").value(VNFD_ID))
+ .andExpect(jsonPath("$._links")
+ .value(buildPkgmLinks(EXPECTED_VNF_PACKAGE_HREF, EXPECTED_SUBSCRIPTION_HREF)))
.andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess());
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
}
@@ -412,13 +411,12 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.BASIC);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgChangeNotification notification = buildPkgChangeNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST))
.andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION))
.andRespond(withStatus(HttpStatus.UNAUTHORIZED));
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -436,7 +434,6 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.OAUTH2_CLIENT_CREDENTIALS);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgChangeNotification notification = buildPkgChangeNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(TOKEN_ENDPOINT)).andExpect(method(HttpMethod.POST))
.andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION))
@@ -448,16 +445,17 @@ public class EtsiSubscriptionNotificationControllerTest {
.andExpect(jsonPath("$.notificationType").value(
VnfPackageChangeNotification.NotificationTypeEnum.VNFPACKAGECHANGENOTIFICATION.toString()))
.andExpect(jsonPath("$.subscriptionId").value(SUBSCRIPTION_ID))
- .andExpect(jsonPath("$.timeStamp").value(TIMESTAMP.toString()))
- .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID.toString()))
- .andExpect(jsonPath("$.vnfdId").value(VNFD_ID.toString()))
+ .andExpect(jsonPath("$.timeStamp").value(TIME_STAMP_STRING_EXPECTED_FROM_ETSI_CATALOG))
+ .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID)).andExpect(jsonPath("$.vnfdId").value(VNFD_ID))
.andExpect(
jsonPath("$.changeType").value(PkgChangeNotification.ChangeTypeEnum.OP_STATE_CHANGE.toString()))
.andExpect(jsonPath("$.operationalState")
.value(PkgChangeNotification.OperationalStateEnum.ENABLED.toString()))
- .andExpect(jsonPath("$._links").value(buildPkgmLinks())).andRespond(withSuccess());
+ .andExpect(jsonPath("$._links")
+ .value(buildPkgmLinks(EXPECTED_VNF_PACKAGE_HREF, EXPECTED_SUBSCRIPTION_HREF)))
+ .andRespond(withSuccess());
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.NO_CONTENT, response.getStatusCode());
}
@@ -468,12 +466,11 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.OAUTH2_CLIENT_CREDENTIALS);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgChangeNotification notification = buildPkgChangeNotification();
- final String notificationString = gson.toJson(notification);
mockRestServer.expect(requestTo(TOKEN_ENDPOINT)).andExpect(method(HttpMethod.POST))
.andExpect(header("Authorization", EXPECTED_BASIC_AUTHORIZATION)).andRespond(withSuccess());
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -490,9 +487,8 @@ public class EtsiSubscriptionNotificationControllerTest {
buildPkgmSubscriptionRequest(SubscriptionsAuthentication.AuthTypeEnum.TLS_CERT);
cache.put(SUBSCRIPTION_ID, subscriptionRequest);
final PkgChangeNotification notification = buildPkgChangeNotification();
- final String notificationString = gson.toJson(notification);
- final ResponseEntity<?> response = sendHttpPost(notificationString);
+ final ResponseEntity<?> response = sendHttpPost(notification);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode());
assertTrue(response.getBody() instanceof ProblemDetails);
@@ -532,17 +528,12 @@ public class EtsiSubscriptionNotificationControllerTest {
}
private PkgmLinks buildPkgmLinks() {
- final PkgmLinks pkgmLinks = new PkgmLinks();
-
- final NOTIFICATIONLINKSERIALIZER subscriptionLinkSerializer = new NOTIFICATIONLINKSERIALIZER();
- subscriptionLinkSerializer.setHref("subscription_href");
- pkgmLinks.setSubscription(subscriptionLinkSerializer);
-
- final NOTIFICATIONLINKSERIALIZER vnfPackageLinkSerializer = new NOTIFICATIONLINKSERIALIZER();
- vnfPackageLinkSerializer.setHref("vnf_package_href");
- pkgmLinks.setVnfPackage(vnfPackageLinkSerializer);
+ return buildPkgmLinks("vnf_package_href", "subscription_href");
+ }
- return pkgmLinks;
+ private PkgmLinks buildPkgmLinks(final String vnfPkgHref, final String subscriptionHref) {
+ return new PkgmLinks().vnfPackage(new NOTIFICATIONLINKSERIALIZER().href(vnfPkgHref))
+ .subscription(new NOTIFICATIONLINKSERIALIZER().href(subscriptionHref));
}
private PkgmSubscriptionRequest buildPkgmSubscriptionRequest(