public OnapCommandLoadProfileFailed(String error) {
super("0x1301", "Failed to load profile details, " + error);
}
+
+ public OnapCommandLoadProfileFailed(Throwable error) {
+ this(error.getMessage());
+ }
+
}
package org.onap.cli.fw.error;
+import java.io.IOException;
+
/**
* Command profile persistence failed.
*
public OnapCommandPersistProfileFailed(String error) {
super("0x1302", "Failed to persist profile details, " + error);
}
+
+ public OnapCommandPersistProfileFailed(Throwable e1) {
+ this(e1.getMessage());
+ }
}
private String profileName = Constants.PARAM_CACHE_FILE_NAME;
- private boolean isLastPersistFailed = false;
-
private OnapCommandParameterCache() {
}
try {
OnapCommandUtils.persistParams(params, this.profileName);
} catch (OnapCommandPersistProfileFailed e) {
- isLastPersistFailed = true;
+ throw new RuntimeException(e);
}
}
private void load() {
- List<Param> params;
+ List<Param> params= new ArrayList<>();
try {
params = OnapCommandUtils.loadParamFromCache(this.profileName);
} catch (OnapCommandLoadProfileFailed e) {
- params = new ArrayList<>();
+ throw new RuntimeException(e);
}
for (Param p : params) {
import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.input.ParameterType;
import org.onap.cli.fw.input.cache.Param;
+import org.onap.cli.fw.log.OnapCommandLogger;
import org.onap.cli.fw.output.OnapCommandResult;
import org.onap.cli.fw.output.OnapCommandResultAttribute;
import org.onap.cli.fw.output.OnapCommandResultAttributeScope;
mapper.writerWithDefaultPrettyPrinter().writeValue(file, params);
}
} catch (IOException e1) {
- throw new OnapCommandPersistProfileFailed(e1.getMessage());
+ throw new OnapCommandPersistProfileFailed(e1);
}
}
}
params.addAll(Arrays.asList(list));
}
} catch (IOException e) {
- throw new OnapCommandLoadProfileFailed(e.getMessage());
+ throw new OnapCommandLoadProfileFailed(e);
}
return params;
throwable.printStackTrace(); // NOSONAR
}
} catch (OnapCommandException e) {
- this.print(e.getCause());
+ System.out.println(e);
}
}
this.handle(new String[] { "sample-test", "-h" });
}
+ @Test
+ public void testVersionSampleCommandShort() {
+ this.handle(new String[] { "sample-test", "-v" });
+ }
+
+ @Test
+ public void testHandleSampleCommandSet() throws OnapCommandException {
+ OnapCommandRegistrar.getRegistrar().addParamCache("sample:string-param", "paramValue");
+ OnapCommandRegistrar.getRegistrar().addParamCache("onap-username", "paramValue");
+ OnapCommandRegistrar.getRegistrar().addParamCache("onap-password", "paramValue");
+ OnapCommandRegistrar.getRegistrar().addParamCache("host-url", "paramValue");
+ this.handle(new String[] { "sample-test", "--string-param", "test"});
+ }
+
+ @Test
+ public void testHandleSampleCommandFailure() throws OnapCommandException {
+ this.handle(new String[] { "sample-test", "--string-param"});
+ }
+
@Test
public void interactiveTest() {
cli = new OnapCli(new String[] {});
short_option: x
long_option: secure
is_secured: true
- is_optional: false
+ is_optional: true
default_Value: pass123#
- name: string-param
type: string
description: Onap string param
long_option: string-param
short_option: c
- is_optional: false
+ is_optional: true
default_Value: test
- name: yaml-param
type: json
description: Onap yaml file location param
long_option: yaml-param
short_option: y
- is_optional: false
+ is_optional: true
- name: json-param
type: json
description: Onap json file location param
long_option: json-param
short_option: j
- is_optional: false
+ is_optional: true
- name: long-param
type: digit
description: Onap long param
short_option: l
long_option: long-opt
- is_optional: false
+ is_optional: true
default_value: 10
- name: url-param
type: url
description: Onap url param
short_option: r
long_option: url
- is_optional: false
+ is_optional: true
default_value: http://localhost:8082/file.txt
- name: env-param
type: string
description: Onap env param.
short_option: z
long_option: env
- is_optional: false
+ is_optional: true
default_value: ${ENV_VAR}
default_value: http://localhost:8082/file.txt
- name: positional-args
type: string
description: Onap positional args, if no short option and no long option given for it
- is_optional: false
+ is_optional: true
default_value: http://localhost:8082/file.txt
- name: text-param
type: text
description: Onap text file location param
long_option: text-param
short_option: e
- is_optional: false
+ is_optional: true
results:
direction: portrait
attributes: