Skip to content

Commit

Permalink
- add junit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Dec 7, 2023
1 parent cb04345 commit 65529ea
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
import com.axway.apim.lib.error.AppException;

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();
Expand All @@ -20,15 +20,15 @@ public Parameters getParams() throws AppException {
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");
option.setArgName("applicationsQuotaCache,*API*");
cliOptions.addOption(option);

option = new Option("stageConfig", true, "Manually provide the name of the stage configuration file to use instead of derived from the given stage.");
option.setArgName("my-staged-config.json");
cliOptions.addOption(option);
Expand All @@ -38,7 +38,7 @@ public void addOptions() {
public void addOption(Option option) {
cliOptions.addOption(option);
}


@Override
public void parse() throws AppException{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,89 +10,89 @@
import com.axway.apim.lib.error.AppException;

public class CLIAPIUpgradeAccessOptions extends CLIOptions {

private CLIAPIUpgradeAccessOptions(String[] args) {
super(args);
}

public static CLIOptions create(String[] args) throws AppException {
CLIOptions cliOptions = new CLIAPIUpgradeAccessOptions(args);
cliOptions = new CLIAPIFilterOptions(cliOptions);
cliOptions = new CoreCLIOptions(cliOptions);
cliOptions.addOptions();
cliOptions.parse();
return cliOptions;
}

@Override
public void addOptions() {
Option option = new Option("refAPIId", true, "Filter the reference API based on the ID.");
option.setRequired(false);
option.setArgName("UUID-ID-OF-THE-REF-API");
addOption(option);

option = new Option("refAPIName", true, "Filter the reference API based on the name. Wildcards are supported.");
option.setRequired(false);
option.setArgName("*My-Old-API*");
addOption(option);

option = new Option("refAPIVersion", true, "Filter the reference API based on the version.");
option.setRequired(false);
option.setArgName("1.0.0");
addOption(option);

option = new Option("refAPIOrg", true, "Filter the reference API based on the organization. Wildcards are supported.");
option.setRequired(false);
option.setArgName("*Org A*");
addOption(option);

option = new Option("refAPIDeprecate", true, "If set the old/reference API will be flagged as deprecated. Defaults to false.");
option.setRequired(false);
option.setArgName("true");
addOption(option);

option = new Option("refAPIRetire", true, "If set the old/reference API will be retired. Default to false.");
option.setRequired(false);
option.setArgName("true");
addOption(option);

option = new Option("refAPIRetireDate", true, "Sets the retirement date of the old API. Supported formats: \"dd.MM.yyyy\", \"dd/MM/yyyy\", \"yyyy-MM-dd\", \"dd-MM-yyyy\"");
option.setRequired(false);
option.setArgName("2021/06/30");
addOption(option);
}

@Override
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
Console.println("----------------------------------------------------------------------------------------");
Console.println("Upgrade access for one or more APIs based on the given reference API.");
Console.println("App-Subscriptions and Granted orgs are taken over to all selected APIs based on the reference API.");
Console.println("The reference API must be unique. APIs must be published to be considered.");
Console.println(getBinaryName()+" api upgrade-access -s api-env -refAPIId <UUID-ID-OF-THE-REF-API> -id <UUID-ID-OF-THE-API>");
Console.println(getBinaryName()+" api upgrade-access -s api-env -n \"*APIs-to-be-upgraded*\" -refAPIName \"*Name of Ref-API*\"");
Console.println(getBinaryName()+" api upgrade-access -s api-env -n \"*APIs-to-be-upgraded*\" -refAPIName \"*Name of Ref-API*\" -refAPIDeprecate true");
Console.println();
Console.println();
Console.println("For more information and advanced examples please visit:");
Console.println("https://github.com/Axway-API-Management-Plus/apim-cli/wiki");
}
private CLIAPIUpgradeAccessOptions(String[] args) {
super(args);
}

public static CLIOptions create(String[] args) throws AppException {
CLIOptions cliOptions = new CLIAPIUpgradeAccessOptions(args);
cliOptions = new CLIAPIFilterOptions(cliOptions);
cliOptions = new CoreCLIOptions(cliOptions);
cliOptions.addOptions();
cliOptions.parse();
return cliOptions;
}

@Override
public void addOptions() {
Option option = new Option("refAPIId", true, "Filter the reference API based on the ID.");
option.setRequired(false);
option.setArgName("UUID-ID-OF-THE-REF-API");
addOption(option);

option = new Option("refAPIName", true, "Filter the reference API based on the name. Wildcards are supported.");
option.setRequired(false);
option.setArgName("*My-Old-API*");
addOption(option);

option = new Option("refAPIVersion", true, "Filter the reference API based on the version.");
option.setRequired(false);
option.setArgName("1.0.0");
addOption(option);

option = new Option("refAPIOrg", true, "Filter the reference API based on the organization. Wildcards are supported.");
option.setRequired(false);
option.setArgName("*Org A*");
addOption(option);

option = new Option("refAPIDeprecate", true, "If set the old/reference API will be flagged as deprecated. Defaults to false.");
option.setRequired(false);
option.setArgName("true");
addOption(option);

option = new Option("refAPIRetire", true, "If set the old/reference API will be retired. Default to false.");
option.setRequired(false);
option.setArgName("true");
addOption(option);

option = new Option("refAPIRetireDate", true, "Sets the retirement date of the old API. Supported formats: \"dd.MM.yyyy\", \"dd/MM/yyyy\", \"yyyy-MM-dd\", \"dd-MM-yyyy\"");
option.setRequired(false);
option.setArgName("2021/06/30");
addOption(option);
}

@Override
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
Console.println("----------------------------------------------------------------------------------------");
Console.println("Upgrade access for one or more APIs based on the given reference API.");
Console.println("App-Subscriptions and Granted orgs are taken over to all selected APIs based on the reference API.");
Console.println("The reference API must be unique. APIs must be published to be considered.");
Console.println(getBinaryName() + " api upgrade-access -s api-env -refAPIId <UUID-ID-OF-THE-REF-API> -id <UUID-ID-OF-THE-API>");
Console.println(getBinaryName() + " api upgrade-access -s api-env -n \"*APIs-to-be-upgraded*\" -refAPIName \"*Name of Ref-API*\"");
Console.println(getBinaryName() + " api upgrade-access -s api-env -n \"*APIs-to-be-upgraded*\" -refAPIName \"*Name of Ref-API*\" -refAPIDeprecate true");
Console.println();
Console.println();
Console.println("For more information and advanced examples please visit:");
Console.println("https://github.com/Axway-API-Management-Plus/apim-cli/wiki");
}

@Override
protected String getAppName() {
return "Upgrade access";
}

@Override
public Parameters getParams() throws AppException {
APIUpgradeAccessParams params = new APIUpgradeAccessParams();
params.setReferenceAPIId(getValue("refAPIId"));
params.setReferenceAPIName(getValue("refAPIName"));
params.setReferenceAPIVersion(getValue("refAPIVersion"));
params.setReferenceAPIOrganization(getValue("refAPIOrg"));
params.setReferenceAPIDeprecate(Boolean.parseBoolean(getValue("refAPIDeprecate")));
params.setReferenceAPIRetire(Boolean.parseBoolean(getValue("refAPIRetire")));
params.setReferenceAPIRetirementDate(getValue("refAPIRetireDate"));
return params;
}
@Override
public Parameters getParams() throws AppException {
APIUpgradeAccessParams params = new APIUpgradeAccessParams();
params.setReferenceAPIId(getValue("refAPIId"));
params.setReferenceAPIName(getValue("refAPIName"));
params.setReferenceAPIVersion(getValue("refAPIVersion"));
params.setReferenceAPIOrganization(getValue("refAPIOrg"));
params.setReferenceAPIDeprecate(Boolean.parseBoolean(getValue("refAPIDeprecate")));
params.setReferenceAPIRetire(Boolean.parseBoolean(getValue("refAPIRetire")));
params.setReferenceAPIRetirementDate(getValue("refAPIRetireDate"));
return params;
}
}
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
package com.axway.apim.api.export.lib;

import static org.testng.Assert.assertEquals;

import com.axway.apim.api.API;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.axway.apim.api.API;
import static org.testng.Assert.assertEquals;

public class APIComparatorTest {
@Test
public void testCompareAPIWithoutVersion() {
APIComparator comp = new APIComparator();
API api1 = new API();
api1.setName("API 1");
api1.setVersion("1.0.0");

API api2 = new API();
api2.setName("API 1");

// Should not lead to a NPE!
int rc = comp.compare(api1, api2);
assertEquals(rc, 0);
}


@Test
public void compareEmptyAPIs() {
public void testCompareAPIWithoutVersion() {
APIComparator comp = new APIComparator();
int rc = comp.compare(null, null);
API api1 = new API();
api1.setName("API 1");
api1.setVersion("1.0.0");

API api2 = new API();
api2.setName("API 1");

// Should not lead to a NPE!
int rc = comp.compare(api1, api2);
assertEquals(rc, 0);
}



@Test
public void compareAPIsWithEmptyName() {
APIComparator comp = new APIComparator();
Expand Down Expand Up @@ -64,4 +58,33 @@ public void compareAPIsWithNameAndVersion() {
assertEquals(rc, 0);
}


@Test
public void compareApi1Empty() {
APIComparator comp = new APIComparator();
Assert.assertEquals(comp.compare(null, new API()), 0);
}

@Test
public void compareApi2Empty() {
APIComparator comp = new APIComparator();
Assert.assertEquals(comp.compare(new API(), null), 0);
}

@Test
public void compareApi1EmptyName() {
API api = new API();
api.setName("abc");
APIComparator comp = new APIComparator();
Assert.assertEquals(comp.compare(null, api), 0);
}

@Test
public void compareApi2EmptyName() {
API api = new API();
api.setName("abc");
APIComparator comp = new APIComparator();
Assert.assertEquals(comp.compare(api, null), 0);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
public class ClientAppComparatorTest {

@Test
public void sortEmptyClientApplications(){
public void sortEmptyClientApplications() {
List<ClientApplication> clientApplicationList = new ArrayList<>();
clientApplicationList.sort(new ClientAppComparator());
Assert.assertTrue(clientApplicationList.isEmpty());
}

@Test
public void sortClientApplicationsWithoutName(){
public void sortClientApplicationsWithoutName() {
List<ClientApplication> clientApplicationList = new ArrayList<>();
ClientApplication clientApplication = new ClientApplication();
clientApplicationList.add(clientApplication);
Expand All @@ -29,7 +29,7 @@ public void sortClientApplicationsWithoutName(){


@Test
public void sortClientApplicationsWithName(){
public void sortClientApplicationsWithName() {
List<ClientApplication> clientApplicationList = new ArrayList<>();
ClientApplication clientApplication = new ClientApplication();
clientApplication.setName("xyz");
Expand All @@ -44,4 +44,44 @@ public void sortClientApplicationsWithName(){

}

@Test
public void sortClientApplicationsWithNameOne() {
List<ClientApplication> clientApplicationList = new ArrayList<>();
ClientApplication clientApplication = new ClientApplication();
clientApplication.setName("xyz");
clientApplicationList.add(clientApplication);
clientApplicationList.sort(new ClientAppComparator());
Assert.assertEquals(clientApplicationList.get(0).getName(), "xyz");

}

@Test
public void compareApp1Empty() {
ClientAppComparator clientAppComparator = new ClientAppComparator();
Assert.assertEquals(clientAppComparator.compare(null, new ClientApplication()), 0);
}

@Test
public void compareApp2Empty() {
ClientAppComparator clientAppComparator = new ClientAppComparator();
Assert.assertEquals(clientAppComparator.compare(new ClientApplication(), null), 0);
}

@Test
public void compareApp1EmptyName() {
ClientApplication clientApplication = new ClientApplication();
clientApplication.setName("abc");
ClientAppComparator clientAppComparator = new ClientAppComparator();
Assert.assertEquals(clientAppComparator.compare(null, clientApplication), 0);
}

@Test
public void compareApp2EmptyName() {
ClientApplication clientApplication = new ClientApplication();
clientApplication.setName("abc");
ClientAppComparator clientAppComparator = new ClientAppComparator();
Assert.assertEquals(clientAppComparator.compare(clientApplication, null), 0);
}


}

0 comments on commit 65529ea

Please sign in to comment.