use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class RegistrySearchUtilTestCase method testAnonymousUserQueryInDevPortal.
@Test
public void testAnonymousUserQueryInDevPortal() throws APIPersistenceException {
// Normal dev portal api listing
String inputQuery = "";
UserContext ctx = new UserContext("wso2.anonymous.user", organization, null, anonymousRoles);
String searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
String expected = "store_view_roles=(null OR system\\/wso2.anonymous.role)&name=*&enableStore=(true OR null)" + "&group=true&group.field=name&group.ngroups=true&group.sort=versionTimestamp desc&lcState=(PUBLISHED OR PROTOTYPED)";
Assert.assertEquals("Generated query mismatched. ", expected, searchQuery);
// search for 'test' in description
inputQuery = "description:test";
expected = "store_view_roles=(null OR system\\/wso2.anonymous.role)&" + "description=*test*&lcState=(PUBLISHED OR PROTOTYPED)";
searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
Assert.assertEquals("Generated query mismatched for description search. ", expected, searchQuery);
// search for provider 'pubuser'
inputQuery = "provider:pubuser";
expected = "store_view_roles=(null OR system\\/wso2.anonymous.role)&" + "provider=*pubuser*&lcState=(PUBLISHED OR PROTOTYPED)";
searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
Assert.assertEquals("Generated query mismatched for provider search. ", expected, searchQuery);
// search for propertyname 'test'
inputQuery = "property_name:test";
expected = "store_view_roles=(null OR system\\/wso2.anonymous.role)" + "&api_meta.property_name__display=*test*&lcState=(PUBLISHED OR PROTOTYPED)";
searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
Assert.assertEquals("Generated query mismatched for property search. ", expected, searchQuery);
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class RegistrySearchUtilTestCase method testPublisherUserQueryInPublisher.
@Test
public void testPublisherUserQueryInPublisher() throws APIPersistenceException {
// Normal publisher api listing
String inputQuery = "";
UserContext ctx = new UserContext("publisher", organization, null, publisherRoles);
String searchQuery = RegistrySearchUtil.getPublisherSearchQuery(inputQuery, ctx);
String expected = "publisher_roles=(null OR internal\\/creator OR internal\\/publisher OR internal\\/everyone)" + "&name=*&type=(HTTP OR WS OR SOAPTOREST OR GRAPHQL OR SOAP OR SSE OR WEBSUB OR WEBHOOK OR ASYNC)";
Assert.assertEquals("Generated query mismatched. ", expected, searchQuery);
// search for 'test' in description
inputQuery = "description:test";
expected = "publisher_roles=(null OR internal\\/creator OR internal\\/publisher OR internal\\/everyone)" + "&description=*test*&type=(HTTP OR WS OR SOAPTOREST OR GRAPHQL OR SOAP OR SSE OR WEBSUB OR WEBHOOK " + "OR ASYNC)";
searchQuery = RegistrySearchUtil.getPublisherSearchQuery(inputQuery, ctx);
Assert.assertEquals("Generated query mismatched for description search. ", expected, searchQuery);
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class ApiPurgeTest method testOrganizationRemoval.
@Test
public void testOrganizationRemoval() throws APIManagementException, APIPersistenceException {
PowerMockito.mockStatic(OrganizationPurgeDAO.class);
PowerMockito.when(OrganizationPurgeDAO.getInstance()).thenReturn(organizationPurgeDAO);
PowerMockito.mockStatic(GatewayArtifactsMgtDAO.class);
PowerMockito.when(GatewayArtifactsMgtDAO.getInstance()).thenReturn(gatewayArtifactsMgtDAO);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
PowerMockito.mockStatic(APIUtil.class);
Mockito.when(APIUtil.isAllowDisplayAPIsWithMultipleStatus()).thenReturn(true);
APIIdentifier api = Mockito.mock(APIIdentifier.class);
ArrayList<APIIdentifier> apiIdentifierList = new ArrayList<>();
apiIdentifierList.add(api);
Mockito.doReturn(apiIdentifierList).when(organizationPurgeDAO).getAPIIdList("testOrg");
Mockito.doNothing().when(organizationPurgeDAO).deleteOrganizationAPIList(Mockito.any());
Mockito.doNothing().when(gatewayArtifactsMgtDAO).removeOrganizationGatewayArtifacts(Mockito.any());
Mockito.doNothing().when(apiPersistenceInstance).deleteAllAPIs(any(Organization.class));
Mockito.doReturn(true).when(organizationPurgeDAO).apiOrganizationExist(Mockito.anyString());
ApiPurge apiPurge = new ApiPurgeWrapper(apiPersistenceInstance);
LinkedHashMap<String, String> subtaskResult = apiPurge.purge("testOrg");
for (Map.Entry<String, String> entry : subtaskResult.entrySet()) {
Assert.assertEquals(entry.getKey() + " is not successful", APIConstants.OrganizationDeletion.COMPLETED, entry.getValue());
}
Mockito.verify(organizationPurgeDAO, Mockito.times(1)).getAPIIdList("testOrg");
Mockito.verify(organizationPurgeDAO, Mockito.times(1)).deleteOrganizationAPIList(Mockito.any());
Mockito.verify(gatewayArtifactsMgtDAO, Mockito.times(1)).removeOrganizationGatewayArtifacts(Mockito.any());
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAllAPIs.
public List<API> getAllAPIs() throws APIManagementException {
List<API> apiSortedList = new ArrayList<API>();
Organization org = new Organization(tenantDomain);
String[] roles = APIUtil.getFilteredUserRoles(username);
Map<String, Object> properties = APIUtil.getUserProperties(username);
UserContext userCtx = new UserContext(username, org, properties, roles);
try {
PublisherAPISearchResult searchAPIs = apiPersistenceInstance.searchAPIsForPublisher(org, "", 0, Integer.MAX_VALUE, userCtx, null, null);
if (searchAPIs != null) {
List<PublisherAPIInfo> list = searchAPIs.getPublisherAPIInfoList();
for (PublisherAPIInfo publisherAPIInfo : list) {
API mappedAPI = APIMapper.INSTANCE.toApi(publisherAPIInfo);
apiSortedList.add(mappedAPI);
}
}
} catch (APIPersistenceException e) {
throw new APIManagementException("Error while searching the api ", e);
}
Collections.sort(apiSortedList, new APINameComparator());
return apiSortedList;
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class APIProviderImpl method deleteAPIProductRevision.
@Override
public void deleteAPIProductRevision(String apiProductId, String apiRevisionId, String organization) throws APIManagementException {
APIProductIdentifier apiProductIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiProductId);
if (apiProductIdentifier == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Product with ID: " + apiProductId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiProductId));
}
APIRevision apiRevision = apiMgtDAO.getRevisionByRevisionUUID(apiRevisionId);
if (apiRevision == null) {
throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Revision with Revision UUID: " + apiRevisionId, ExceptionCodes.from(ExceptionCodes.API_REVISION_NOT_FOUND, apiRevisionId));
}
List<APIRevisionDeployment> apiRevisionDeploymentsResponse = getAPIRevisionDeploymentList(apiRevisionId);
if (apiRevisionDeploymentsResponse.size() != 0) {
String errorMessage = "Couldn't delete API revision since API revision is currently deployed to a gateway." + "You need to undeploy the API Revision from the gateway before attempting deleting API Revision: " + apiRevision.getRevisionUUID();
throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.EXISTING_API_REVISION_DEPLOYMENT_FOUND, apiRevisionId));
}
apiProductIdentifier.setUUID(apiProductId);
try {
apiPersistenceInstance.deleteAPIRevision(new Organization(organization), apiProductIdentifier.getUUID(), apiRevision.getRevisionUUID(), apiRevision.getId());
} catch (APIPersistenceException e) {
String errorMessage = "Failed to delete registry artifacts";
throw new APIManagementException(errorMessage, ExceptionCodes.from(ExceptionCodes.ERROR_DELETING_API_REVISION, apiRevision.getApiUUID()));
}
apiMgtDAO.deleteAPIProductRevision(apiRevision);
gatewayArtifactsMgtDAO.deleteGatewayArtifact(apiRevision.getApiUUID(), apiRevision.getRevisionUUID());
if (artifactSaver != null) {
try {
artifactSaver.removeArtifact(apiRevision.getApiUUID(), apiProductIdentifier.getName(), apiProductIdentifier.getVersion(), apiRevision.getRevisionUUID(), tenantDomain);
} catch (ArtifactSynchronizerException e) {
log.error("Error while deleting Runtime artifacts from artifact Store", e);
}
}
}
Aggregations