use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testDocumentAdd.
@Test
public void testDocumentAdd() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
DocumentInfo documentInfo = SampleTestObjectCreator.createDefaultFileDocumentationInfo();
Assert.assertFalse(apiDAO.isDocumentExist(api.getId(), documentInfo));
apiDAO.addDocumentInfo(api.getId(), documentInfo);
apiDAO.addDocumentFileContent(documentInfo.getId(), IOUtils.toInputStream(SampleTestObjectCreator.createDefaultInlineDocumentationContent()), "inline1.txt", documentInfo.getCreatedBy());
Assert.assertTrue(apiDAO.isDocumentExist(api.getId(), documentInfo));
List<DocumentInfo> documentInfoList = apiDAO.getDocumentsInfoList(api.getId());
Assert.assertEquals(documentInfoList.get(0), documentInfo);
apiDAO.deleteDocument(documentInfo.getId());
Assert.assertFalse(apiDAO.isDocumentExist(api.getId(), documentInfo));
}
use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testUpdateGetDedicatedGatewayWhenLabelsAreNull.
@Test
public void testUpdateGetDedicatedGatewayWhenLabelsAreNull() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
DedicatedGateway dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(true);
dedicatedGateway.setUpdatedBy(api.getCreatedBy());
dedicatedGateway.setApiId(api.getId());
apiDAO.updateDedicatedGateway(dedicatedGateway, null);
DedicatedGateway result = apiDAO.getDedicatedGateway(api.getId());
Assert.assertEquals(result.isEnabled(), dedicatedGateway.isEnabled());
}
use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class ApiDAOImplIT method testAddGetCommentsOfAPI.
@Test
public void testAddGetCommentsOfAPI() throws Exception {
ApiDAO apiDAO = DAOFactory.getApiDAO();
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
API api = builder.build();
testAddGetEndpoint();
apiDAO.addAPI(api);
Comment comment1 = SampleTestObjectCreator.createDefaultComment(api.getId());
Comment comment2 = SampleTestObjectCreator.createAlternativeComment(api.getId());
apiDAO.addComment(comment1, api.getId());
apiDAO.addComment(comment2, api.getId());
List<Comment> commentsFromDB = apiDAO.getCommentsForApi(api.getId());
Assert.assertEquals(commentsFromDB.size(), 2);
Assert.assertTrue(commentsFromDB.get(0).getCommentText().equals(comment1.getCommentText()) || commentsFromDB.get(0).getCommentText().equals(comment2.getCommentText()));
Assert.assertTrue(commentsFromDB.get(1).getCommentText().equals(comment1.getCommentText()) || commentsFromDB.get(1).getCommentText().equals(comment2.getCommentText()));
}
use of org.wso2.carbon.apimgt.core.api.APIDefinition in project carbon-apimgt by wso2.
the class AuthenticatorService method getApplicationScopes.
/**
* This method returns the scopes for a given application.
*
* @param appName Name the application
* @return scopes - A space separated list of scope keys
* @throws APIManagementException When retrieving scopes from swagger definition fails
*/
private String getApplicationScopes(String appName) throws APIManagementException {
String scopes;
String applicationRestAPI = null;
if (AuthenticatorConstants.STORE_APPLICATION.equals(appName)) {
applicationRestAPI = RestApiUtil.getStoreRestAPIResource();
} else if (AuthenticatorConstants.PUBLISHER_APPLICATION.equals(appName)) {
applicationRestAPI = RestApiUtil.getPublisherRestAPIResource();
} else if (AuthenticatorConstants.ADMIN_APPLICATION.equals(appName)) {
applicationRestAPI = RestApiUtil.getAdminRestAPIResource();
}
try {
if (applicationRestAPI != null) {
APIDefinition apiDefinitionFromSwagger20 = new APIDefinitionFromSwagger20();
Map<String, Scope> applicationScopesMap = apiDefinitionFromSwagger20.getScopesFromSecurityDefinitionForWebApps(applicationRestAPI);
scopes = String.join(" ", applicationScopesMap.keySet());
// Set openid scope
if (StringUtils.isEmpty(scopes)) {
scopes = KeyManagerConstants.OPEN_ID_CONNECT_SCOPE;
} else {
scopes = scopes + " " + KeyManagerConstants.OPEN_ID_CONNECT_SCOPE;
}
} else {
String errorMsg = "Error while getting application rest API resource.";
log.error(errorMsg, ExceptionCodes.INTERNAL_ERROR);
throw new APIManagementException(errorMsg, ExceptionCodes.INTERNAL_ERROR);
}
} catch (APIManagementException e) {
String errorMsg = "Error while reading scopes from swagger definition.";
log.error(errorMsg, e, ExceptionCodes.INTERNAL_ERROR);
throw new APIManagementException(errorMsg, e, ExceptionCodes.INTERNAL_ERROR);
}
return scopes;
}
Aggregations