Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search Enhancements Add API Definition Content Search #13507

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading