Search in sources :

Example 1 with DedicatedGateway

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

the class ApiDAOImpl method getDedicatedGateway.

/**
 * @see ApiDAO#getDedicatedGateway(String)
 */
@Override
public DedicatedGateway getDedicatedGateway(String apiId) throws APIMgtDAOException {
    final String query = "SELECT HAS_OWN_GATEWAY FROM AM_API WHERE UUID = ?";
    DedicatedGateway dedicatedGateway;
    try (Connection connection = DAOUtil.getConnection();
        PreparedStatement statement = connection.prepareStatement(query)) {
        try {
            statement.setString(1, apiId);
            statement.execute();
            try (ResultSet rs = statement.getResultSet()) {
                if (rs.next()) {
                    dedicatedGateway = new DedicatedGateway();
                    dedicatedGateway.setEnabled(rs.getBoolean(ContainerBasedGatewayConstants.IS_DEDICATED_GATEWAY_ENABLED));
                    return dedicatedGateway;
                } else {
                    throw new APIMgtDAOException("Couldn't Find Dedicated Gateway details ", ExceptionCodes.DEDICATED_GATEWAY_DETAILS_NOT_FOUND);
                }
            }
        } catch (SQLException e) {
            String errorMessage = "Error while retrieving dedicated gateway details of API : " + apiId;
            throw new APIMgtDAOException(errorMessage, e);
        }
    } catch (SQLException e) {
        String message = "Error while creating database connection/prepared-statement";
        throw new APIMgtDAOException(message, e);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway)

Example 2 with DedicatedGateway

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

the class SampleTestObjectCreator method createDedicatedGateway.

public static DedicatedGateway createDedicatedGateway(String apiId, boolean enabled, String updatedBy) {
    DedicatedGateway dedicatedGateway = new DedicatedGateway();
    dedicatedGateway.setEnabled(enabled);
    dedicatedGateway.setApiId(apiId);
    dedicatedGateway.setUpdatedBy(updatedBy);
    return dedicatedGateway;
}
Also used : DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway)

Example 3 with DedicatedGateway

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

the class ApiDAOImplIT method testUpdateGetDedicatedGateway.

@Test
public void testUpdateGetDedicatedGateway() throws Exception {
    ApiDAO apiDAO = DAOFactory.getApiDAO();
    API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI().apiDefinition(SampleTestObjectCreator.apiDefinition);
    API api = builder.build();
    testAddGetEndpoint();
    apiDAO.addAPI(api);
    String autoGeneratedLabelName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + api.getId();
    List<Label> labelList = new ArrayList<>();
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    Label autoGenLabel = new Label.Builder().id(UUID.randomUUID().toString()).name(autoGeneratedLabelName).accessUrls(null).build();
    labelList.add(autoGenLabel);
    labelDAO.addLabels(labelList);
    DedicatedGateway dedicatedGateway = new DedicatedGateway();
    dedicatedGateway.setEnabled(true);
    dedicatedGateway.setUpdatedBy(api.getCreatedBy());
    dedicatedGateway.setApiId(api.getId());
    List<String> labels = new ArrayList<>();
    labels.add(autoGeneratedLabelName);
    apiDAO.updateDedicatedGateway(dedicatedGateway, labels);
    DedicatedGateway result = apiDAO.getDedicatedGateway(api.getId());
    Assert.assertEquals(result.isEnabled(), dedicatedGateway.isEnabled());
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) Test(org.testng.annotations.Test)

Example 4 with DedicatedGateway

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

the class APIPublisherImplTestCase method testUpdateDedicatedGatewayWhenDedicatedGatewayIsDisabledAndAPIHasOwnGateway.

@Test(description = "Update dedicated gateway when dedicated gateway is disabled and api has own gateway")
public void testUpdateDedicatedGatewayWhenDedicatedGatewayIsDisabledAndAPIHasOwnGateway() 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().hasOwnGateway(true).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, false, api.getCreatedBy());
    apiPublisher.updateDedicatedGateway(dedicatedGateway);
    Mockito.verify(apiDAO, Mockito.times(1)).updateDedicatedGateway(Mockito.any(), Mockito.anyList());
}
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 5 with DedicatedGateway

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

the class APIPublisherImplTestCase method testGetDedicatedGateway.

@Test(description = "Get dedicated gateway")
public void testGetDedicatedGateway() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    DedicatedGateway dedicatedGateway = new DedicatedGateway();
    dedicatedGateway.setEnabled(true);
    APIPublisherImpl apiPublisher = getApiPublisherImpl(apiDAO);
    Mockito.when(apiDAO.getDedicatedGateway(Mockito.anyString())).thenReturn(dedicatedGateway);
    DedicatedGateway result = apiPublisher.getDedicatedGateway(Mockito.anyString());
    Assert.assertTrue(result.isEnabled());
}
Also used : ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) Test(org.testng.annotations.Test)

Aggregations

DedicatedGateway (org.wso2.carbon.apimgt.core.models.DedicatedGateway)33 Test (org.testng.annotations.Test)20 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)20 API (org.wso2.carbon.apimgt.core.models.API)19 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)14 ArrayList (java.util.ArrayList)12 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)9 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)8 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)8 BeforeTest (org.testng.annotations.BeforeTest)7 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)7 Label (org.wso2.carbon.apimgt.core.models.Label)5 HashMap (java.util.HashMap)4 Response (javax.ws.rs.core.Response)4 Test (org.junit.Test)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)4 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)4 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)4 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)4