use of org.wso2.carbon.apimgt.core.models.DedicatedGateway in project carbon-apimgt by wso2.
the class APIPublisherImpl method updateDedicatedGateway.
/**
* @see APIPublisherImpl#updateDedicatedGateway(DedicatedGateway)
*/
@Override
public void updateDedicatedGateway(DedicatedGateway dedicatedGateway) throws APIManagementException {
String apiId = dedicatedGateway.getApiId();
API api = getAPIbyUUID(apiId);
try {
validateChangingDedicatedGateway(api);
// label generation for the API
String autoGenLabelName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + apiId;
List<String> labelSet = new ArrayList<>();
if (dedicatedGateway.isEnabled()) {
Label label = getLabelDAO().getLabelByName(autoGenLabelName);
if (label == null) {
// A new label is created with auto generated label name value for per api gateway
List<Label> labelList = new ArrayList<>();
List<String> accessUrls = new ArrayList<>();
accessUrls.add(APIMgtConstants.HTTPS + APIMgtConstants.WEB_PROTOCOL_SUFFIX + autoGenLabelName);
Label autoGenLabel = new Label.Builder().id(autoGenLabelName).name(autoGenLabelName).accessUrls(accessUrls).type(APIMgtConstants.LABEL_TYPE_GATEWAY).build();
labelList.add(autoGenLabel);
getLabelDAO().addLabels(labelList);
log.debug("New label: {} added.", autoGenLabelName);
}
labelSet.add(autoGenLabelName);
labelSet.add(getLabelIdByNameAndType(APIMgtConstants.DEFAULT_LABEL_NAME, APIMgtConstants.LABEL_TYPE_STORE));
getApiDAO().updateDedicatedGateway(dedicatedGateway, labelSet);
} else {
if (api.hasOwnGateway()) {
labelSet.add(getLabelIdByNameAndType(APIMgtConstants.DEFAULT_LABEL_NAME, APIMgtConstants.LABEL_TYPE_GATEWAY));
labelSet.add(getLabelIdByNameAndType(APIMgtConstants.DEFAULT_LABEL_NAME, APIMgtConstants.LABEL_TYPE_STORE));
getApiDAO().updateDedicatedGateway(dedicatedGateway, labelSet);
}
}
} catch (APIMgtDAOException e) {
throw new APIManagementException("Error occurred while updating dedicatedGateway details of API with id " + apiId, e, ExceptionCodes.ERROR_WHILE_UPDATING_DEDICATED_CONTAINER_BASED_GATEWAY);
}
}
use of org.wso2.carbon.apimgt.core.models.DedicatedGateway in project carbon-apimgt by wso2.
the class APIStoreImpl method updateDedicatedGateway.
/**
* @see APIStoreImpl#updateDedicatedGateway(DedicatedGateway)
*/
@Override
public void updateDedicatedGateway(DedicatedGateway dedicatedGateway) throws APIManagementException {
String apiId = dedicatedGateway.getApiId();
API api = getAPIbyUUID(apiId);
try {
// label generation for the API
String autoGenLabelName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + apiId;
List<String> labelSet = new ArrayList<>();
if (dedicatedGateway.isEnabled()) {
Label label = getLabelDAO().getLabelByName(autoGenLabelName);
if (label == null) {
// A new label is created with auto generated label name value for per api gateway
List<Label> labelList = new ArrayList<>();
List<String> accessUrls = new ArrayList<>();
accessUrls.add(APIMgtConstants.HTTPS + APIMgtConstants.WEB_PROTOCOL_SUFFIX + autoGenLabelName);
Label autoGenLabel = new Label.Builder().id(UUID.randomUUID().toString()).name(autoGenLabelName).accessUrls(accessUrls).type(APIMgtConstants.LABEL_TYPE_GATEWAY).build();
labelList.add(autoGenLabel);
getLabelDAO().addLabels(labelList);
log.debug("New label: {} added.", autoGenLabelName);
}
labelSet.add(autoGenLabelName);
getApiDAO().updateDedicatedGateway(dedicatedGateway, labelSet);
} else {
if (api.hasOwnGateway()) {
labelSet.add(APIMgtConstants.DEFAULT_LABEL_NAME);
getApiDAO().updateDedicatedGateway(dedicatedGateway, labelSet);
}
}
} catch (APIMgtDAOException e) {
throw new APIManagementException("Error occurred while updating dedicatedGateway details of API with id " + apiId, e, ExceptionCodes.ERROR_WHILE_UPDATING_DEDICATED_CONTAINER_BASED_GATEWAY);
}
}
use of org.wso2.carbon.apimgt.core.models.DedicatedGateway in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetDedicatedGatewayForException.
@Test(description = "Get dedicated gateway exception scenario", expectedExceptions = APIManagementException.class)
public void testGetDedicatedGatewayForException() throws APIManagementException {
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
DedicatedGateway dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(true);
APIStoreImpl apiStore = getApiStoreImpl(apiDAO);
Mockito.when(apiDAO.getDedicatedGateway(Mockito.anyString())).thenThrow(APIMgtDAOException.class);
apiStore.getDedicatedGateway(Mockito.anyString());
}
use of org.wso2.carbon.apimgt.core.models.DedicatedGateway in project carbon-apimgt by wso2.
the class APIStoreImplTestCase 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);
APIStoreImpl apiStore = getApiStoreImpl(apiDAO);
Mockito.when(apiDAO.getDedicatedGateway(Mockito.anyString())).thenReturn(dedicatedGateway);
DedicatedGateway result = apiStore.getDedicatedGateway(Mockito.anyString());
Assert.assertTrue(result.isEnabled());
}
use of org.wso2.carbon.apimgt.core.models.DedicatedGateway in project carbon-apimgt by wso2.
the class CompositeApisApiServiceImplTestCase method testCompositeApisApiIdDedicatedGatewayGet.
@Test
public void testCompositeApisApiIdDedicatedGatewayGet() throws Exception {
TestUtil.printTestMethodName();
String apiID = UUID.randomUUID().toString();
CompositeApisApiServiceImpl compositeApisApiService = new CompositeApisApiServiceImpl();
APIStore apiStore = Mockito.mock(APIStoreImpl.class);
Request request = TestUtil.getRequest();
PowerMockito.mockStatic(RestApiUtil.class);
PowerMockito.when(RestApiUtil.getLoggedInUsername(request)).thenReturn(USER);
PowerMockito.when(RestApiUtil.getConsumer(USER)).thenReturn(apiStore);
Mockito.when(apiStore.isCompositeAPIExist(apiID)).thenReturn(Boolean.TRUE);
DedicatedGateway dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(true);
Mockito.when(apiStore.getDedicatedGateway(apiID)).thenReturn(dedicatedGateway);
Response response = compositeApisApiService.compositeApisApiIdDedicatedGatewayGet(apiID, null, null, request);
Assert.assertEquals(200, response.getStatus());
}
Aggregations