aboutsummaryrefslogtreecommitdiffstats
path: root/client/client-deployment/src/main/java/org
diff options
context:
space:
mode:
authorning.xi <ning.xi@est.tech>2019-08-13 05:20:20 +0000
committerning.xi <ning.xi@est.tech>2019-08-13 05:20:20 +0000
commitc678c3a22f7761928f4be8e4f82f2f3c7ea417db (patch)
tree15679e12025af9a056208ff9879250b7ce458d25 /client/client-deployment/src/main/java/org
parent6203d19345c38dbfb6136ea6754bb11ca09fa90b (diff)
add JUnit test in client deployment and client full
Issue-ID: POLICY-1962 Change-Id: Ic10b0edc9364624161f71935f51f4411fe67c882 Signed-off-by: ning.xi <ning.xi@est.tech>
Diffstat (limited to 'client/client-deployment/src/main/java/org')
-rw-r--r--client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java26
-rw-r--r--client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ParameterCheck.java39
2 files changed, 53 insertions, 12 deletions
diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java
index d3a7d654a..55cabe900 100644
--- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java
+++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ApexDeploymentRestResource.java
@@ -21,9 +21,7 @@
package org.onap.policy.apex.client.deployment.rest;
import com.google.gson.JsonObject;
-
import java.io.InputStream;
-
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
@@ -32,8 +30,6 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-
-import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;
import org.onap.policy.apex.core.deployment.ApexDeploymentException;
import org.onap.policy.apex.core.deployment.EngineServiceFacade;
@@ -69,7 +65,7 @@ public class ApexDeploymentRestResource {
@GET
public Response createSession(@QueryParam("hostName") final String hostName, @QueryParam("port") final int port) {
final String host = hostName + ":" + port;
- final EngineServiceFacade engineServiceFacade = new EngineServiceFacade(hostName, port);
+ final EngineServiceFacade engineServiceFacade = getEngineServiceFacade(hostName, port);
try {
engineServiceFacade.init();
@@ -109,10 +105,10 @@ public class ApexDeploymentRestResource {
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response modelUpload(@FormDataParam("hostName") final String hostName, @FormDataParam("port") final int port,
@FormDataParam("file") final InputStream uploadedInputStream,
- @FormDataParam("file") final FormDataContentDisposition fileDetail,
+ @FormDataParam("fileName") final String fileName,
@FormDataParam("ignoreConflicts") final boolean ignoreConflicts,
@FormDataParam("forceUpdate") final boolean forceUpdate) {
- final EngineServiceFacade engineServiceFacade = new EngineServiceFacade(hostName, port);
+ final EngineServiceFacade engineServiceFacade = getEngineServiceFacade(hostName, port);
try {
engineServiceFacade.init();
@@ -124,8 +120,7 @@ public class ApexDeploymentRestResource {
}
try {
- engineServiceFacade.deployModel(fileDetail.getFileName(), uploadedInputStream, ignoreConflicts,
- forceUpdate);
+ engineServiceFacade.deployModel(fileName, uploadedInputStream, ignoreConflicts, forceUpdate);
} catch (final Exception e) {
LOGGER.warn("Error updating model on engine service " + engineServiceFacade.getKey().getId(), e);
final String errorMessage =
@@ -135,8 +130,19 @@ public class ApexDeploymentRestResource {
.build();
}
- return Response.ok("Model " + fileDetail.getFileName() + " deployed on engine service "
+ return Response.ok("Model " + fileName + " deployed on engine service "
+ engineServiceFacade.getKey().getId()).build();
}
+ /**
+ * Get an engine service facade for sending REST requests. This method is package because it is used by unit test.
+ *
+ * @param hostName the host name of the Apex engine
+ * @param port the port of the Apex engine
+ * @return the engine service facade
+ */
+ protected EngineServiceFacade getEngineServiceFacade(final String hostName, final int port) {
+ return new EngineServiceFacade(hostName, port);
+ }
+
}
diff --git a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ParameterCheck.java b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ParameterCheck.java
index 4e75763db..cad0911f1 100644
--- a/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ParameterCheck.java
+++ b/client/client-deployment/src/main/java/org/onap/policy/apex/client/deployment/rest/ParameterCheck.java
@@ -1,6 +1,7 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +22,6 @@
package org.onap.policy.apex.client.deployment.rest;
import java.util.Map;
-
import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
@@ -71,12 +71,19 @@ public final class ParameterCheck {
* @return the host name
*/
public static String getHostName(final Map<String, String[]> parameterMap) {
+ if (parameterMap == null) {
+ return null;
+ }
+
if (!parameterMap.containsKey(HOSTNAME_PAR)) {
LOGGER.warn(PARAMETER + HOSTNAME_PAR + NOT_FOUND);
return null;
}
final String[] hostNameValue = parameterMap.get(HOSTNAME_PAR);
+ if (hostNameValue == null) {
+ return null;
+ }
if (hostNameValue.length == 0 || hostNameValue[0].trim().length() == 0) {
LOGGER.warn("value of parameter \"" + HOSTNAME_PAR + NOT_FOUND);
@@ -93,6 +100,10 @@ public final class ParameterCheck {
* @return the port
*/
public static int getPort(final Map<String, String[]> parameterMap) {
+ if (parameterMap == null) {
+ return -1;
+ }
+
if (!parameterMap.containsKey(PORT_PAR)) {
LOGGER.warn(PARAMETER + PORT_PAR + NOT_FOUND);
return -1;
@@ -130,6 +141,10 @@ public final class ParameterCheck {
* @return the engine key
*/
public static AxArtifactKey getEngineKey(final Map<String, String[]> parameterMap) {
+ if (parameterMap == null) {
+ return null;
+ }
+
String artifactKeyParameter = null;
for (final String parameter : parameterMap.keySet()) {
// Check for an AxArtifactKey parameter
@@ -152,7 +167,12 @@ public final class ParameterCheck {
return null;
}
- return new AxArtifactKey(axArtifactKeyArray[1]);
+ try {
+ return new AxArtifactKey(axArtifactKeyArray[1]);
+ } catch (Exception apEx) {
+ LOGGER.trace("invalid artifact key ID {}", axArtifactKeyArray[1], apEx);
+ return null;
+ }
}
/**
@@ -164,6 +184,10 @@ public final class ParameterCheck {
*/
public static ParameterCheck.StartStop getStartStop(final Map<String, String[]> parameterMap,
final AxArtifactKey engineKey) {
+ if (parameterMap == null || engineKey == null) {
+ return null;
+ }
+
final String startStopPar = AXARTIFACTKEY_PAR + '#' + engineKey.getId();
if (!parameterMap.containsKey(startStopPar)) {
LOGGER.warn("parameter \"{}\" not found", startStopPar);
@@ -171,6 +195,9 @@ public final class ParameterCheck {
}
final String[] startStopValue = parameterMap.get(startStopPar);
+ if (startStopValue == null) {
+ return null;
+ }
if (startStopValue.length == 0 || startStopValue[0].trim().length() == 0) {
LOGGER.warn("value of parameter \"{}\" not found", startStopPar);
@@ -198,6 +225,10 @@ public final class ParameterCheck {
* @return The long value
*/
public static long getLong(final Map<String, String[]> parameterMap, final String longName) {
+ if (parameterMap == null || longName == null) {
+ return -1;
+ }
+
if (!parameterMap.containsKey(longName)) {
LOGGER.warn("parameter \"{}\" not found", longName);
return -1;
@@ -205,6 +236,10 @@ public final class ParameterCheck {
final String[] longValue = parameterMap.get(longName);
+ if (longValue == null) {
+ return -1;
+ }
+
if (longValue.length == 0 || longValue[0].trim().length() == 0) {
LOGGER.warn("value of parameter \"{}\" not found", longName);
return -1;