Search in sources :

Example 11 with DedicatedGateway

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);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) Label(org.wso2.carbon.apimgt.core.models.Label) API(org.wso2.carbon.apimgt.core.models.API)

Example 12 with DedicatedGateway

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);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) Label(org.wso2.carbon.apimgt.core.models.Label) CompositeAPI(org.wso2.carbon.apimgt.core.models.CompositeAPI) API(org.wso2.carbon.apimgt.core.models.API)

Example 13 with DedicatedGateway

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());
}
Also used : ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 14 with DedicatedGateway

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());
}
Also used : ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 15 with DedicatedGateway

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());
}
Also used : Response(javax.ws.rs.core.Response) Request(org.wso2.msf4j.Request) APIStore(org.wso2.carbon.apimgt.core.api.APIStore) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.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