Search in sources :

Example 26 with APIList

use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.

the class MappingUtil method toAPIInfo.

/**
 * Converts {@link API} List to an {@link APIInfoDTO} List.
 *
 * @param apiList
 * @return
 */
private static List<APIInfoDTO> toAPIInfo(List<API> apiList) {
    List<APIInfoDTO> apiInfoList = new ArrayList<APIInfoDTO>();
    for (API api : apiList) {
        APIInfoDTO apiInfo = new APIInfoDTO();
        apiInfo.setId(api.getId());
        apiInfo.setContext(api.getContext());
        apiInfo.setName(api.getName());
        apiInfo.setLifeCycleStatus(api.getLifeCycleStatus());
        apiInfo.setVersion(api.getVersion());
        apiInfo.setSecurityScheme(api.getSecurityScheme());
        for (String threatProtectionPolicyId : api.getThreatProtectionPolicies()) {
            apiInfo.addThreatProtectionPoliciesItem(threatProtectionPolicyId);
        }
        apiInfoList.add(apiInfo);
    }
    return apiInfoList;
}
Also used : ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.core.models.API) APIInfoDTO(org.wso2.carbon.apimgt.rest.api.core.dto.APIInfoDTO)

Example 27 with APIList

use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.

the class ApisApiServiceImplTestCase method apisGetTestCase.

@Test
public void apisGetTestCase() throws Exception {
    String labels = "ZONE_ONE,ZONE_TWO";
    String[] gatewayLabels = labels.split(",");
    List<String> labelList = new ArrayList<String>(Arrays.asList(gatewayLabels));
    APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
    PowerMockito.mockStatic(RestApiUtil.class);
    PowerMockito.when(RestApiUtil.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
    List<API> apiList = new ArrayList<>();
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    Mockito.when(apiMgtAdminService.getAPIsByStatus(labelList, "Published")).thenReturn(apiList);
    ApisApiServiceImpl apisApiService = new ApisApiServiceImpl();
    Response response = apisApiService.apisGet(labels, "Published", getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    Integer count = ((APIListDTO) response.getEntity()).getCount();
    Assert.assertEquals(count.intValue(), 3);
}
Also used : Response(javax.ws.rs.core.Response) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.APIListDTO) API(org.wso2.carbon.apimgt.core.models.API) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 28 with APIList

use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.

the class MappingUtilTestCase method toAPIListDTOTest.

@Test
public void toAPIListDTOTest() {
    List<API> apiList = new ArrayList<>();
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    apiList.add(SampleTestObjectCreator.createUniqueAPI().build());
    APIListDTO apDTOList = MappingUtil.toAPIListDTO(apiList);
    Assert.assertEquals(apiList.size(), apDTOList.getList().size());
}
Also used : ArrayList(java.util.ArrayList) APIListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.APIListDTO) API(org.wso2.carbon.apimgt.core.models.API) Test(org.testng.annotations.Test)

Example 29 with APIList

use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.

the class ApiDAOImpl method getCompositeAPISummaryList.

private List<CompositeAPI> getCompositeAPISummaryList(Connection connection, PreparedStatement statement) throws SQLException, APIMgtDAOException {
    List<CompositeAPI> apiList = new ArrayList<>();
    try (ResultSet rs = statement.executeQuery()) {
        while (rs.next()) {
            String apiPrimaryKey = rs.getString("UUID");
            CompositeAPI apiSummary = new CompositeAPI.Builder().id(apiPrimaryKey).provider(rs.getString("PROVIDER")).name(rs.getString("NAME")).version(rs.getString("VERSION")).context(rs.getString("CONTEXT")).description(rs.getString("DESCRIPTION")).applicationId(getCompositeAPIApplicationId(connection, apiPrimaryKey)).workflowStatus(rs.getString("LC_WORKFLOW_STATUS")).threatProtectionPolicies(getThreatProtectionPolicies(connection, apiPrimaryKey)).build();
            apiList.add(apiSummary);
        }
    }
    return apiList;
}
Also used : ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI)

Example 30 with APIList

use of org.wso2.carbon.apimgt.keymgt.model.entity.APIList in project carbon-apimgt by wso2.

the class SampleTestObjectCreator method createMockAPIList.

public static List<API> createMockAPIList() {
    List<API> apiList = new ArrayList<>();
    API api1 = createDefaultAPI().build();
    API api2 = createAlternativeAPI().build();
    apiList.add(api1);
    apiList.add(api2);
    return apiList;
}
Also used : ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API)

Aggregations

ArrayList (java.util.ArrayList)33 API (org.wso2.carbon.apimgt.core.models.API)21 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)15 API (org.wso2.carbon.apimgt.api.model.API)14 Test (org.testng.annotations.Test)12 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)12 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)12 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)10 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)9 JSONObject (org.json.simple.JSONObject)9 APIComparator (org.wso2.carbon.apimgt.core.util.APIComparator)8 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)7 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)6 TreeSet (java.util.TreeSet)5 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)5 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)5 IOException (java.io.IOException)4 ResultSet (java.sql.ResultSet)4 List (java.util.List)4