Search in sources :

Example 96 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method apisApiIdSdksLanguageGetIncorrectSwagger.

@Test
public void apisApiIdSdksLanguageGetIncorrectSwagger() throws APIManagementException, ApiStoreSdkGenerationException, NotFoundException {
    String apiId = UUID.randomUUID().toString();
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    APIStore apiStore = Mockito.mock(APIStoreImpl.class);
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    Mockito.when(instance.getAPIConsumer(USER)).thenReturn(apiStore);
    PowerMockito.mockStatic(RestApiUtil.class);
    Request request = getRequest();
    PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
    Endpoint api1SandBoxEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("abcd").build();
    Endpoint api1ProdEndpointId = new Endpoint.Builder().id(UUID.randomUUID().toString()).applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).name("cdef").build();
    API api = TestUtil.createApi("provider1", apiId, "testapi1", "1.0.0", "Test API 1 - version 1.0.0", TestUtil.createEndpointTypeToIdMap(api1SandBoxEndpointId, api1ProdEndpointId)).build();
    Mockito.when(apiStore.getAPIbyUUID(apiId)).thenReturn(api);
    Mockito.when(apiStore.getApiSwaggerDefinition(apiId)).thenReturn(swaggerPetStoreIncorrect);
    Response response = apisApiService.apisApiIdSdksLanguageGet(apiId, correctLanguage, request);
    Assert.assertEquals(500, response.getStatus());
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) Request(org.wso2.msf4j.Request) API(org.wso2.carbon.apimgt.core.models.API) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 97 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class WorkflowExecutorFactory method createWorkflow.

/**
 * Create a DTO object related to a given workflow type.
 *
 * @param workflowType Type of the workflow.
 * @return WorkFlow instance
 */
public Workflow createWorkflow(String workflowType) throws APIMgtDAOException {
    Workflow workflow = null;
    if (WorkflowConstants.WF_TYPE_AM_APPLICATION_CREATION.equals(workflowType)) {
        workflow = new ApplicationCreationWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_DELETION.equals(workflowType)) {
        workflow = new ApplicationDeletionWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_CREATION.equals(workflowType)) {
        workflow = new SubscriptionCreationWorkflow(DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_SUBSCRIPTION_DELETION.equals(workflowType)) {
        workflow = new SubscriptionDeletionWorkflow(DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_API_STATE.equals(workflowType)) {
        workflow = new APIStateChangeWorkflow(DAOFactory.getApiDAO(), DAOFactory.getAPISubscriptionDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().geApiLifecycleManager(), APIManagerFactory.getInstance().getApiGateway(), DAOFactory.getLabelDAO());
        workflow.setWorkflowType(workflowType);
    } else if (WorkflowConstants.WF_TYPE_AM_APPLICATION_UPDATE.equals(workflowType)) {
        workflow = new ApplicationUpdateWorkflow(DAOFactory.getApplicationDAO(), DAOFactory.getWorkflowDAO(), APIManagerFactory.getInstance().getApiGateway());
        workflow.setWorkflowType(workflowType);
    } else {
        throw new APIMgtDAOException("Invalid workflow type: " + workflowType + " specified", ExceptionCodes.WORKFLOW_INVALID_WFTYPE);
    }
    return workflow;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 98 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createNewIPRangePipeline.

/**
 * Creates a new {@link Pipeline} instance
 *
 * @return created Pipeline instance
 */
public static Pipeline createNewIPRangePipeline() {
    IPCondition ipCondition = new IPCondition(PolicyConstants.IP_RANGE_TYPE);
    ipCondition.setStartingIP("10.100.0.105");
    ipCondition.setEndingIP("10.100.0.115");
    Pipeline pipeline = new Pipeline();
    RequestCountLimit requestCountLimit = new RequestCountLimit(TIME_UNIT_SECONDS, 1, 1000);
    QuotaPolicy quotaPolicy = new QuotaPolicy();
    quotaPolicy.setType(REQUEST_COUNT_TYPE);
    quotaPolicy.setLimit(requestCountLimit);
    pipeline.setQuotaPolicy(quotaPolicy);
    pipeline.setConditions(Arrays.asList(ipCondition));
    return pipeline;
}
Also used : IPCondition(org.wso2.carbon.apimgt.core.models.policy.IPCondition) RequestCountLimit(org.wso2.carbon.apimgt.core.models.policy.RequestCountLimit) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) Pipeline(org.wso2.carbon.apimgt.core.models.policy.Pipeline)

Example 99 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method updateAPIPolicy.

/**
 * Updated the given API policy
 *
 * @param apiPolicy {@link APIPolicy} instance to be updated
 * @return updated {@link APIPolicy} instance
 */
public static APIPolicy updateAPIPolicy(APIPolicy apiPolicy) {
    apiPolicy.setDisplayName(UPDATED_SAMPLE_API_POLICY);
    apiPolicy.setDescription(UPDATED_SAMPLE_API_POLICY_DESCRIPTION);
    QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
    defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
    BandwidthLimit bandwidthLimit = new BandwidthLimit(TIME_UNIT_SECONDS, 1, 1000, "KB");
    defaultQuotaPolicy.setLimit(bandwidthLimit);
    apiPolicy.setDefaultQuotaPolicy(defaultQuotaPolicy);
    apiPolicy.setPipelines(createDefaultPipelines());
    apiPolicy.getPipelines().add(createNewIPRangePipeline());
    return apiPolicy;
}
Also used : QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.core.models.policy.BandwidthLimit)

Example 100 with Instance

use of org.wso2.carbon.bpel.core.ode.integration.jmx.Instance in project carbon-apimgt by wso2.

the class EndpointsApiServiceImplTestCase method endpointsEndpointIdGatewayConfigGetTest.

@Test
public void endpointsEndpointIdGatewayConfigGetTest() throws Exception {
    APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
    PowerMockito.mockStatic(APIManagerFactory.class);
    PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
    Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
    EndpointsApiServiceImpl endpointsApiService = new EndpointsApiServiceImpl();
    String endpointId = UUID.randomUUID().toString();
    String endpointGatewayConfig = "package deployment.org.wso2.apim;\n" + "import ballerina.net.http;\n" + "\n" + "@http:BasePath(\"/aaa1\")\n" + "service aaa1_1489666767745 {\n" + "\n" + "    @http:GET\n" + "    @http:Path(\"/*\")\n" + "    resource get_star_ (message m) {\n" + "        http:ClientConnector productionEndpoint = create http:ClientConnector(getUrlFromKey" + "(\"aaa1_1.0.0__ep\"));\n   http:ClientConnector sandboxEndpoint = create http:ClientConnector" + "(getUrlFromKey(\"aaa1_1.0.0__ep\"));\n message response;\n string endpointType;\n string " + "productionType;\n \n \n      endpointType = \"production\";\n productionType = \"production\";\n" + "\n      if (endpointType == productionType) {\n" + "            response = http:ClientConnector.execute(productionEndpoint, \"get\", \"\", m);\n" + "        } else {\n" + "            response = http:ClientConnector.execute(sandboxEndpoint, \"get\", \"\", m);\n" + "        }\n" + "\n" + "        reply response;\n" + "    }\n" + "}";
    Mockito.when(apiMgtAdminService.getEndpointGatewayConfig(endpointId)).thenReturn(endpointGatewayConfig);
    Response response = endpointsApiService.endpointsEndpointIdGatewayConfigGet(endpointId, null, getRequest());
    Assert.assertEquals(response.getStatus(), 200);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ArrayList (java.util.ArrayList)28 Test (org.junit.Test)23 Response (javax.ws.rs.core.Response)22 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)21 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)20 HashMap (java.util.HashMap)15 Path (javax.ws.rs.Path)15 RuntimeService (org.activiti.engine.RuntimeService)15 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)15 InstanceManagementException (org.wso2.carbon.bpel.skeleton.ode.integration.mgt.services.InstanceManagementException)14 Produces (javax.ws.rs.Produces)13 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)13 IOException (java.io.IOException)12 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)12 GET (javax.ws.rs.GET)11 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8