aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-04-11 20:25:29 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-04-17 12:09:41 +0200
commitdf2ad94ee9b641a4c2c19969816a6275f6d056e3 (patch)
treea6e54a66e9973ace00c0c88377dd3ef3a24aa747 /src/main/java
parente820afb80b830453f667280d94f6e86279ad4f2c (diff)
Add model-loader integration tests1.13.6
- add integration tests that assert the external communication towards other services using Wiremock - remove tests that are asserting getters and setters of objects Issue-ID: AAI-3826 Change-Id: I1f627801869f40cb0eaa61b10148b41bd3b1bdb8 Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/onap/aai/modelloader/config/BeanConfig.java18
-rw-r--r--src/main/java/org/onap/aai/modelloader/config/DistributionClientStartupConfig.java7
-rw-r--r--src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java34
-rw-r--r--src/main/java/org/onap/aai/modelloader/notification/NotificationDataImpl.java94
-rw-r--r--src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java2
-rw-r--r--src/main/java/org/onap/aai/modelloader/restclient/HttpsBabelServiceClient.java4
-rw-r--r--src/main/java/org/onap/aai/modelloader/service/ArtifactInfoImpl.java109
7 files changed, 78 insertions, 190 deletions
diff --git a/src/main/java/org/onap/aai/modelloader/config/BeanConfig.java b/src/main/java/org/onap/aai/modelloader/config/BeanConfig.java
index 8f7b2bb..63956e2 100644
--- a/src/main/java/org/onap/aai/modelloader/config/BeanConfig.java
+++ b/src/main/java/org/onap/aai/modelloader/config/BeanConfig.java
@@ -30,9 +30,11 @@ import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.modelloader.service.ModelLoaderMsgs;
import org.onap.sdc.api.IDistributionClient;
import org.onap.sdc.impl.DistributionClientFactory;
+import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
+import org.springframework.web.client.RestTemplate;
@Configuration
public class BeanConfig {
@@ -44,13 +46,18 @@ public class BeanConfig {
private String configDir;
@Bean
- public ModelLoaderConfig modelLoaderConfig() throws IOException {
+ public Properties configProperties() throws IOException {
// Load model loader system configuration
logger.info(ModelLoaderMsgs.LOADING_CONFIGURATION);
- ModelLoaderConfig.setConfigHome(configDir);
- Properties configProperties = new Properties();
InputStream configInputStream = Files.newInputStream(Paths.get(configDir, "model-loader.properties"));
+ Properties configProperties = new Properties();
configProperties.load(configInputStream);
+ return configProperties;
+ }
+
+ @Bean
+ public ModelLoaderConfig modelLoaderConfig(Properties configProperties) {
+ ModelLoaderConfig.setConfigHome(configDir);
return new ModelLoaderConfig(configProperties);
}
@@ -58,4 +65,9 @@ public class BeanConfig {
public IDistributionClient iDistributionClient() {
return DistributionClientFactory.createDistributionClient();
}
+
+ @Bean
+ public RestTemplate restTemplate() {
+ return new RestTemplate();
+ }
}
diff --git a/src/main/java/org/onap/aai/modelloader/config/DistributionClientStartupConfig.java b/src/main/java/org/onap/aai/modelloader/config/DistributionClientStartupConfig.java
index 84c79f2..cd9d919 100644
--- a/src/main/java/org/onap/aai/modelloader/config/DistributionClientStartupConfig.java
+++ b/src/main/java/org/onap/aai/modelloader/config/DistributionClientStartupConfig.java
@@ -33,10 +33,10 @@ import org.onap.sdc.api.results.IDistributionClientResult;
import org.onap.sdc.utils.DistributionActionResultEnum;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationReadyEvent;
+import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
-import org.springframework.stereotype.Component;
-@Component
+@Configuration
@ConditionalOnProperty(value = "ml.distribution.connection.enabled", havingValue = "true", matchIfMissing = true)
public class DistributionClientStartupConfig {
@@ -57,7 +57,8 @@ public class DistributionClientStartupConfig {
protected void initSdcClient() {
// Initialize distribution client
logger.debug(ModelLoaderMsgs.INITIALIZING, "Initializing distribution client...");
- IDistributionClientResult initResult = client.init(config, eventCallback);
+ IDistributionClientResult initResult = null;
+ initResult = client.init(config, eventCallback);
if (initResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) {
// Start distribution client
diff --git a/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java b/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java
index 7da90d9..6723e75 100644
--- a/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java
+++ b/src/main/java/org/onap/aai/modelloader/config/ModelLoaderConfig.java
@@ -77,6 +77,9 @@ public class ModelLoaderConfig implements IConfiguration {
protected static final String PROP_ML_DISTRIBUTION_HTTP_PROXY_PORT = PREFIX_DISTRIBUTION_CLIENT + "HTTP_PROXY_PORT";
protected static final String PROP_ML_DISTRIBUTION_HTTPS_PROXY_HOST = PREFIX_DISTRIBUTION_CLIENT + "HTTPS_PROXY_HOST";
protected static final String PROP_ML_DISTRIBUTION_HTTPS_PROXY_PORT = PREFIX_DISTRIBUTION_CLIENT + "HTTPS_PROXY_PORT";
+ protected static final String PROP_ML_DISTRIBUTION_SASL_JAAS_CONFIG = PREFIX_DISTRIBUTION_CLIENT + "SASL_JAAS_CONFIG";
+ protected static final String PROP_ML_DISTRIBUTION_SASL_MECHANISM = PREFIX_DISTRIBUTION_CLIENT + "SASL_MECHANISM";
+ protected static final String PROP_ML_DISTRIBUTION_SECURITY_PROTOCOL = PREFIX_DISTRIBUTION_CLIENT + "SECURITY_PROTOCOL";
protected static final String PROP_AAI_BASE_URL = PREFIX_AAI + "BASE_URL";
protected static final String PROP_AAI_KEYSTORE_FILE = PREFIX_AAI + SUFFIX_KEYSTORE_FILE;
protected static final String PROP_AAI_KEYSTORE_PASSWORD = PREFIX_AAI + SUFFIX_KEYSTORE_PASS;
@@ -413,4 +416,35 @@ public class ModelLoaderConfig implements IConfiguration {
return Integer.parseInt(connectTimeout);
}
+ @Override
+ public String getKafkaSaslJaasConfig() {
+ String saslJaasConfFromEnv = System.getenv("SASL_JAAS_CONFIG");
+ if(saslJaasConfFromEnv != null) {
+ return saslJaasConfFromEnv;
+ }
+ if(get(PROP_ML_DISTRIBUTION_SASL_JAAS_CONFIG) != null) {
+ return get(PROP_ML_DISTRIBUTION_SASL_JAAS_CONFIG);
+ }
+ return null;
+ }
+
+ @Override
+ public String getKafkaSaslMechanism() {
+ if(get(PROP_ML_DISTRIBUTION_SASL_MECHANISM) != null) {
+ return get(PROP_ML_DISTRIBUTION_SASL_MECHANISM);
+ }
+ return System.getenv().getOrDefault("SASL_MECHANISM", "SCRAM-SHA-512");
+ }
+
+ /**
+ * One of PLAINTEXT, SSL, SASL_PLAINTEXT, SASL_SSL
+ */
+ @Override
+ public String getKafkaSecurityProtocolConfig() {
+ if(get(PROP_ML_DISTRIBUTION_SECURITY_PROTOCOL) != null) {
+ return get(PROP_ML_DISTRIBUTION_SECURITY_PROTOCOL);
+ }
+ return System.getenv().getOrDefault("SECURITY_PROTOCOL", "SASL_PLAINTEXT");
+ }
+
}
diff --git a/src/main/java/org/onap/aai/modelloader/notification/NotificationDataImpl.java b/src/main/java/org/onap/aai/modelloader/notification/NotificationDataImpl.java
index 566415e..3eb07f3 100644
--- a/src/main/java/org/onap/aai/modelloader/notification/NotificationDataImpl.java
+++ b/src/main/java/org/onap/aai/modelloader/notification/NotificationDataImpl.java
@@ -20,98 +20,28 @@
*/
package org.onap.aai.modelloader.notification;
-import java.util.Collections;
import java.util.List;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.INotificationData;
import org.onap.sdc.api.notification.IResourceInstance;
+import lombok.Data;
+
+@Data
public class NotificationDataImpl implements INotificationData {
private String distributionID;
+ private String serviceName;
+ private String serviceVersion;
+ private String serviceUUID;
+ private String serviceDescription;
+ private List<IResourceInstance> resources;
+ private List<IArtifactInfo> serviceArtifacts;
+ private String serviceInvariantUUID;
+ private String workloadContext;
@Override
- public IArtifactInfo getArtifactMetadataByUUID(String arg0) {
- return null;
- }
-
- @Override
- public String getDistributionID() {
- return distributionID;
- }
-
- public void setDistributionID(String distributionID) {
- this.distributionID = distributionID;
- }
-
- @Override
- public List<IResourceInstance> getResources() {
- return Collections.emptyList();
- }
-
- @Override
- public List<IArtifactInfo> getServiceArtifacts() {
- return Collections.emptyList();
- }
-
- @Override
- public String getServiceDescription() {
- return null;
- }
-
- @Override
- public String getServiceInvariantUUID() {
- return null;
- }
-
- @Override
- public String getServiceName() {
- return null;
- }
-
- @Override
- public String getServiceUUID() {
- return null;
- }
-
- @Override
- public String getServiceVersion() {
+ public IArtifactInfo getArtifactMetadataByUUID(String uuid) {
return null;
}
-
- @Override
- public String getWorkloadContext() {
- return null;
- }
-
- @Override
- public void setWorkloadContext(String arg0) {
- // Unsupported method - not expected to be called
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((distributionID == null) ? 0 : distributionID.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- NotificationDataImpl other = (NotificationDataImpl) obj;
- if (distributionID == null) {
- if (other.distributionID != null)
- return false;
- } else if (!distributionID.equals(other.distributionID))
- return false;
- return true;
- }
-
}
diff --git a/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java b/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java
index 40aeacc..45f84d6 100644
--- a/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java
+++ b/src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java
@@ -42,6 +42,7 @@ import org.onap.aai.modelloader.service.ModelLoaderMsgs;
import org.onap.aai.restclient.client.OperationResult;
import org.onap.aai.restclient.client.RestClient;
import org.onap.aai.restclient.enums.RestAuthenticationMode;
+import org.springframework.stereotype.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@@ -52,6 +53,7 @@ import org.xml.sax.SAXException;
* Wrapper around the standard A&AI Rest Client interface. This currently uses Jersey client 1.x
*
*/
+@Component
public class AaiRestClient {
public static final String HEADER_TRANS_ID = "X-TransactionId";
diff --git a/src/main/java/org/onap/aai/modelloader/restclient/HttpsBabelServiceClient.java b/src/main/java/org/onap/aai/modelloader/restclient/HttpsBabelServiceClient.java
index c76996f..0789996 100644
--- a/src/main/java/org/onap/aai/modelloader/restclient/HttpsBabelServiceClient.java
+++ b/src/main/java/org/onap/aai/modelloader/restclient/HttpsBabelServiceClient.java
@@ -229,8 +229,8 @@ public class HttpsBabelServiceClient implements BabelServiceClient {
String resourceUrl = config.getBabelBaseUrl() + config.getBabelGenerateArtifactsUrl();
WebResource webResource = client.resource(resourceUrl);
ClientResponse response = webResource.type("application/json")
- .header(AaiRestClient.HEADER_TRANS_ID, Collections.singletonList(transactionId))
- .header(AaiRestClient.HEADER_FROM_APP_ID, Collections.singletonList(AaiRestClient.ML_APP_NAME))
+ .header(AaiRestClient.HEADER_TRANS_ID, transactionId)
+ .header(AaiRestClient.HEADER_FROM_APP_ID, AaiRestClient.ML_APP_NAME)
.post(ClientResponse.class, obj.toString());
String sanitizedJson = JsonSanitizer.sanitize(response.getEntity(String.class));
diff --git a/src/main/java/org/onap/aai/modelloader/service/ArtifactInfoImpl.java b/src/main/java/org/onap/aai/modelloader/service/ArtifactInfoImpl.java
index 9af92be..f83e44d 100644
--- a/src/main/java/org/onap/aai/modelloader/service/ArtifactInfoImpl.java
+++ b/src/main/java/org/onap/aai/modelloader/service/ArtifactInfoImpl.java
@@ -20,116 +20,25 @@
*/
package org.onap.aai.modelloader.service;
-import java.util.Collections;
import java.util.List;
import org.onap.sdc.api.notification.IArtifactInfo;
+import lombok.Data;
+
/**
* This class is an implementation of IArtifactInfo for test purposes.
*/
+@Data
public class ArtifactInfoImpl implements IArtifactInfo {
private String artifactName;
private String artifactType;
private String artifactDescription;
private String artifactVersion;
-
- @Override
- public String getArtifactName() {
- return artifactName;
- }
-
- public void setArtifactName(String artifactName) {
- this.artifactName = artifactName;
- }
-
- @Override
- public String getArtifactType() {
- return artifactType;
- }
-
- public void setArtifactType(String artifactType) {
- this.artifactType = artifactType;
- }
-
- @Override
- public String getArtifactURL() {
- return null;
- }
-
- @Override
- public String getArtifactChecksum() {
- return null;
- }
-
- @Override
- public String getArtifactDescription() {
- return artifactDescription;
- }
-
- public void setArtifactDescription(String artifactDescription) {
- this.artifactDescription = artifactDescription;
- }
-
- @Override
- public Integer getArtifactTimeout() {
- return null;
- }
-
- @Override
- public String getArtifactVersion() {
- return artifactVersion;
- }
-
- public void setArtifactVersion(String artifactVersion) {
- this.artifactVersion = artifactVersion;
- }
-
- @Override
- public String getArtifactUUID() {
- return null;
- }
-
- @Override
- public IArtifactInfo getGeneratedArtifact() {
- return null;
- }
-
- @Override
- public List<IArtifactInfo> getRelatedArtifacts() {
- return Collections.emptyList();
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) {
- return true;
- }
- if (o == null || getClass() != o.getClass()) {
- return false;
- }
-
- ArtifactInfoImpl that = (ArtifactInfoImpl) o;
-
- if (artifactName != null ? !artifactName.equals(that.artifactName) : that.artifactName != null) {
- return false;
- }
- if (artifactType != null ? !artifactType.equals(that.artifactType) : that.artifactType != null) {
- return false;
- }
- if (artifactDescription != null ? !artifactDescription.equals(that.artifactDescription)
- : that.artifactDescription != null) {
- return false;
- }
- return artifactVersion != null ? artifactVersion.equals(that.artifactVersion) : that.artifactVersion == null;
- }
-
- @Override
- public int hashCode() {
- int result = artifactName != null ? artifactName.hashCode() : 0;
- result = 31 * result + (artifactType != null ? artifactType.hashCode() : 0);
- result = 31 * result + (artifactDescription != null ? artifactDescription.hashCode() : 0);
- result = 31 * result + (artifactVersion != null ? artifactVersion.hashCode() : 0);
- return result;
- }
+ private String artifactURL;
+ private String artifactChecksum;
+ private Integer artifactTimeout;
+ private String artifactUUID;
+ private IArtifactInfo generatedArtifact;
+ private List<IArtifactInfo> relatedArtifacts;
}