Search in sources :

Example 16 with GovernanceException

use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.

the class APIMapperTestCase method testPublisherAPIInfoToAPI.

@Test
public void testPublisherAPIInfoToAPI() throws GovernanceException, APIManagementException {
    PublisherAPIInfo infoapi = new PublisherAPIInfo();
    infoapi.setApiName("TestAPI");
    infoapi.setVersion("1.0");
    infoapi.setType("API");
    infoapi.setStatus("PUBLISHED");
    infoapi.setProviderName("admin");
    infoapi.setDescription("Test API description");
    API mappedAPI = APIMapper.INSTANCE.toApi(infoapi);
    Assert.assertEquals("Mapped api name does not match", mappedAPI.getId().getName(), infoapi.getApiName());
    Assert.assertEquals("Mapped api version does not match", mappedAPI.getId().getVersion(), infoapi.getVersion());
    Assert.assertEquals("Mapped api state does not match", mappedAPI.getStatus(), infoapi.getStatus());
    Assert.assertEquals("Mapped api description does not match", mappedAPI.getDescription(), infoapi.getDescription());
}
Also used : PublisherAPIInfo(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIInfo) API(org.wso2.carbon.apimgt.api.model.API) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with GovernanceException

use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.

the class APIMapperTestCase method testDevPortalAPIInfoToAPI.

@Test
public void testDevPortalAPIInfoToAPI() throws GovernanceException, APIManagementException {
    DevPortalAPIInfo infoapi = new DevPortalAPIInfo();
    infoapi.setApiName("TestAPI");
    infoapi.setVersion("1.0");
    infoapi.setType("API");
    infoapi.setStatus("PUBLISHED");
    infoapi.setProviderName("admin");
    infoapi.setDescription("Test API description");
    API mappedAPI = APIMapper.INSTANCE.toApi(infoapi);
    Assert.assertEquals("Mapped api name does not match", mappedAPI.getId().getName(), infoapi.getApiName());
    Assert.assertEquals("Mapped api version does not match", mappedAPI.getId().getVersion(), infoapi.getVersion());
    Assert.assertEquals("Mapped api state does not match", mappedAPI.getStatus(), infoapi.getStatus());
    Assert.assertEquals("Mapped api description does not match", mappedAPI.getDescription(), infoapi.getDescription());
}
Also used : DevPortalAPIInfo(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPIInfo) API(org.wso2.carbon.apimgt.api.model.API) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 18 with GovernanceException

use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.

the class APIMapperTestCase method testAPItoPublisherApiAndBack.

@Test
public void testAPItoPublisherApiAndBack() throws GovernanceException, APIManagementException {
    PublisherAPI pubAPI = APIMapper.INSTANCE.toPublisherApi(api);
    Assert.assertEquals("API name does not match", api.getId().getName(), pubAPI.getApiName());
    Assert.assertEquals("API uuid does not match", api.getUuid(), pubAPI.getId());
    Assert.assertTrue("Mapped api does not have status", pubAPI.toString().contains(api.getStatus()));
    API mappedAPI = APIMapper.INSTANCE.toApi(pubAPI);
    Assert.assertEquals("Mapped api name does not match", mappedAPI.getId().getName(), api.getId().getName());
}
Also used : PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API) DevPortalAPI(org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 19 with GovernanceException

use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.

the class APIMapperTestCase method testAPIProductToPublisherAPIProductAndBack.

@Test
public void testAPIProductToPublisherAPIProductAndBack() throws GovernanceException, APIManagementException {
    PublisherAPIProduct pubAPI = APIProductMapper.INSTANCE.toPublisherApiProduct(product);
    Assert.assertEquals("API product uuid does not match", product.getUuid(), pubAPI.getId());
    Assert.assertEquals("API product type does not match", product.getType(), pubAPI.getType());
    APIProduct mappedProduct = APIProductMapper.INSTANCE.toApiProduct(pubAPI);
    Assert.assertEquals("Mapped product uuid does not match", mappedProduct.getUuid(), product.getUuid());
}
Also used : APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) PublisherAPIProduct(org.wso2.carbon.apimgt.persistence.dto.PublisherAPIProduct) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 20 with GovernanceException

use of org.wso2.carbon.governance.api.exception.GovernanceException in project carbon-apimgt by wso2.

the class APIProviderImplTest method testAddAPINameWithIllegalCharacters.

@Test
public void testAddAPINameWithIllegalCharacters() throws APIManagementException, GovernanceException {
    APIIdentifier apiId = new APIIdentifier("admin", "API2&", "1.0.2");
    API api = new API(apiId);
    api.setContext("/test");
    api.setStatus(APIConstants.CREATED);
    APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
    Mockito.when(artifactManager.newGovernanceArtifact(any(QName.class))).thenReturn(artifact);
    Mockito.when(APIUtil.createAPIArtifactContent(artifact, api)).thenReturn(artifact);
    try {
        apiProvider.addAPI(api);
        Assert.fail("Exception was expected, but wasn't thrown");
    } catch (APIManagementException e) {
        Assert.assertTrue(e.getMessage().contains("API Name contains one or more illegal characters"));
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) QName(javax.xml.namespace.QName) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

GovernanceException (org.wso2.carbon.governance.api.exception.GovernanceException)42 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)32 GenericArtifact (org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact)29 API (org.wso2.carbon.apimgt.api.model.API)26 Test (org.junit.Test)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)18 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)17 ArrayList (java.util.ArrayList)15 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)15 GenericArtifactManager (org.wso2.carbon.governance.api.generic.GenericArtifactManager)14 Tier (org.wso2.carbon.apimgt.api.model.Tier)13 HashSet (java.util.HashSet)11 DevPortalAPI (org.wso2.carbon.apimgt.persistence.dto.DevPortalAPI)10 UserStoreException (org.wso2.carbon.user.api.UserStoreException)10 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)9 Endpoint (org.wso2.carbon.governance.api.endpoints.dataobjects.Endpoint)9 Resource (org.wso2.carbon.registry.core.Resource)9 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)9 LinkedHashSet (java.util.LinkedHashSet)8