Search in sources :

Example 16 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method getLabelsByType.

@Test(description = "get  labels by STORE type")
public void getLabelsByType() throws Exception {
    LabelDAO labelDao = Mockito.mock(LabelDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(labelDao);
    Mockito.when(labelDao.getLabelsByType("GATEWAY")).thenReturn(new ArrayList<Label>());
    apiPublisher.getLabelsByType("GATEWAY");
    Mockito.verify(labelDao, Mockito.times(1)).getLabelsByType("GATEWAY");
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 17 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateDedicatedGatewayWhenAPIIsInDeprecatedState.

@Test(description = "Update dedicated gateway when API is in Deprecated state", expectedExceptions = APIManagementException.class)
public void testUpdateDedicatedGatewayWhenAPIIsInDeprecatedState() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.DEPRECATED.getStatus()).build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
    Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, labelDAO, gatewaySourceGenerator);
    DedicatedGateway dedicatedGateway = SampleTestObjectCreator.createDedicatedGateway(uuid, true, api.getCreatedBy());
    apiPublisher.updateDedicatedGateway(dedicatedGateway);
}
Also used : IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) API(org.wso2.carbon.apimgt.core.models.API) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) Test(org.testng.annotations.Test)

Example 18 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testUpdateDedicatedGatewayWhenDedicatedGatewayIsDisabled.

@Test(description = "Update dedicated gateway when dedicated gateway is disabled")
public void testUpdateDedicatedGatewayWhenDedicatedGatewayIsDisabled() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    IdentityProvider identityProvider = Mockito.mock(IdentityProvider.class);
    API api = SampleTestObjectCreator.createDefaultAPI().build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.DEVELOPER_ROLE_ID)).thenReturn(DEVELOPER_ROLE);
    Mockito.when(identityProvider.getRoleName(SampleTestObjectCreator.ADMIN_ROLE_ID)).thenReturn(ADMIN_ROLE);
    Mockito.when(apiDAO.getApiSwaggerDefinition(api.getId())).thenReturn(SampleTestObjectCreator.apiDefinition);
    String autoGenLabelName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + uuid;
    APIPublisherImpl apiPublisher = getApiPublisherImpl(identityProvider, apiDAO, labelDAO, gatewaySourceGenerator);
    DedicatedGateway dedicatedGateway = SampleTestObjectCreator.createDedicatedGateway(uuid, false, api.getCreatedBy());
    apiPublisher.updateDedicatedGateway(dedicatedGateway);
    List<String> labelSet = new ArrayList<>();
    labelSet.add(autoGenLabelName);
    Mockito.verify(apiDAO, Mockito.times(0)).updateDedicatedGateway(dedicatedGateway, labelSet);
}
Also used : ArrayList(java.util.ArrayList) IdentityProvider(org.wso2.carbon.apimgt.core.api.IdentityProvider) API(org.wso2.carbon.apimgt.core.models.API) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) Test(org.testng.annotations.Test)

Example 19 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testAddUpdateAPIFromWSDLFile.

@Test(description = "Test adding an API from WSDL file")
public void testAddUpdateAPIFromWSDLFile() throws APIManagementException, LifecycleException, IOException {
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(SampleTestObjectCreator.getMockEndpointMap());
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    APIGateway gateway = Mockito.mock(APIGateway.class);
    APILifecycleManager apiLifecycleManager = getDefaultMockedAPILifecycleManager();
    PolicyDAO policyDAO = getDefaultMockedPolicyDAO();
    LabelDAO labelDao = Mockito.mock(LabelDAO.class);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO, apiLifecycleManager, gatewaySourceGenerator, gateway, policyDAO, labelDao);
    String endpointId = apiBuilder.getEndpoint().get("production").getId();
    Endpoint endpoint = new Endpoint.Builder().id(endpointId).name("testEndpoint").build();
    Mockito.when(apiDAO.getEndpoint(endpointId)).thenReturn(endpoint);
    apiPublisher.addAPIFromWSDLFile(apiBuilder, SampleTestObjectCreator.createDefaultWSDL11ContentInputStream(), true);
    Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
    Mockito.verify(apiDAO, Mockito.times(1)).addOrUpdateWSDL(apiBuilder.getId(), IOUtils.toByteArray(SampleTestObjectCreator.createDefaultWSDL11ContentInputStream()), USER);
    Mockito.verify(apiLifecycleManager, Mockito.times(1)).addLifecycle(APIMgtConstants.API_LIFECYCLE, USER);
    apiPublisher.updateAPIWSDL(apiBuilder.getId(), SampleTestObjectCreator.createAlternativeWSDL11ContentInputStream());
    Mockito.verify(apiDAO, Mockito.times(1)).addOrUpdateWSDL(apiBuilder.getId(), IOUtils.toByteArray(SampleTestObjectCreator.createAlternativeWSDL11ContentInputStream()), USER);
}
Also used : APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) Test(org.testng.annotations.Test)

Example 20 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.

the class APIPublisherImplTestCase method testAddApi.

@Test(description = "Test add api with production endpoint")
public void testAddApi() throws APIManagementException, LifecycleException {
    /**
     * this test method verify the API Add with correct API object get invoked correctly
     */
    API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().id("").endpoint(SampleTestObjectCreator.getMockEndpointMap());
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    LabelDAO labelDao = Mockito.mock(LabelDAO.class);
    GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
    APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
    Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
    APIGateway gateway = Mockito.mock(APIGateway.class);
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, APIMgtConstants.DEFAULT_API_POLICY)).thenReturn(new APIPolicy(APIMgtConstants.DEFAULT_API_POLICY));
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, GOLD_TIER)).thenReturn(new SubscriptionPolicy(GOLD_TIER));
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, SILVER_TIER)).thenReturn(new SubscriptionPolicy(SILVER_TIER));
    Mockito.when(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, BRONZE_TIER)).thenReturn(new SubscriptionPolicy(BRONZE_TIER));
    APIPublisherImpl apiPublisher = getApiPublisherImpl(null, apiDAO, null, null, policyDAO, apiLifecycleManager, labelDao, null, null, null, gatewaySourceGenerator, gateway);
    String endpointId = apiBuilder.getEndpoint().get("production").getId();
    Endpoint endpoint = new Endpoint.Builder().id(endpointId).name("testEndpoint").build();
    Mockito.when(apiDAO.getEndpoint(endpointId)).thenReturn(endpoint);
    apiPublisher.addAPI(apiBuilder);
    Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
    Mockito.verify(apiLifecycleManager, Mockito.times(1)).addLifecycle(APIMgtConstants.API_LIFECYCLE, USER);
    // Error path
    // When an APIMgtDAOException is being thrown when the API is created
    Mockito.doThrow(APIMgtDAOException.class).when(apiDAO).addAPI(apiBuilder.build());
    try {
        apiPublisher.addAPI(apiBuilder);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while creating the API - " + apiBuilder.getName());
    }
    // Error path
    // When an GatewayException is being thrown when an error occurred while adding API to the Gateway
    Mockito.doThrow(GatewayException.class).when(gateway).addAPI(apiBuilder.build());
    try {
        apiPublisher.addAPI(apiBuilder);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error occurred while adding API - " + apiBuilder.getName() + " to gateway");
    }
    // Error path
    // When an APITemplateException is being thrown when generating API configuration for API
    Mockito.when(gatewaySourceGenerator.getConfigStringFromTemplate(Mockito.any())).thenThrow(APITemplateException.class);
    try {
        apiPublisher.addAPI(apiBuilder);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Error generating API configuration for API " + apiBuilder.getName());
    }
}
Also used : APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) LifecycleState(org.wso2.carbon.lcm.core.impl.LifecycleState) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) GatewaySourceGenerator(org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator) APILifecycleManager(org.wso2.carbon.apimgt.core.api.APILifecycleManager) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) API(org.wso2.carbon.apimgt.core.models.API) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Aggregations

LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)71 Test (org.testng.annotations.Test)70 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)45 API (org.wso2.carbon.apimgt.core.models.API)44 ArrayList (java.util.ArrayList)33 Label (org.wso2.carbon.apimgt.core.models.Label)33 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)28 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)26 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)26 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)26 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)17 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)16 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)15 HashMap (java.util.HashMap)14 DedicatedGateway (org.wso2.carbon.apimgt.core.models.DedicatedGateway)14 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)14 BeforeTest (org.testng.annotations.BeforeTest)13 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)11 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)11 WorkflowExtensionsConfigBuilder (org.wso2.carbon.apimgt.core.workflow.WorkflowExtensionsConfigBuilder)11