Skip to content

Commit

Permalink
- add junit test and refactor import cli common code
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Oct 31, 2024
1 parent 6151857 commit bc59343
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,10 @@

import org.apache.commons.cli.Option;

import com.axway.apim.lib.error.AppException;
public class StandardImportCLIOptions {

public class StandardImportCLIOptions extends CLIOptions {

private final CLIOptions cliOptions;

public StandardImportCLIOptions(CLIOptions cliOptions) {
this.cliOptions = cliOptions;
}

@Override
public Parameters getParams() throws AppException {
StandardImportParams params = (StandardImportParams)cliOptions.getParams();

params.setEnabledCaches(getValue("enabledCaches"));
params.setStageConfig(getValue("stageConfig"));
return params;
}

@Override
public void addOptions() {
cliOptions.addOptions();

Option option = new Option("enabledCaches", true, "By default, no cache is used for import actions. However, here you can enable caches if necessary to improve performance. Has no effect, when -gnoreCache is set. More information on the impact: https://bit.ly/3FjXRXE");
public void addOptions(CLIOptions cliOptions) {
Option option = new Option("enabledCaches", true, "By default, no cache is used for import actions. However, here you can enable caches if necessary to improve performance. Has no effect, when -ignoreCache is set. More information on the impact: https://bit.ly/3FjXRXE");
option.setArgName("applicationsQuotaCache,*API*");
cliOptions.addOption(option);

Expand All @@ -34,39 +14,4 @@ public void addOptions() {
cliOptions.addOption(option);
}

@Override
public void addOption(Option option) {
cliOptions.addOption(option);
}


@Override
public void parse() throws AppException{
cliOptions.parse();
}

@Override
public String getValue(String key) {
return cliOptions.getValue(key);
}

@Override
public void printUsage(String message, String[] args) {
cliOptions.printUsage(message, args);
}

@Override
public void showReturnCodes() {
cliOptions.showReturnCodes();
}

@Override
public boolean hasOption(String key) {
return cliOptions.hasOption(key);
}

@Override
public EnvironmentProperties getEnvProperties() {
return cliOptions.getEnvProperties();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.axway.lib;

import com.axway.apim.lib.CLIOptions;
import com.axway.apim.lib.StandardImportCLIOptions;
import com.axway.lib.utils.SampleCLIOptions;
import org.testng.Assert;
import org.testng.annotations.Test;

public class StandardImportCLIOptionsTest {

@Test
public void testStandardImportCLIOptions() throws Exception {
String[] args = {"-enabledCaches", "applicationsQuotaCache", "-stageConfig", "my-staged-config.json"};
CLIOptions options = SampleCLIOptions.create(args);
StandardImportCLIOptions standardImportCLIOptions = new StandardImportCLIOptions();
standardImportCLIOptions.addOptions(options);
options.parse();
Assert.assertTrue(options.hasOption("enabledCaches"));
Assert.assertTrue(options.hasOption("stageConfig"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ private CLIAPIImportOptions(String[] args) {

public static CLIOptions create(String[] args) throws AppException {
CLIOptions cliOptions = new CLIAPIImportOptions(args);
cliOptions = new StandardImportCLIOptions(cliOptions);
cliOptions = new CoreCLIOptions(cliOptions);
cliOptions.addOptions();
cliOptions.parse();
Expand Down Expand Up @@ -98,8 +97,7 @@ public void addOptions() {
addOption(option);

new OptionsCommon().addDeprecateAndRetired(this);


new StandardImportCLIOptions().addOptions(this);
}

@Override
Expand Down Expand Up @@ -128,8 +126,9 @@ protected String getAppName() {
@Override
public Parameters getParams() {
APIImportParams params = new APIImportParams();
params.setEnabledCaches(getValue("enabledCaches"));
params.setStageConfig(getValue("stageConfig"));
params.setConfig(getValue("config"));
params.setStageConfig(getValue("stagedConfig"));
params.setApiDefinition(getValue("apidefinition"));
params.setForceUpdate(hasOption("forceUpdate"));
params.setChangeOrganization(hasOption("changeOrganization"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ private AppImportCLIOptions(String[] args) {

public static CLIOptions create(String[] args) throws AppException {
CLIOptions cliOptions = new AppImportCLIOptions(args);
cliOptions = new StandardImportCLIOptions(cliOptions);
cliOptions = new CoreCLIOptions(cliOptions);
cliOptions.addOptions();
cliOptions.parse();
Expand All @@ -30,6 +29,7 @@ public void addOptions() {
option.setRequired(true);
option.setArgName("app_config.json");
addOption(option);
new StandardImportCLIOptions().addOptions(this);
}

@Override
Expand All @@ -55,6 +55,8 @@ protected String getAppName() {
@Override
public Parameters getParams() {
AppImportParams params = new AppImportParams();
params.setEnabledCaches(getValue("enabledCaches"));
params.setStageConfig(getValue("stageConfig"));
params.setConfig(getValue("c"));
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ public class OrgImportCLIOptions extends CLIOptions {
private OrgImportCLIOptions(String[] args) {
super(args);
}

public static CLIOptions create(String[] args) throws AppException {
CLIOptions cliOptions = new OrgImportCLIOptions(args);
cliOptions = new StandardImportCLIOptions(cliOptions);
cliOptions = new CoreCLIOptions(cliOptions);
cliOptions.addOptions();
cliOptions.parse();
Expand All @@ -30,11 +29,12 @@ public void addOptions() {
option.setRequired(true);
option.setArgName("org_config.json");
addOption(option);
}
new StandardImportCLIOptions().addOptions(this);
}

@Override
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
super.printUsage(message, args);
Console.println("----------------------------------------------------------------------------------------");
Console.println("How to imports organizations using the JSON-Config format");
Console.println("Import an organization using enviornment properties: env.api-env.properties:");
Expand All @@ -50,10 +50,12 @@ public void printUsage(String message, String[] args) {
protected String getAppName() {
return "Organization-Import";
}

@Override
public Parameters getParams() {
OrgImportParams params = new OrgImportParams();
params.setEnabledCaches(getValue("enabledCaches"));
params.setStageConfig(getValue("stageConfig"));
params.setConfig(getValue("config"));
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ public class APIManagerSetupImportCLIOptions extends CLIOptions {
private APIManagerSetupImportCLIOptions(String[] args) {
super(args);
}

public static CLIOptions create(String[] args) throws AppException {
CLIOptions cliOptions = new APIManagerSetupImportCLIOptions(args);
cliOptions = new StandardImportCLIOptions(cliOptions);
cliOptions = new CoreCLIOptions(cliOptions);
cliOptions.addOptions();
cliOptions.parse();
Expand All @@ -29,11 +28,12 @@ public void addOptions() {
option.setRequired(true);
option.setArgName("api-manager.json");
addOption(option);
}
new StandardImportCLIOptions().addOptions(this);
}

@Override
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
super.printUsage(message, args);
Console.println("----------------------------------------------------------------------------------------");
Console.println("How to import API-Manager configuration");
Console.println("Import the API-Manager configuration:");
Expand All @@ -48,10 +48,12 @@ public void printUsage(String message, String[] args) {
protected String getAppName() {
return "API-Manager Config-Import";
}

@Override
public StandardImportParams getParams() {
StandardImportParams params = new StandardImportParams();
params.setEnabledCaches(getValue("enabledCaches"));
params.setStageConfig(getValue("stageConfig"));
params.setConfig(getValue("config"));
return params;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ private UserImportCLIOptions(String[] args) {

public static CLIOptions create(String[] args) throws AppException {
CLIOptions cliOptions = new UserImportCLIOptions(args);
cliOptions = new StandardImportCLIOptions(cliOptions);
cliOptions = new CoreCLIOptions(cliOptions);
cliOptions.addOptions();
cliOptions.parse();
Expand All @@ -31,6 +30,8 @@ public void addOptions() {
option.setRequired(true);
option.setArgName("user_config.json");
addOption(option);
new StandardImportCLIOptions().addOptions(this);

}

@Override
Expand All @@ -56,6 +57,8 @@ protected String getAppName() {
@Override
public Parameters getParams() {
UserImportParams params = new UserImportParams();
params.setEnabledCaches(getValue("enabledCaches"));
params.setStageConfig(getValue("stageConfig"));
params.setConfig(getValue("config"));
return params;
}
Expand Down

0 comments on commit bc59343

Please sign in to comment.