Skip to content

Commit

Permalink
- add junit
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Oct 17, 2024
1 parent c2ae152 commit 8594d3c
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,5 +217,14 @@ public void getApiAccess() throws AppException {
Assert.assertEquals(4, apiOrganizationSubscriptions.size());
}

@Test
public void createAPIAccessForApplication() throws AppException {
String applicationId = "40dd53a4-0b13-4485-82e8-63c687404c2f";
APIAccess apiAccess = new APIAccess();
apiAccess.setApiId("40dd53a4-0b13-4485-82e8-63c687404c2g");
APIAccess response = apiManagerAPIAccessAdapter.createAPIAccessForApplication(apiAccess, applicationId);
Assert.assertNotNull(response);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public API getDesiredAPI() throws AppException {
validateHasQueryStringKey(apiConfig);
completeCaCerts(apiConfig);
addQuotaConfiguration(apiConfig);
handleAllOrganizations(apiConfig);
handleOrganizations(apiConfig);
completeClientApplications(apiConfig);
handleVhost(apiConfig);
validateMethodDescription(apiConfig.getApiMethods());
Expand Down Expand Up @@ -181,7 +181,7 @@ private void validateOrganization(API apiConfig) throws AppException {
private void addAPISpecification(API apiConfig) throws IOException {
APISpecification apiSpecification;
if (((DesiredAPI) apiConfig).getDesiredAPISpecification() != null) {
// API-Specification object that might contain filters, the type of an API, etc.
// API-Specification object that might contain filters, the type of API, etc.
apiSpecification = APISpecificationFactory.getAPISpecification(((DesiredAPI) apiConfig).getDesiredAPISpecification(), this.apiConfigFile.getCanonicalFile().getParent(), apiConfig.getName());
} else if (StringUtils.isNotEmpty(this.pathToAPIDefinition)) {
apiSpecification = APISpecificationFactory.getAPISpecification(this.pathToAPIDefinition, this.apiConfigFile.getCanonicalFile().getParent(), apiConfig.getName());
Expand All @@ -196,18 +196,17 @@ private void addAPISpecification(API apiConfig) throws IOException {
apiConfig.setApiDefinition(apiSpecification);
}

private void handleAllOrganizations(API apiConfig) throws AppException {
public void handleOrganizations(API apiConfig) throws AppException {
if (apiConfig.getClientOrganizations() == null) return;
if (apiConfig.getState().equals(API.STATE_UNPUBLISHED)) {
apiConfig.setClientOrganizations(null); // Making sure, orgs are not considered as a changed property
return;
}
APIManagerOrganizationAdapter organizationAdapter = APIManagerAdapter.getInstance().getOrgAdapter();
if (apiConfig.getClientOrganizations().contains(new Organization.Builder().hasName("ALL").build())) {
List<Organization> allOrgs = organizationAdapter.getAllOrgs();
apiConfig.getClientOrganizations().clear();
allOrgs.remove(apiConfig.getOrganization());
apiConfig.getClientOrganizations().addAll(allOrgs);
List<Organization> organizations = organizationAdapter.getAllOrgs();
organizations.remove(apiConfig.getOrganization());
apiConfig.setClientOrganizations(organizations);
apiConfig.setRequestForAllOrgs(true);
} else {
List<Organization> filteredOrganizations = removeInvalidOrganizations(apiConfig.getClientOrganizations());
Expand Down Expand Up @@ -370,7 +369,7 @@ private void addDefaultCorsProfile(API apiConfig) {
/**
* Purpose of this method is to load the actual existing applications from API-Manager
* based on the provided criteria (App-Name, API-Key, OAuth-ClientId or Ext-ClientId).
* Or, if the APP doesn't exists remove it from the list and log a warning message.
* Or, if the APP doesn't exist remove it from the list and log a warning message.
* Additionally, for each application it's checked, that the organization has access
* to this API, otherwise it will be removed from the list as well and a warning message is logged.
*
Expand Down Expand Up @@ -436,7 +435,6 @@ private static ClientApplication getAppForCredential(String credential, String t
ClientApplication app = APIManagerAdapter.getInstance().getAppIdForCredential(credential, type);
if (app == null) {
LOG.warn("Unknown application with ({}): {} configured. Ignoring this application.", type, credential);
return null;
}
return app;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.axway.apim.WiremockWrapper;
import com.axway.apim.api.API;
import com.axway.apim.api.model.CaCert;
import com.axway.apim.api.model.Organization;
import com.axway.apim.api.model.OutboundProfile;
import com.axway.apim.apiimport.lib.params.APIImportParams;
import com.axway.apim.lib.CoreParameters;
Expand All @@ -20,6 +21,7 @@
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -334,4 +336,66 @@ public void testOutboundBasicAuthEmptyPassword() throws AppException {
Assert.assertEquals("", apiConfig.getAuthenticationProfiles().get(0).getParameters().get("password"));
}

@Test
public void handleOrganizationsDoNothing() throws AppException {
APIImportParams params = new APIImportParams();
params.setHostname("localhost");
params.setUsername("test");
params.setPassword(Utils.getEncryptedPassword());
String testConfig = this.getClass().getResource("/com/axway/apim/test/files/basic/outbound_basic_auth_empty_password.json").getFile();
params.setConfig(testConfig);
APIImportConfigAdapter adapter = new APIImportConfigAdapter(params);
API api = new API();
adapter.handleOrganizations(api);
Assert.assertNull(api.getClientOrganizations());
}

@Test
public void handleOrganizationsWithUnpublishedApi() throws AppException {
APIImportParams params = new APIImportParams();
params.setHostname("localhost");
params.setUsername("test");
params.setPassword(Utils.getEncryptedPassword());
String testConfig = this.getClass().getResource("/com/axway/apim/test/files/basic/outbound_basic_auth_empty_password.json").getFile();
params.setConfig(testConfig);
APIImportConfigAdapter adapter = new APIImportConfigAdapter(params);
API api = new API();
api.setState(API.STATE_UNPUBLISHED);
api.setClientOrganizations(new ArrayList<>());
adapter.handleOrganizations(api);
Assert.assertNull(api.getClientOrganizations());
}

@Test
public void handleOrganizationsAll() throws AppException {
APIImportParams params = new APIImportParams();
params.setHostname("localhost");
params.setUsername("test");
params.setPassword(Utils.getEncryptedPassword());
String testConfig = this.getClass().getResource("/com/axway/apim/test/files/basic/outbound_basic_auth_empty_password.json").getFile();
params.setConfig(testConfig);
APIImportConfigAdapter adapter = new APIImportConfigAdapter(params);
API api = new API();
api.setState(API.STATE_PUBLISHED);
api.setClientOrganizations(Arrays.asList(new Organization("ALL")));
adapter.handleOrganizations(api);
Assert.assertEquals(api.getClientOrganizations().size(), 1);
}

@Test
public void handleOrganizationsSingle() throws AppException {
APIImportParams params = new APIImportParams();
params.setHostname("localhost");
params.setUsername("test");
params.setPassword(Utils.getEncryptedPassword());
String testConfig = this.getClass().getResource("/com/axway/apim/test/files/basic/outbound_basic_auth_empty_password.json").getFile();
params.setConfig(testConfig);
APIImportConfigAdapter adapter = new APIImportConfigAdapter(params);
API api = new API();
api.setState(API.STATE_PUBLISHED);
api.setClientOrganizations(Arrays.asList(new Organization("orga")));
adapter.handleOrganizations(api);
Assert.assertEquals(api.getClientOrganizations().size(), 1);
}

}
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>

Expand Down

0 comments on commit 8594d3c

Please sign in to comment.