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 84a6315 commit 32e4880
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ public void printUsage(String message, String[] args) {
Console.println("----------------------------------------------------------------------------------------");
Console.println("Approve APIs using different filter options:");
Console.println("** APIs must be in pending state to be considered for approval ** ");
Console.println(getBinaryName()+" api approve -s api-env");
Console.println(getBinaryName()+" api approve -s api-env -n \"*API*\"");
Console.println(getBinaryName()+" api approve -s api-env -id f6106454-1651-430e-8a2f-e3514afad8ee");
Console.println(getBinaryName()+" api approve -s api-env -policy \"*Policy ABC*\"");
Console.println(getBinaryName()+" api approve -s api-env -name \"*API*\" -policy \"*Policy ABC*\"");
Console.println(getAppName() + " -s api-env");
Console.println(getAppName() + " -s api-env -n \"*API*\"");
Console.println(getAppName() + " -s api-env -id f6106454-1651-430e-8a2f-e3514afad8ee");
Console.println(getAppName() + " -s api-env -policy \"*Policy ABC*\"");
Console.println(getAppName() + " -s api-env -name \"*API*\" -policy \"*Policy ABC*\"");
Console.println();
Console.println();
Console.println("For more information and advanced examples please visit:");
Expand Down
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 APIs using different filter options:");
Console.println(getBinaryName() + " api delete -s api-env");
Console.println(getBinaryName() + " api delete -s api-env -n \"*API*\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,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 APIs with different output formats");
Console.println("Get all APIs on console using environment properties: env.api-env.properties:");
Console.println(getBinaryName()+" api get -s api-env");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void addOptions() {
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
Console.println("----------------------------------------------------------------------------------------");
Console.println(getAppName());
Console.println("Changing APIs examples:");
Console.println();
Console.println("Changes the backend basepath of selected APIs from any to new");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void addOptions() {
public void printUsage(String message, String[] args) {
super.printUsage(message, args);
Console.println("----------------------------------------------------------------------------------------");
Console.println(getAppName());
Console.println("Check Certificate examples:");
Console.println();
Console.println("Certificate expires in next 90 days");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.testng.Assert;
import org.testng.annotations.Test;

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

public class CLIAPIApproveOptionsTest {

@Test
Expand Down Expand Up @@ -37,4 +40,16 @@ public void testApproveAPIParameters() throws AppException {

Assert.assertEquals(params.getPublishVhost(), "my.api-host.com");
}

@Test
public void printUsage() throws AppException {
PrintStream old = System.out;
String[] args = {"-s", "prod", "-a", "/api/v1/greet", "-publishVHost", "my.api-host.com"};
CLIOptions options = CLIAPIApproveOptions.create(args);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(byteArrayOutputStream));
options.printUsage("test", args);
System.setOut(old);
Assert.assertTrue(byteArrayOutputStream.toString().contains("-publishVHost my.api-host.com"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.testng.Assert;
import org.testng.annotations.Test;

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

public class CLIAPIDeleteOptionsTest {

@Test
Expand All @@ -15,4 +18,16 @@ public void cliApiDelete() throws AppException {
APIExportParams params = (APIExportParams) options.getParams();
Assert.assertEquals(params.getName(), "petstore");
}

@Test
public void printUsage() throws AppException {
PrintStream old = System.out;
String[] args = {"-h", "localhost", "-n", "petstore"};
CLIOptions options = CLIChangeAPIOptions.create(args);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(byteArrayOutputStream));
options.printUsage("test", args);
System.setOut(old);
Assert.assertTrue(byteArrayOutputStream.toString().contains("-n petstore"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.testng.Assert;
import org.testng.annotations.Test;

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

public class CLIAPIExportOptionsTest {


Expand Down Expand Up @@ -87,7 +90,7 @@ public void testCreatedOnAPIFilterParameters() throws AppException {
options = CLIAPIExportOptions.create(args3);
params = (APIExportParams) options.getParams();
Assert.assertEquals(params.getCreatedOnAfter(), "1590969600000");
Assert.assertTrue(Long.parseLong(params.getCreatedOnBefore())>Long.parseLong("1630665581555"), "Now should be always in the future.");
Assert.assertTrue(Long.parseLong(params.getCreatedOnBefore()) > Long.parseLong("1630665581555"), "Now should be always in the future.");
}

@Test(expectedExceptions = AppException.class, expectedExceptionsMessageRegExp = "The start-date: 01/Jan/2021 00:00:00 GMT cannot be bigger than the end date: 31/Dec/2020 23:59:59 GMT.")
Expand All @@ -96,6 +99,7 @@ public void testCreatedOnWithBiggerStartDate() throws AppException {
CLIOptions options = CLIAPIExportOptions.create(args);
options.getParams();
}

@Test(expectedExceptions = AppException.class, expectedExceptionsMessageRegExp = "You cannot use 'now' as the start date.")
public void testCreatedOnWithStartNow() throws AppException {
String[] args = {"-s", "prod", "-createdOn", "now:2020-12-31"};
Expand All @@ -110,4 +114,17 @@ public void testCreatedWithoutColon() throws AppException {
options.getParams();
}


@Test
public void printUsage() throws AppException {
PrintStream old = System.out;
String[] args = {"-s", "prod", "-createdOn", "2020-01-01-2020-12-31"};
CLIOptions options = CLIAPIExportOptions.create(args);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(byteArrayOutputStream));
options.printUsage("test", args);
System.setOut(old);
Assert.assertTrue(byteArrayOutputStream.toString().contains("-createdOn 2020-01-01-2020-12-31 "));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import org.testng.Assert;
import org.testng.annotations.Test;

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

public class CLIChangeAPIOptionsTest {

@Test
Expand All @@ -32,4 +35,16 @@ public void testChangeAPIParameters() throws AppException {
Assert.assertEquals(params.getOldBackend(), "http://my.old.backend");
}

@Test
public void printUsage() throws AppException {
PrintStream old = System.out;
String[] args = {"-s", "prod", "-a", "/api/v1/greet", "-newBackend", "http://my.new.backend", "-oldBackend", "http://my.old.backend"};
CLIOptions options = CLIChangeAPIOptions.create(args);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
System.setOut(new PrintStream(byteArrayOutputStream));
options.printUsage("test", args);
System.setOut(old);
Assert.assertTrue(byteArrayOutputStream.toString().contains("-newBackend http://my.new.backend"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import org.testng.Assert;
import org.testng.annotations.Test;

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

public class CLICheckCertificatesOptionsTest {

@Test
Expand All @@ -19,4 +22,16 @@ public void testCertificateCheckParams() throws AppException {
Assert.assertEquals(params.getPassword(), "changeme");
Assert.assertEquals(params.getAPIManagerURL().toString(), "https://localhost:8075");
}

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

0 comments on commit 32e4880

Please sign in to comment.