|
| 1 | +package com.axway.apim.apiimport.lib.cli; |
| 2 | + |
| 3 | +import com.axway.apim.apiimport.lib.params.APIImportDatParams; |
| 4 | +import com.axway.apim.lib.CLIOptions; |
| 5 | +import com.axway.apim.lib.error.AppException; |
| 6 | +import org.testng.Assert; |
| 7 | +import org.testng.annotations.Test; |
| 8 | + |
| 9 | +import java.io.ByteArrayOutputStream; |
| 10 | +import java.io.PrintStream; |
| 11 | + |
| 12 | +public class APIImportDatCLIOptionsTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + public void testAPIImportDatParameter() throws AppException { |
| 16 | + String[] args = {"-s", "prod", "-a", "api-export.dat", "-orgName", "API Development", "-datPassword", "changeme"}; |
| 17 | + CLIOptions options = CLIAPIImportDatOptions.create(args); |
| 18 | + APIImportDatParams params = (APIImportDatParams) options.getParams(); |
| 19 | + Assert.assertEquals(params.getUsername(), "apiadmin"); |
| 20 | + Assert.assertEquals(params.getPassword(), "changeme"); |
| 21 | + Assert.assertEquals(params.getAPIManagerURL().toString(), "https://localhost:8075"); |
| 22 | + Assert.assertEquals(params.getApiDefinition(), "api-export.dat"); |
| 23 | + Assert.assertEquals(params.getOrgName(), "API Development"); |
| 24 | + Assert.assertEquals(params.getDatPassword(), "changeme"); |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + public void testAPIImportDatParameterWithoutPassword() throws AppException { |
| 29 | + String[] args = {"-s", "prod", "-a", "api-export.dat", "-orgName", "API Development"}; |
| 30 | + CLIOptions options = CLIAPIImportDatOptions.create(args); |
| 31 | + APIImportDatParams params = (APIImportDatParams) options.getParams(); |
| 32 | + Assert.assertEquals(params.getUsername(), "apiadmin"); |
| 33 | + Assert.assertEquals(params.getPassword(), "changeme"); |
| 34 | + Assert.assertEquals(params.getAPIManagerURL().toString(), "https://localhost:8075"); |
| 35 | + Assert.assertEquals(params.getApiDefinition(), "api-export.dat"); |
| 36 | + Assert.assertEquals(params.getOrgName(), "API Development"); |
| 37 | + Assert.assertNull(params.getDatPassword()); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testPrintUsage() throws AppException { |
| 42 | + PrintStream old = System.out; |
| 43 | + String[] args = {"-s", "prod", "-a", "api-export.dat", "-orgName", "API Development"}; |
| 44 | + CLIOptions options = CLIAPIImportDatOptions.create(args); |
| 45 | + options.printUsage("test", args); |
| 46 | + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| 47 | + System.setOut(new PrintStream(byteArrayOutputStream)); |
| 48 | + options.printUsage("test", args); |
| 49 | + System.setOut(old); |
| 50 | + Assert.assertTrue(byteArrayOutputStream.toString().contains("import-dat")); |
| 51 | + |
| 52 | + } |
| 53 | +} |
0 commit comments