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);
}
}
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;
}
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());
}
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());
}
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());
}
Aggregations