Skip to content

Commit

Permalink
Fix content search integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Avishka-Shamendra committed Sep 20, 2024
1 parent 349ff8a commit 8b993fc
Showing 1 changed file with 39 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,11 @@ public void setEnvironment() throws Exception {
userManagementClient1.updateRolesOfUser(user.getUserNameWithoutDomain(), newRoleList);
}

userManagementClient1
.addUser(user1, password, new String[] { role1, "Internal/publisher", "Internal/subscriber" }, user1);
userManagementClient1
.addUser(user2, password, new String[] { role2, "Internal/publisher", "Internal/subscriber" }, user2);

APIRequest apiRequest = createAPIRequest(contentSearchTestAPI, contentSearchTestAPI, endpointURL, version,
user.getUserName(), description);

apiId = createAndPublishAPIUsingRest(apiRequest, restAPIPublisher, false);

//Login to API Publisher adn Store with CarbonSuper normal user1
restAPIPublisherFirstUser = new RestAPIPublisherImpl(user1, password, user.getUserDomain(), publisherURLHttps);
restAPIPublisherSecondUser = new RestAPIPublisherImpl(user2, password, user.getUserDomain(), publisherURLHttps);

restAPIStoreFirstUser = new RestAPIStoreImpl(user1, password, user.getUserDomain(), storeURLHttps);
restAPIStoreSecondUser = new RestAPIStoreImpl(user2, password, user.getUserDomain(), storeURLHttps);

}

@Test(groups = { "wso2.am" }, description = "Test basic content Search")
Expand All @@ -137,7 +125,7 @@ public void testBasicContentSearch() throws Exception {
//check in publisher
for (int i = 0; i <= retries; i++) {
SearchResultListDTO searchResultListDTO = restAPIPublisher.searchAPIs(description);
if (searchResultListDTO.getCount() == 1) {
if (searchResultListDTO.getCount() >= 1) {
Assert.assertTrue(true);
break;
} else {
Expand All @@ -156,7 +144,7 @@ public void testBasicContentSearch() throws Exception {
//search term : UnifiedSearchFeature, created api has this in description filed
org.wso2.am.integration.clients.store.api.v1.dto.SearchResultListDTO searchResultListDTO = restAPIStore
.searchAPIs(description);
if (searchResultListDTO.getCount() == 1) {
if (searchResultListDTO.getCount() >= 1) { // API and API Definitions
Assert.assertTrue(true);
break;
} else {
Expand Down Expand Up @@ -252,7 +240,7 @@ public void testDocumentContentSearch() throws Exception {
@Test(groups = {
"wso2.am" }, description = "Test content Search with access control", dependsOnMethods = "testBasicContentSearch")
public void testContentSearchWithAccessControl() throws Exception {

// Set API publisher access control to role1
HttpResponse httpResponse = restAPIPublisher.getAPI(apiId);
Gson g = new Gson();
APIDTO apiDto = g.fromJson(httpResponse.getData(), APIDTO.class);
Expand All @@ -262,25 +250,31 @@ public void testContentSearchWithAccessControl() throws Exception {
roles.add(role1);
apiDto.setAccessControlRoles(roles);

apiDto.setVisibility(APIDTO.VisibilityEnum.RESTRICTED);
apiDto.setVisibleRoles(roles);

restAPIPublisher.updateAPI(apiDto);

restAPIPublisher.changeAPILifeCycleStatus(apiId, APILifeCycleAction.PUBLISH.getAction());

// Add users for test
userManagementClient1
.addUser(user1, password, new String[] { role1, "Internal/publisher"}, user1);
userManagementClient1
.addUser(user2, password, new String[] { role2, "Internal/publisher"}, user2);

//Login to API Publisher adn Store with CarbonSuper normal user1
restAPIPublisherFirstUser = new RestAPIPublisherImpl(user1, password, user.getUserDomain(), publisherURLHttps);
restAPIPublisherSecondUser = new RestAPIPublisherImpl(user2, password, user.getUserDomain(), publisherURLHttps);

//check with user1
for (int i = 0; i <= retries; i++) {
SearchResultListDTO searchResultListDTO = restAPIPublisherFirstUser.searchAPIs(description);
if (searchResultListDTO.getCount() == 1) {
if (searchResultListDTO.getCount() == 2) { // API and API Definition
Assert.assertTrue(true);
break;
} else {
if (i == retries) {
Assert.fail("Content search with access control failed. 1 result expected. Received response : "
Assert.fail("Content search with access control failed. 2 result expected. Received response : "
+ searchResultListDTO.getCount());
} else {
log.warn("Content search with access control failed. 1 results expected. Received response : "
log.warn("Content search with access control failed. 2 results expected. Received response : "
+ searchResultListDTO.getCount() + " Retrying...");
Thread.sleep(3000);
}
Expand Down Expand Up @@ -314,19 +308,39 @@ public void testContentSearchWithAccessControl() throws Exception {
"wso2.am" }, description = "Test content Search with store visibility", dependsOnMethods = "testContentSearchWithAccessControl")
public void testContentSearchWithStoreVisibility() throws Exception {

// Set store visibility to role1
HttpResponse httpResponse = restAPIPublisher.getAPI(apiId);
Gson g = new Gson();
APIDTO apiDto = g.fromJson(httpResponse.getData(), APIDTO.class);
apiDto.setAccessControl(APIDTO.AccessControlEnum.NONE);

List<String> roles = new ArrayList<>();
roles.add(role1);
apiDto.setVisibility(APIDTO.VisibilityEnum.RESTRICTED);
apiDto.setVisibleRoles(roles);

restAPIPublisher.updateAPI(apiDto);

// Update user for tests
userManagementClient1.updateRolesOfUser(user1, new String[] { role1, "Internal/subscriber" });
userManagementClient1.updateRolesOfUser(user2, new String[] { role2, "Internal/subscriber" });

restAPIStoreFirstUser = new RestAPIStoreImpl(user1, password, user.getUserDomain(), storeURLHttps);
restAPIStoreSecondUser = new RestAPIStoreImpl(user2, password, user.getUserDomain(), storeURLHttps);

//check with user1
for (int i = 0; i <= retries; i++) {
org.wso2.am.integration.clients.store.api.v1.dto.SearchResultListDTO searchResultListDTO = restAPIStoreFirstUser
.searchAPIs(description);
if (searchResultListDTO.getCount() == 1) {
if (searchResultListDTO.getCount() == 2) { // API and API Definition
Assert.assertTrue(true);
break;
} else {
if (i == retries) {
Assert.fail("Content search with visibility failed. 1 result expected. Received response : "
Assert.fail("Content search with visibility failed. 2 result expected. Received response : "
+ searchResultListDTO.getCount());
} else {
log.warn("Content search with visibility failed. 1 results expected. Received response : "
log.warn("Content search with visibility failed. 2 results expected. Received response : "
+ searchResultListDTO.getCount() + " Retrying...");
Thread.sleep(5000);
}
Expand Down

0 comments on commit 8b993fc

Please sign in to comment.