aboutsummaryrefslogtreecommitdiffstats
path: root/certServiceClient/src/main/java
diff options
context:
space:
mode:
authorkjaniak <kornel.janiak@nokia.com>2020-02-27 09:56:08 +0100
committerkjaniak <kornel.janiak@nokia.com>2020-02-27 11:27:46 +0100
commit5b1830d2eec4eddbeaeea9b4076404fbdb78e5e2 (patch)
treeedee4ec658596157dbd149df23e76b9dd72c0f02 /certServiceClient/src/main/java
parent628ed81f0e56f7163b08b57a8d54833b646239d5 (diff)
Replacement of RuntimeException with Exception class
Clean up in tests and run method. Issue-ID: AAF-996 Signed-off-by: kjaniak <kornel.janiak@nokia.com> Change-Id: I2abbfa9af4a77960cb65e9b9ecfcb058eb69cf12
Diffstat (limited to 'certServiceClient/src/main/java')
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java20
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitCode.java1
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java2
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/KeyPairFactory.java2
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java6
-rw-r--r--certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java4
6 files changed, 13 insertions, 22 deletions
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java
index ac1062a0..f8867846 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/CertServiceClient.java
@@ -29,8 +29,8 @@ import org.onap.aaf.certservice.client.configuration.model.ClientConfiguration;
import org.onap.aaf.certservice.client.configuration.model.CsrConfiguration;
import java.security.KeyPair;
-import java.util.Optional;
+import static org.onap.aaf.certservice.client.api.ExitCode.SUCCESS_EXIT_CODE;
import static org.onap.aaf.certservice.client.certification.EncryptionAlgorithmConstants.KEY_SIZE;
import static org.onap.aaf.certservice.client.certification.EncryptionAlgorithmConstants.RSA_ENCRYPTION_ALGORITHM;
@@ -42,23 +42,15 @@ public class CertServiceClient {
}
public void run() {
- ClientConfiguration clientConfiguration;
- CsrConfiguration csrConfiguration;
- clientConfiguration = new ClientConfigurationFactory(new EnvsForClient()).create();
- csrConfiguration = new CsrConfigurationFactory(new EnvsForCsr()).create();
-
KeyPairFactory keyPairFactory = new KeyPairFactory(RSA_ENCRYPTION_ALGORITHM, KEY_SIZE);
- Optional<KeyPair> keyPair = generateKeyPair(keyPairFactory);
-
- appExitHandler.exit(0);
- }
-
- public Optional<KeyPair> generateKeyPair(KeyPairFactory keyPairFactory) {
try {
- return Optional.of(keyPairFactory.create());
+ ClientConfiguration clientConfiguration = new ClientConfigurationFactory(new EnvsForClient()).create();
+ CsrConfiguration csrConfiguration = new CsrConfigurationFactory(new EnvsForCsr()).create();
+ KeyPair keyPair = keyPairFactory.create();
} catch (ExitableException e) {
appExitHandler.exit(e.applicationExitCode());
}
- return Optional.empty();
+ appExitHandler.exit(SUCCESS_EXIT_CODE.getValue());
}
+
}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitCode.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitCode.java
index aed9f3fe..295738f4 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitCode.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitCode.java
@@ -19,6 +19,7 @@
package org.onap.aaf.certservice.client.api;
public enum ExitCode {
+ SUCCESS_EXIT_CODE(0),
CLIENT_CONFIGURATION_EXCEPTION(1),
CSR_CONFIGURATION_EXCEPTION(2),
KEY_PAIR_GENERATION_EXCEPTION(3);
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java
index e884d11a..51981a48 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/api/ExitableException.java
@@ -18,7 +18,7 @@
*/
package org.onap.aaf.certservice.client.api;
-public abstract class ExitableException extends RuntimeException {
+public abstract class ExitableException extends Exception {
public ExitableException(Throwable e) {
super(e);
}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/KeyPairFactory.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/KeyPairFactory.java
index 6ad6528a..64136863 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/KeyPairFactory.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/certification/KeyPairFactory.java
@@ -37,7 +37,7 @@ public class KeyPairFactory {
this.keySize = keySize;
}
- public KeyPair create() {
+ public KeyPair create() throws KeyPairGenerationException {
try {
return createKeyPairGenerator().generateKeyPair();
} catch (NoSuchAlgorithmException e) {
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java
index 9592ac3e..beccd383 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/EnvProvider.java
@@ -17,14 +17,10 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-
package org.onap.aaf.certservice.client.configuration;
-
-import org.onap.aaf.certservice.client.configuration.exception.ClientConfigurationException;
-
public class EnvProvider {
- public String readEnvVariable(String envVariable) throws ClientConfigurationException {
+ public String readEnvVariable(String envVariable) {
return System.getProperty(envVariable);
}
}
diff --git a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java
index 28a5cf41..2464cc58 100644
--- a/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java
+++ b/certServiceClient/src/main/java/org/onap/aaf/certservice/client/configuration/factory/AbstractConfigurationFactory.java
@@ -20,8 +20,10 @@
package org.onap.aaf.certservice.client.configuration.factory;
+import org.onap.aaf.certservice.client.configuration.exception.ClientConfigurationException;
+import org.onap.aaf.certservice.client.configuration.exception.CsrConfigurationException;
import org.onap.aaf.certservice.client.configuration.model.ConfigurationModel;
public interface AbstractConfigurationFactory<T extends ConfigurationModel> {
- T create();
+ T create() throws ClientConfigurationException, CsrConfigurationException;
}