Skip to content

Commit

Permalink
- add junit
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Jan 11, 2024
1 parent 2aeb1be commit c93b357
Show file tree
Hide file tree
Showing 13 changed files with 243 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public List<SecurityProfile> getSecurityProfiles() {
return actualAPIProxy.getSecurityProfiles();
}

private void expandTokenStoreAndAuthPolicy(){
private void expandTokenStoreAndAuthPolicy() {
for (SecurityProfile profile : actualAPIProxy.getSecurityProfiles()) {
for (SecurityDevice device : profile.getDevices()) {
if (device.getType().equals(DeviceType.oauthExternal)) {
Expand Down Expand Up @@ -102,15 +102,15 @@ public List<AuthenticationProfile> getAuthenticationProfiles() {
}

public Map<String, InboundProfile> getInboundProfiles() {
if (actualAPIProxy.getInboundProfiles() == null) return Collections.emptyMap();
if (actualAPIProxy.getInboundProfiles().isEmpty()) return Collections.emptyMap();
if (actualAPIProxy.getInboundProfiles() == null || actualAPIProxy.getInboundProfiles().isEmpty())
return Collections.emptyMap();
return actualAPIProxy.getInboundProfiles();
}


public List<CorsProfile> getCorsProfiles() {
if (actualAPIProxy.getCorsProfiles() == null) return Collections.emptyList();
if (actualAPIProxy.getCorsProfiles().isEmpty()) return Collections.emptyList();
if (actualAPIProxy.getCorsProfiles() == null || actualAPIProxy.getCorsProfiles().isEmpty())
return Collections.emptyList();
if (actualAPIProxy.getCorsProfiles().size() == 1) {
CorsProfile corsProfile = actualAPIProxy.getCorsProfiles().get(0);
if (corsProfile.equals(CorsProfile.getDefaultCorsProfile())) return Collections.emptyList();
Expand All @@ -135,8 +135,7 @@ public String getRemoteHost() {


public TagMap getTags() {
if (actualAPIProxy.getTags() == null) return new TagMap();
if (actualAPIProxy.getTags().isEmpty()) return new TagMap();
if (actualAPIProxy.getTags() == null || actualAPIProxy.getTags().isEmpty()) return new TagMap();
return actualAPIProxy.getTags();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,88 @@ public void getSecurityProfilesPassThrough() {
List<SecurityProfile> resultSecurityProfiles = exportAPI.getSecurityProfiles();
Assert.assertTrue(resultSecurityProfiles.isEmpty());
}

@Test
public void getRemoteHostNull(){
API api = new API();
ExportAPI exportAPI = new ExportAPI(api);
Assert.assertNull(exportAPI.getRemoteHost());
}

@Test
public void getRemoteHostStandard(){
API api = new API();
RemoteHost remoteHost = new RemoteHost();
remoteHost.setPort(443);
remoteHost.setName("api.axway.com");
api.setRemotehost(remoteHost);
ExportAPI exportAPI = new ExportAPI(api);
Assert.assertEquals(exportAPI.getRemoteHost(), "api.axway.com");
}

@Test
public void getRemoteHostCustomPort(){
API api = new API();
RemoteHost remoteHost = new RemoteHost();
remoteHost.setPort(8065);
remoteHost.setName("api.axway.com");
api.setRemotehost(remoteHost);
ExportAPI exportAPI = new ExportAPI(api);
Assert.assertEquals(exportAPI.getRemoteHost(), "api.axway.com:8065");
}

@Test
public void getCorsProfilesEmpty(){
API api = new API();
ExportAPI exportAPI = new ExportAPI(api);
Assert.assertTrue(exportAPI.getCorsProfiles().isEmpty());
}

@Test
public void getCorsProfilesDefault(){
API api = new API();
CorsProfile corsProfile = CorsProfile.getDefaultCorsProfile();
List<CorsProfile> corsProfiles = new ArrayList<>();
corsProfiles.add(corsProfile);
api.setCorsProfiles(corsProfiles);
ExportAPI exportAPI = new ExportAPI(api);
Assert.assertTrue(exportAPI.getCorsProfiles().isEmpty());
}

@Test
public void getCorsProfiles(){
API api = new API();
CorsProfile corsProfile = CorsProfile.getDefaultCorsProfile();
corsProfile.setName("custom");
List<CorsProfile> corsProfiles = new ArrayList<>();
corsProfiles.add(corsProfile);
api.setCorsProfiles(corsProfiles);
ExportAPI exportAPI = new ExportAPI(api);
Assert.assertFalse(exportAPI.getCorsProfiles().isEmpty());
}

@Test
public void getInboundProfilesEmpty(){
API api = new API();
ExportAPI exportAPI = new ExportAPI(api);
Assert.assertTrue(exportAPI.getInboundProfiles().isEmpty());
}

@Test
public void getTagsEmpty(){
API api = new API();
ExportAPI exportAPI = new ExportAPI(api);
Assert.assertTrue(exportAPI.getTags().isEmpty());
}

@Test
public void getTags(){
API api = new API();
TagMap apiManagerTags = new TagMap();
String[] tagValue = {"dev"};
apiManagerTags.put("stage", tagValue);
api.setTags(apiManagerTags);
ExportAPI exportAPI = new ExportAPI(api);
Assert.assertFalse(exportAPI.getTags().isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AppExportCLIOptions extends CLIOptions {
private AppExportCLIOptions(String[] args) {
super(args);
}

public static CLIOptions create(String[] args) throws AppException {
CLIOptions cliOptions = new AppExportCLIOptions(args);
cliOptions = new StandardExportCLIOptions(cliOptions);
Expand All @@ -30,7 +30,7 @@ public void addOptions() {
option.setRequired(false);
option.setArgName("*My Great App*");
addOption(option);

option = new Option("id", true, "Filter the export to an application with that specific ID.");
option.setRequired(false);
option.setArgName("UUID-ID-OF-THE-APP");
Expand All @@ -45,22 +45,22 @@ public void addOptions() {
option.setRequired(false);
option.setArgName("*Partners*");
addOption(option);

option = new Option("createdBy", true, "Filter for applications created by this user based on the login-name");
option.setRequired(false);
option.setArgName("tom");
addOption(option);

option = new Option("api", true, "Filter applications having access to this API. You may use wildcards at the end or beginning.");
option.setRequired(false);
option.setArgName("*MyAPI*");
addOption(option);

option = new Option("credential", true, "Filter applications having this credential information. Client-ID and API-Key is considered here.");
option.setRequired(false);
option.setArgName("*9877979779*");
addOption(option);

option = new Option("redirectUrl", true, "Filter applications having this Redirect-URL. Only OAuth-Credentials are considered.");
option.setRequired(false);
option.setArgName("*localhost*");
Expand All @@ -71,6 +71,7 @@ public void addOptions() {
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
Console.println("----------------------------------------------------------------------------------------");
Console.println(getAppName());
Console.println("How to get/export applications with different output formats");
Console.println("Get all applications on console using environment properties: env.api-env.properties:");
Console.println(getBinaryName()+" app get -s api-env");
Expand All @@ -93,7 +94,7 @@ public void printUsage(String message, String[] args) {
protected String getAppName() {
return "Application-Export";
}

@Override
public Parameters getParams() {
AppExportParams params = new AppExportParams();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.axway.apim.appexport.lib;

import com.axway.apim.lib.CLIOptions;
import com.axway.apim.lib.error.AppException;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class AppExportCLIOptionsTest {

@Test
public void printUsage() throws AppException {
PrintStream old = System.out;
String[] args = {"-h", "localhost", "-n", "test"};
CLIOptions options = AppExportCLIOptions.create(args);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(byteArrayOutputStream));
options.printUsage("test", args);
System.setOut(old);
Assert.assertTrue(byteArrayOutputStream.toString().contains("-n test"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public void addOptions() {
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
Console.println("----------------------------------------------------------------------------------------");
Console.println("How to Generate Config files");
Console.println(getAppName());
Console.println("How to Generate API Config files");
Console.println("Generate API manager configuration file based on Open API Specification");
Console.println(getBinaryName() + " template generate -c samples/config-api-specification.json -a samples/openapi.json");
Console.println("For more information and advanced examples please visit:");
Expand All @@ -70,7 +71,7 @@ public void printUsage(String message, String[] args) {

@Override
protected String getAppName() {
return "Application-Export";
return "Generate Template";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
Expand Down Expand Up @@ -185,4 +187,16 @@ public void testGenerateAPIConfigWithBackendSSL() throws IOException {
Assert.assertTrue(documentContext.read("$.authenticationProfiles[0].parameters.trustAll", Boolean.class));
Assert.assertTrue(documentContext.read("$.authenticationProfiles[0].isDefault", Boolean.class));
}

@Test
public void printUsage() throws AppException {
PrintStream old = System.out;
String[] args = {"template", "generate", "-c", "test/api-config.json", "-a", openApiLocation, "-apimCLIHome", apimCliHome, "-backendAuthType", "ssl", "-frontendAuthType", "apiKey"};
CLIOptions options = GenerateTemplateCLIOptions.create(args);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(byteArrayOutputStream));
options.printUsage("test", args);
System.setOut(old);
Assert.assertTrue(byteArrayOutputStream.toString().contains("generate"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static CLIOptions create(String[] args) throws AppException {
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
Console.println("----------------------------------------------------------------------------------------");
Console.println(getAppName());
Console.println("How to delete users using different filter options:");
Console.println(getBinaryName() + " user delete -s api-env");
Console.println(getBinaryName() + " user delete -s api-env -n \"*Name of user*\" -loginName \"*loginNameOfUser*\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public void addOptions() { // implementation ignored
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
Console.println("----------------------------------------------------------------------------------------");
Console.println("How to get/export user(s) with different output formats");
Console.println(getAppName());
Console.println("How to get/export user(s) with different output formats");
Console.println("Get all users on console using environment properties: env.api-env.properties:");
Console.println(getBinaryName()+" user get -s api-env");
Console.println("Same as before, but with output format JSON - As it is used to import applications");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public void addOptions() {
@Override
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
Console.println(getAppName());
Console.println("----------------------------------------------------------------------------------------");
Console.println("How to imports users using the JSON-Config format");
Console.println("Import an user using environment properties: env.api-env.properties:");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.axway.apim.user.cli;

import com.axway.apim.lib.CLIOptions;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.users.lib.cli.UserChangePasswordCLIOptions;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class UserChangePasswordCLIOptionsTest {

@Test
public void printUsage() throws AppException {
PrintStream old = System.out;
String[] args = {"-s", "prod", "-id", "UUID-ID-OF-THE-USER", "-loginName", "*mark24*", "-n", "*Mark*", "-email", "*@axway.com*", "-type", "external", "-org", "*Partner*", "-role", "oadmin", "-state", "pending", "-enabled", "true", "-o", "json", "-newpassword", "123456"};
CLIOptions options = UserChangePasswordCLIOptions.create(args);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(byteArrayOutputStream));
options.printUsage("test", args);
System.setOut(old);
Assert.assertTrue(byteArrayOutputStream.toString().contains("-id UUID-ID-OF-THE-USER"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.axway.apim.user.cli;

import com.axway.apim.lib.CLIOptions;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.users.lib.cli.UserDeleteCLIOptions;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class UserDeleteCLIOptionsTest {

@Test
public void printUsage() throws AppException {
PrintStream old = System.out;
String[] args = {"-s", "prod", "-n", "test"};
CLIOptions options = UserDeleteCLIOptions.create(args);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(byteArrayOutputStream));
options.printUsage("test", args);
System.setOut(old);
Assert.assertTrue(byteArrayOutputStream.toString().contains("-n test"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.axway.apim.user.cli;

import com.axway.apim.lib.CLIOptions;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.users.lib.cli.UserExportCLIOptions;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class UserExportCLIOptionsTest {

@Test
public void printUsage() throws AppException {
PrintStream old = System.out;
String[] args = {"-s", "prod", "-id", "UUID-ID-OF-THE-USER", "-loginName", "*mark24*", "-n", "*Mark*", "-email", "*@axway.com*", "-type", "external", "-org", "*Partner*", "-role", "oadmin", "-state", "pending", "-enabled", "false", "-o", "json"};
CLIOptions options = UserExportCLIOptions.create(args);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(byteArrayOutputStream));
options.printUsage("test", args);
System.setOut(old);
Assert.assertTrue(byteArrayOutputStream.toString().contains("-id UUID-ID-OF-THE-USER"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.axway.apim.user.cli;

import com.axway.apim.lib.CLIOptions;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.users.lib.cli.UserImportCLIOptions;
import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;

public class UserImportCLIOptionsTest {

@Test
public void printUsage() throws AppException {
PrintStream old = System.out;
String[] args = {"-s", "prod", "-c", "myUserConfig.json"};
CLIOptions options = UserImportCLIOptions.create(args);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(byteArrayOutputStream));
options.printUsage("test", args);
System.setOut(old);
Assert.assertTrue(byteArrayOutputStream.toString().contains("-c myUserConfig.json"));
}
}

0 comments on commit c93b357

Please sign in to comment.