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

Add testcase HasThumbnailVariableWhenSearch #13210

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 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 @@ -79,6 +79,7 @@
import org.wso2.am.integration.clients.publisher.api.v1.dto.CommentListDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.DocumentDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.DocumentListDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.FileInfoDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.GraphQLQueryComplexityInfoDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.GraphQLSchemaDTO;
import org.wso2.am.integration.clients.publisher.api.v1.dto.GraphQLSchemaTypeListDTO;
Expand Down Expand Up @@ -372,6 +373,10 @@ public APIDTO addAPI(APIDTO apidto, String osVersion) throws ApiException {
return httpInfo.getData();
}

public FileInfoDTO updateAPIThumbnail(String apiId, File file) throws ApiException {
return apIsApi.updateAPIThumbnail(apiId, file, null);
}

private boolean isAsyncApi(APIRequest apiRequest) {

String type = apiRequest.getType();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
*Copyright (c) 2023, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
*
*WSO2 LLC. licenses this file to you under the Apache License,
*Version 2.0 (the "License"); you may not use this file except
*in compliance with the License.
*You may obtain a copy of the License at
*
*http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing,
*software distributed under the License is distributed on an
*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
*KIND, either express or implied. See the License for the
*specific language governing permissions and limitations
*under the License.
*/

package org.wso2.am.integration.tests.restapi;

import com.google.gson.internal.LinkedTreeMap;
import org.apache.http.HttpStatus;
import org.testng.Assert;
import org.testng.annotations.*;
import org.wso2.am.integration.clients.publisher.api.v1.dto.SearchResultListDTO;
import org.wso2.am.integration.test.utils.base.APIMIntegrationBaseTest;
import org.wso2.am.integration.test.utils.bean.*;
import org.wso2.am.integration.test.utils.clients.APIPublisherRestClient;
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;

import java.io.File;
import java.net.URL;

public class ThumbnailSearchTestCase extends APIMIntegrationBaseTest {
private String testApiId;

@BeforeClass(alwaysRun = true) public void setEnvironment() throws Exception {

super.init();
String publisherURLHttp = publisherUrls.getWebAppURLHttp();

APIPublisherRestClient apiPublisher = new APIPublisherRestClient(publisherURLHttp);

apiPublisher.login(publisherContext.getContextTenant().getContextUser().getUserName(),
publisherContext.getContextTenant().getContextUser().getPassword());

}

@Test(groups = { "wso2.am" },
description = "Test whether the API thumbnail information is reflected in the API search results.")
public void testHasThumbnailVariableWhenSearch() throws Exception {

//prepare API to create and publish
String imageFile = "thumbnail.png";
String apiContext = "testContext";
String url = "https://localhost:9443/test";
String apiName = "TestAPI";
String apiVersion = "1.0.0";
APIRequest apiRequest = new APIRequest(apiName, apiContext, new URL(url));
String description = "This is test API create by API manager integration test.";
apiRequest.setDescription(description);
apiRequest.setVersion(apiVersion);
apiRequest.setSandbox(url);
apiRequest.setResourceMethod("GET");
apiRequest.setProvider(user.getUserName());

//set API visibility to public hence this API should be visible to all tenants
apiRequest.setVisibility("public");
HttpResponse response = restAPIPublisher.addAPI(apiRequest);
testApiId = response.getData();
int responseCode = response.getResponseCode();

// Assert api creation.
Assert.assertEquals(responseCode, HttpStatus.SC_CREATED);

HttpResponse lifecycleResponse = restAPIPublisher.
changeAPILifeCycleStatusToPublish(testApiId, false);

// Assert successful lifecycle change
Assert.assertEquals(lifecycleResponse.getResponseCode(), HttpStatus.SC_OK);

String imagePath = (new File(System.getProperty("user.dir"))).getParent() + RESTAPITestConstants.PATH_SUBSTRING
+ imageFile;
File image = new File(imagePath);

//upload the thumbnail image
restAPIPublisher.updateAPIThumbnail(testApiId, image);

//search for the API
SearchResultListDTO searchResultListDTO = restAPIPublisher.searchAPIs("test");

//check whether the hasThumbnail variable is set to true
assert searchResultListDTO.getList() != null;
LinkedTreeMap searchResultDTO = (LinkedTreeMap) searchResultListDTO.getList().get(0);
Assert.assertEquals(searchResultDTO.get("hasThumbnail").toString(), "true");
}

@AfterClass(alwaysRun = true) public void destroy() throws Exception {
if (testApiId != null) {
restAPIPublisher.deleteAPI(testApiId);
}
super.cleanUp();
}
}



Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<parameter name="group" value="group1"/>
<classes>
<class name="org.wso2.am.integration.tests.restapi.ContentSearchTestCase"/>
<class name="org.wso2.am.integration.tests.restapi.ThumbnailSearchTestCase"/>
<class name="org.wso2.am.integration.tests.other.PublisherAccessControlTestCase"/>
<!-- <class name="org.wso2.am.integration.tests.other.DevPortalVisibilityTestCase"/>-->
<class name="org.wso2.am.integration.tests.api.lifecycle.APIVisibilityWithDirectURLTestCase"/>
Expand Down
Loading