Skip to content

Commit

Permalink
Merge pull request #13507 from Avishka-Shamendra/swagger-content-search
Browse files Browse the repository at this point in the history
Search Enhancements Add API Definition Content Search
  • Loading branch information
Avishka-Shamendra authored Sep 23, 2024
2 parents 1d2ff36 + 01a7917 commit e74610b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@
<indexer class="org.wso2.carbon.governance.registry.extensions.indexers.RXTIndexer" mediaTypeRegEx="application/policy\+xml" profiles ="default,control-plane"/-->
<indexer class="org.wso2.carbon.apimgt.impl.indexing.indexer.DocumentIndexer" mediaTypeRegEx="application/vnd.wso2-document\+xml" profiles ="default,control-plane"/>
<indexer class="org.wso2.carbon.apimgt.impl.indexing.indexer.CustomAPIIndexer" mediaTypeRegEx="application/vnd.(.)+\+xml" profiles ="default,control-plane"/>
<indexer class="org.wso2.carbon.apimgt.impl.indexing.indexer.RESTAsyncAPIDefinitionIndexer" mediaTypeRegEx="application/json" profiles ="default,control-plane"/>
<indexer class="org.wso2.carbon.apimgt.impl.indexing.indexer.GraphQLAPIDefinitionIndexer" mediaTypeRegEx="text/plain(.)+charset=ISO-8859-1" profiles ="default,control-plane"/>
<indexer class="org.wso2.carbon.apimgt.impl.indexing.indexer.SOAPAPIDefinitionIndexer" mediaTypeRegEx="application/wsdl\+xml|application/octet-stream" profiles ="default,control-plane"/>
<!--indexer class="org.wso2.carbon.registry.indexing.indexer.XMLIndexer" mediaTypeRegEx="application/(.)+\+xml"/>
<indexer class="org.wso2.carbon.registry.indexing.indexer.PlainTextIndexer" mediaTypeRegEx="text/(.)+"/>
<indexer class="org.wso2.carbon.registry.indexing.indexer.PlainTextIndexer" mediaTypeRegEx="application/x-javascript"/-->
Expand Down
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,35 +240,40 @@ 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);
APIDTO apiDto = new Gson().fromJson(httpResponse.getData(), APIDTO.class);

apiDto.setAccessControl(APIDTO.AccessControlEnum.RESTRICTED);
List<String> roles = new ArrayList<>();
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 +307,38 @@ 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);
APIDTO apiDto = new Gson().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 e74610b

Please sign in to comment.