use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class RegistryPersistenceImplTestCase method testUpdateAPI.
@Test
public void testUpdateAPI() throws APIPersistenceException, RegistryException, APIManagementException {
PublisherAPI publisherAPI = new PublisherAPI();
publisherAPI.setDescription("Modified description");
API api = APIMapper.INSTANCE.toApi(publisherAPI);
Registry registry = Mockito.mock(UserRegistry.class);
Resource resource = new ResourceImpl();
Mockito.when(registry.get(anyString())).thenReturn(resource);
Tag[] tags = new Tag[0];
Mockito.when(registry.getTags(anyString())).thenReturn(tags);
GenericArtifact existArtifact = PersistenceHelper.getSampleAPIArtifact();
String apiUUID = existArtifact.getId();
PowerMockito.mockStatic(RegistryPersistenceUtil.class);
GenericArtifactManager manager = Mockito.mock(GenericArtifactManager.class);
PowerMockito.when(RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY)).thenReturn(manager);
Mockito.when(manager.getGenericArtifact(apiUUID)).thenReturn(existArtifact);
Mockito.doNothing().when(manager).updateGenericArtifact(existArtifact);
PowerMockito.when(RegistryPersistenceUtil.getArtifactManager(registry, APIConstants.API_KEY)).thenReturn(manager);
GenericArtifact updatedArtifact = PersistenceHelper.getSampleAPIArtifact();
updatedArtifact.setAttribute(APIConstants.API_OVERVIEW_DESCRIPTION, api.getDescription());
PowerMockito.when(RegistryPersistenceUtil.createAPIArtifactContent(any(GenericArtifact.class), any(API.class))).thenReturn(updatedArtifact);
Organization org = new Organization(SUPER_TENANT_DOMAIN);
APIPersistence apiPersistenceInstance = new RegistryPersistenceImplWrapper(registry, existArtifact);
PublisherAPI updatedAPI = apiPersistenceInstance.updateAPI(org, publisherAPI);
Assert.assertEquals("Updated API description does not match", "Modified description", updatedAPI.getDescription());
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class RegistryPersistenceUtilTestCase method testcreateAPIArtifactContent.
@Test
public void testcreateAPIArtifactContent() throws APIPersistenceException, APIManagementException, RegistryException {
API api = new API(new APIIdentifier("pubuser", "TestAPI", "1.0"));
Set<Tier> availableTiers = new HashSet<Tier>();
availableTiers.add(new Tier("Unlimited"));
availableTiers.add(new Tier("Gold"));
api.setAvailableTiers(availableTiers);
Set<URITemplate> uriTemplates = new HashSet<URITemplate>();
URITemplate template = new URITemplate();
template.setHTTPVerb("GET");
template.setUriTemplate("/test");
template.setAuthType("None");
uriTemplates.add(template);
api.setUriTemplates(uriTemplates);
List<APICategory> categories = new ArrayList<APICategory>();
APICategory category = new APICategory();
category.setName("testcategory");
categories.add(category);
api.setApiCategories(categories);
List<Label> gatewayLabels = new ArrayList<Label>();
Label label = new Label();
label.setName("TestLabel");
gatewayLabels.add(label);
GenericArtifact genericArtifact = new GenericArtifactImpl(new QName("", "TestAPI", ""), "application/vnd.wso2-api+xml");
genericArtifact.setAttribute("URITemplate", "/test");
GenericArtifact retArtifact = RegistryPersistenceUtil.createAPIArtifactContent(genericArtifact, api);
Assert.assertEquals("API name does not match", api.getId().getApiName(), retArtifact.getAttribute("overview_name"));
Assert.assertEquals("API version does not match", api.getId().getVersion(), retArtifact.getAttribute("overview_version"));
Assert.assertEquals("API provider does not match", api.getId().getProviderName(), retArtifact.getAttribute("overview_provider"));
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class RegistryPersistenceUtilTestCase method testcreateAPIProductArtifactContent.
@Test
public void testcreateAPIProductArtifactContent() throws APIPersistenceException, APIManagementException, RegistryException {
APIProduct product = new APIProduct(new APIProductIdentifier("pubuser", "TestAPIProd", "1.0.0"));
GenericArtifact genericArtifact = new GenericArtifactImpl(new QName("", "TestAPIProd", ""), "application/vnd.wso2-api+xml");
List<APICategory> categories = new ArrayList<APICategory>();
APICategory category = new APICategory();
category.setName("testcategory");
categories.add(category);
product.setApiCategories(categories);
Set<Tier> availableTiers = new HashSet<Tier>();
availableTiers.add(new Tier("Unlimited"));
availableTiers.add(new Tier("Gold"));
product.setAvailableTiers(availableTiers);
GenericArtifact retArtifact = RegistryPersistenceUtil.createAPIProductArtifactContent(genericArtifact, product);
Assert.assertEquals("API name does not match", product.getId().getName(), retArtifact.getAttribute("overview_name"));
Assert.assertEquals("API version does not match", product.getId().getVersion(), retArtifact.getAttribute("overview_version"));
Assert.assertEquals("API provider does not match", product.getId().getProviderName(), retArtifact.getAttribute("overview_provider"));
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class RegistrySearchUtilTestCase method testAdminUserQueryInDevPortal.
@Test
public void testAdminUserQueryInDevPortal() throws APIPersistenceException {
// Normal dev portal api listing
String inputQuery = "";
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("isAdmin", true);
UserContext ctx = new UserContext("admin", organization, properties, new String[] { "admin" });
String searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
String expected = "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 = "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 = "provider=*pubuser*&lcState=(PUBLISHED OR PROTOTYPED)";
searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
Assert.assertEquals("Generated query mismatched for provider search. ", expected, searchQuery);
}
use of org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException in project carbon-apimgt by wso2.
the class RegistrySearchUtilTestCase method testDevPortalUserQueryInDevPortal.
@Test
public void testDevPortalUserQueryInDevPortal() throws APIPersistenceException {
// Normal dev portal api listing
String inputQuery = "";
UserContext ctx = new UserContext("devUser", organization, null, devPortalRoles);
String searchQuery = RegistrySearchUtil.getDevPortalSearchQuery(inputQuery, ctx, false, false);
String expected = "store_view_roles=(null OR internal\\/subscriber OR internal\\/everyone)&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 internal\\/subscriber OR internal\\/everyone)&" + "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 internal\\/subscriber OR internal\\/everyone)&" + "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 internal\\/subscriber OR internal\\/everyone)" + "&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);
}
Aggregations