Skip to content

Commit

Permalink
- Fix application api access test
Browse files Browse the repository at this point in the history
  • Loading branch information
rathnapandi committed Dec 7, 2023
1 parent 606be62 commit 5f33a68
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public void populateApiId(APIAccess apiAccess) throws AppException {
public void createAPIAccess(APIAccess apiAccess, AbstractEntity parentEntity, Type type) throws AppException {
List<APIAccess> existingAPIAccess = getAPIAccess(parentEntity, type);
if (existingAPIAccess != null &&
existingAPIAccess.stream().anyMatch(existingAPIAccessElement -> existingAPIAccessElement.getApiId().equals(apiAccess.getApiId()))) {
existingAPIAccess.stream().anyMatch(existingAPIAccessElement -> existingAPIAccessElement.getApiId().equals(apiAccess.getApiId()))) {
apiAccess.setId(existingAPIAccess.get(0).getId());
return;
}
Expand Down Expand Up @@ -282,15 +282,17 @@ public void removeClientOrganization(List<Organization> removingActualOrgs, Stri
}
}

private List<APIAccess> getMissingAPIAccesses(List<APIAccess> apiAccess, List<APIAccess> otherApiAccess) {
List<APIAccess> missingAccess = new ArrayList<>();
public List<APIAccess> getMissingAPIAccesses(List<APIAccess> apiAccess, List<APIAccess> otherApiAccess) {
if (otherApiAccess == null) otherApiAccess = new ArrayList<>();
if (apiAccess == null) apiAccess = new ArrayList<>();
List<APIAccess> missingAccess = new ArrayList<>();
for (APIAccess access : apiAccess) {
if (otherApiAccess.contains(access)) {
continue;
for (APIAccess otherAccess : otherApiAccess) {
if (access.getApiId().equals(otherAccess.getApiId())) {
break;
}
missingAccess.add(access);
}
missingAccess.add(access);
}
return missingAccess;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ public void saveQuota(ClientApplication app, ClientApplication actualApp) throws

private void saveAPIAccess(ClientApplication app, ClientApplication actualApp) throws AppException {
if (app.getApiAccess() == null || app.getApiAccess().isEmpty()) return;
if (actualApp != null && app.getApiAccess().equals(actualApp.getApiAccess())) return;
if (actualApp != null && Utils.compareValues(app.getApiAccess(),(actualApp.getApiAccess()))) return;
APIManagerAPIAccessAdapter accessAdapter = APIManagerAdapter.getInstance().getAccessAdapter();
accessAdapter.saveAPIAccess(app.getApiAccess(), app, Type.applications);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.axway.apim.lib.CoreParameters;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.lib.utils.Utils;
import com.beust.ah.A;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
Expand Down Expand Up @@ -125,4 +126,93 @@ public void createAPIAccessWithExistingApi() throws AppException {
}
}

@Test
public void getMissingAPIAccessesEmpty(){
List<APIAccess> apiAccess = new ArrayList<>();
List<APIAccess> otherApiAccess = new ArrayList<>();
List<APIAccess> missingApiAccesses = apiManagerAPIAccessAdapter.getMissingAPIAccesses(apiAccess, otherApiAccess);
Assert.assertTrue(missingApiAccesses.isEmpty());
}


@Test
public void getMissingAPIAccessesSame(){
List<APIAccess> apiAccesses = new ArrayList<>();
APIAccess apiAccess = new APIAccess();
apiAccess.setApiId("1235");
apiAccesses.add(apiAccess);
List<APIAccess> otherApiAccess = new ArrayList<>();
otherApiAccess.add(apiAccess);
List<APIAccess> missingApiAccesses = apiManagerAPIAccessAdapter.getMissingAPIAccesses(apiAccesses, otherApiAccess);
Assert.assertTrue(missingApiAccesses.isEmpty());
}


@Test
public void getMissingAPIAccessesSourceEmpty(){
List<APIAccess> apiAccesses = new ArrayList<>();
List<APIAccess> otherApiAccess = new ArrayList<>();
APIAccess apiAccess = new APIAccess();
apiAccess.setApiId("1235");
otherApiAccess.add(apiAccess);
List<APIAccess> missingApiAccesses = apiManagerAPIAccessAdapter.getMissingAPIAccesses(apiAccesses, otherApiAccess);
Assert.assertTrue(missingApiAccesses.isEmpty());
}

@Test
public void getMissingAPIAccessesTargetEmpty(){
List<APIAccess> apiAccesses = new ArrayList<>();
APIAccess apiAccess = new APIAccess();
apiAccess.setApiId("1235");
List<APIAccess> otherApiAccess = new ArrayList<>();
otherApiAccess.add(apiAccess);
List<APIAccess> missingApiAccesses = apiManagerAPIAccessAdapter.getMissingAPIAccesses(apiAccesses, otherApiAccess);
System.out.println(missingApiAccesses);
Assert.assertTrue(missingApiAccesses.isEmpty());
}

@Test
public void getMissingAPIAccessesWithDuplicates(){
List<APIAccess> apiAccesses = new ArrayList<>();
APIAccess apiAccess = new APIAccess();
apiAccess.setApiId("1235");
apiAccesses.add(apiAccess);
List<APIAccess> otherApiAccess = new ArrayList<>();
otherApiAccess.add(apiAccess);
List<APIAccess> missingApiAccesses = apiManagerAPIAccessAdapter.getMissingAPIAccesses(apiAccesses, otherApiAccess);
System.out.println(missingApiAccesses);
Assert.assertEquals(0,missingApiAccesses.size());
}

@Test
public void getMissingAPIAccessesWithUnique(){
List<APIAccess> apiAccesses = new ArrayList<>();
APIAccess apiAccess = new APIAccess();
apiAccess.setApiId("1235");
apiAccesses.add(apiAccess);
List<APIAccess> otherApiAccess = new ArrayList<>();
APIAccess apiAccess2 = new APIAccess();
apiAccess2.setApiId("12345");
otherApiAccess.add(apiAccess2);
List<APIAccess> missingApiAccesses = apiManagerAPIAccessAdapter.getMissingAPIAccesses(apiAccesses, otherApiAccess);
Assert.assertEquals("1235",missingApiAccesses.get(0).getApiId());
}

@Test
public void getMissingAPIAccessesWithUniqueReverse(){
List<APIAccess> apiAccesses = new ArrayList<>();
APIAccess apiAccess = new APIAccess();
apiAccess.setApiId("1235");
apiAccesses.add(apiAccess);
List<APIAccess> otherApiAccess = new ArrayList<>();
APIAccess apiAccess2 = new APIAccess();
apiAccess2.setApiId("12345");
otherApiAccess.add(apiAccess2);
List<APIAccess> missingApiAccesses = apiManagerAPIAccessAdapter.getMissingAPIAccesses(otherApiAccess, apiAccesses);
Assert.assertEquals("12345",missingApiAccesses.get(0).getApiId());
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.axway.apim.api.model.apps.ClientApplication;
import com.axway.apim.lib.error.AppException;
import com.axway.apim.lib.error.ErrorCode;
import com.axway.apim.lib.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -51,8 +52,8 @@ public void setActualApp(ClientApplication actualApp) {

public static boolean appsAreEqual(ClientApplication desiredApp, ClientApplication actualApp) {
boolean application = desiredApp.equals(actualApp);
boolean apiAccess = (desiredApp.getApiAccess() == null || desiredApp.getApiAccess().equals(actualApp.getApiAccess()));
boolean permission = (desiredApp.getPermissions() == null || desiredApp.getPermissions().containsAll(actualApp.getPermissions()));
boolean apiAccess = (desiredApp.getApiAccess() == null || Utils.compareValues(desiredApp.getApiAccess(), actualApp.getApiAccess()));
boolean permission = (desiredApp.getPermissions() == null || Utils.compareValues(desiredApp.getPermissions(), actualApp.getPermissions()));
boolean quota = (desiredApp.getAppQuota() == null || desiredApp.getAppQuota().equals(actualApp.getAppQuota()));
LOG.debug("apps Not changed: {}", application);
LOG.debug("api access Not changed: {}", apiAccess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void importApplicationBasicTest(@Optional @CitrusResource TestContext con
createVariable(TestParams.PARAM_EXPECTED_RC, "0");
importApp.doExecute(context);


echo("####### Validate application: '${appName}' has been imported now having access to two APIs #######");
http(builder -> builder.client("apiManager").send().get("/applications/${appId}").header("Content-Type", "application/json"));

Expand Down

0 comments on commit 5f33a68

Please sign in to comment.