Search in sources :

Example 16 with CompositeAPI

use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.

the class CompositeAPIMappingUtilTestCase method testToCompositeAPIDTOAndViceVersa.

@Test
public void testToCompositeAPIDTOAndViceVersa() {
    List<String> labels = new ArrayList<>();
    labels.add("label1");
    // Test compositeAPI to CompositeAPIDTO
    CompositeAPI compositeAPI = SampleTestObjectCreator.createCompositeAPIModelBuilder().labels(labels).build();
    CompositeAPIDTO compositeAPIDTO = CompositeAPIMappingUtil.toCompositeAPIDTO(compositeAPI);
    assertEquals(compositeAPI.getId(), compositeAPIDTO.getId());
    assertEquals(compositeAPI.getName(), compositeAPIDTO.getName());
    assertEquals(compositeAPI.getProvider(), compositeAPIDTO.getProvider());
    assertEquals(compositeAPI.getVersion(), compositeAPIDTO.getVersion());
    assertEquals(compositeAPI.getContext(), compositeAPIDTO.getContext());
    assertEquals(compositeAPI.getDescription(), compositeAPIDTO.getDescription());
    assertEquals(compositeAPI.getLabels().size(), compositeAPIDTO.getLabels().size());
    assertEquals(compositeAPI.getApplicationId(), compositeAPIDTO.getApplicationId());
    // Test CompositeAPIDTO to compositeAPI
    CompositeAPI compositeAPIGenerated = CompositeAPIMappingUtil.toAPI(compositeAPIDTO).build();
    assertEquals(compositeAPIGenerated.getId(), compositeAPIDTO.getId());
    assertEquals(compositeAPIGenerated.getName(), compositeAPIDTO.getName());
    assertEquals(compositeAPIGenerated.getProvider(), compositeAPIDTO.getProvider());
    assertEquals(compositeAPIGenerated.getVersion(), compositeAPIDTO.getVersion());
    assertEquals(compositeAPIGenerated.getContext(), compositeAPIDTO.getContext());
    assertEquals(compositeAPIGenerated.getDescription(), compositeAPIDTO.getDescription());
    assertEquals(compositeAPIGenerated.getLabels().size(), compositeAPIDTO.getLabels().size());
    assertEquals(compositeAPIGenerated.getApplicationId(), compositeAPIDTO.getApplicationId());
}
Also used : ArrayList(java.util.ArrayList) CompositeAPIDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIDTO) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) Test(org.testng.annotations.Test)

Example 17 with CompositeAPI

use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.

the class CompositeAPIMappingUtilTestCase method testToCompositeAPIListDTO.

@Test
public void testToCompositeAPIListDTO() {
    List<CompositeAPI> apisResult = new ArrayList<>();
    CompositeAPI comp1 = SampleTestObjectCreator.createCompositeAPIModelBuilder().name("newComp1").build();
    CompositeAPI comp2 = SampleTestObjectCreator.createCompositeAPIModelBuilder().name("newComp2").build();
    apisResult.add(comp1);
    apisResult.add(comp2);
    CompositeAPIListDTO compositeAPIListDTO = CompositeAPIMappingUtil.toCompositeAPIListDTO(apisResult);
    assertEquals(compositeAPIListDTO.getCount(), (Integer) apisResult.size());
    assertEquals(comp1.getId(), compositeAPIListDTO.getList().get(0).getId());
    assertEquals(comp1.getName(), compositeAPIListDTO.getList().get(0).getName());
    assertEquals(comp1.getProvider(), compositeAPIListDTO.getList().get(0).getProvider());
    assertEquals(comp1.getVersion(), compositeAPIListDTO.getList().get(0).getVersion());
    assertEquals(comp1.getContext(), compositeAPIListDTO.getList().get(0).getContext());
    assertEquals(comp1.getDescription(), compositeAPIListDTO.getList().get(0).getDescription());
    assertEquals(comp1.getApplicationId(), compositeAPIListDTO.getList().get(0).getApplicationId());
    assertEquals(comp2.getId(), compositeAPIListDTO.getList().get(1).getId());
    assertEquals(comp2.getName(), compositeAPIListDTO.getList().get(1).getName());
    assertEquals(comp2.getProvider(), compositeAPIListDTO.getList().get(1).getProvider());
    assertEquals(comp2.getVersion(), compositeAPIListDTO.getList().get(1).getVersion());
    assertEquals(comp2.getContext(), compositeAPIListDTO.getList().get(1).getContext());
    assertEquals(comp2.getDescription(), compositeAPIListDTO.getList().get(1).getDescription());
    assertEquals(comp2.getApplicationId(), compositeAPIListDTO.getList().get(1).getApplicationId());
}
Also used : ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) CompositeAPIListDTO(org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIListDTO) Test(org.testng.annotations.Test)

Example 18 with CompositeAPI

use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.

the class ApiDAOImpl method getCompositeAPI.

@Override
public CompositeAPI getCompositeAPI(String apiID) throws APIMgtDAOException {
    final String query = "SELECT UUID, PROVIDER, NAME, CONTEXT, VERSION, DESCRIPTION, CREATED_BY, CREATED_TIME, " + "LAST_UPDATED_TIME, COPIED_FROM_API, UPDATED_BY, LC_WORKFLOW_STATUS " + "FROM AM_API WHERE UUID = ? AND API_TYPE_ID = (SELECT TYPE_ID FROM AM_API_TYPES WHERE TYPE_NAME = ?)";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setString(1, apiID);
        statement.setString(2, ApiType.COMPOSITE.toString());
        CompositeAPI api = getCompositeAPIFromResultSet(connection, statement);
        if (api == null) {
            throw new APIMgtDAOException("Composite API: " + apiID + " does not exist", ExceptionCodes.API_NOT_FOUND);
        }
        return api;
    } catch (SQLException | IOException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting Composite API: " + apiID, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) PreparedStatement(java.sql.PreparedStatement) IOException(java.io.IOException)

Example 19 with CompositeAPI

use of org.wso2.carbon.apimgt.core.models.CompositeAPI 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 20 with CompositeAPI

use of org.wso2.carbon.apimgt.core.models.CompositeAPI in project carbon-apimgt by wso2.

the class ApiDAOImpl method getCompositeAPISummary.

@Override
public CompositeAPI getCompositeAPISummary(String apiID) throws APIMgtDAOException {
    final String query = COMPOSITE_API_SUMMARY_SELECT + " WHERE UUID = ? AND API_TYPE_ID = " + "(SELECT TYPE_ID FROM AM_API_TYPES WHERE TYPE_NAME = ?)";
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        statement.setString(1, apiID);
        statement.setString(2, ApiType.COMPOSITE.toString());
        List<CompositeAPI> apiResults = getCompositeAPISummaryList(connection, statement);
        if (apiResults.isEmpty()) {
            throw new APIMgtDAOException("API with ID " + apiID + " does not exist", ExceptionCodes.API_NOT_FOUND);
        }
        // there should be only 1 result from the database
        return apiResults.get(0);
    } catch (SQLException e) {
        throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + "getting Composite API: " + apiID, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) PreparedStatement(java.sql.PreparedStatement)

Aggregations

CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)19 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)9 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)7 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)7 Test (org.testng.annotations.Test)6 ArrayList (java.util.ArrayList)5 Connection (java.sql.Connection)4 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 BeforeTest (org.testng.annotations.BeforeTest)3 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)3 CompositeAPIDTO (org.wso2.carbon.apimgt.rest.api.store.dto.CompositeAPIDTO)3 Request (org.wso2.msf4j.Request)3 IOException (java.io.IOException)2 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)2