Search in sources :

Example 71 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.

the class LabelDAOImplIT method testGetLabelsByID.

@Test
public void testGetLabelsByID() throws Exception {
    LabelDAO labelDAO = DAOFactory.getLabelDAO();
    Label label1 = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    Label label2 = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
    List<Label> labelList = new ArrayList<>();
    LabelDAOImpl.addLabel(label1);
    LabelDAOImpl.addLabel(label2);
    List<String> labelNames = new ArrayList<>();
    labelNames.add(label1.getName());
    labelNames.add(label2.getName());
    List<String> labelIds = new ArrayList<>();
    labelIds.add(label1.getId());
    labelIds.add(label2.getId());
    List<Label> labelFromDb = new ArrayList<>();
    for (String id : labelIds) {
        labelFromDb.add(labelDAO.getLabelByID(id));
    }
    Assert.assertNotNull(labelFromDb);
    Assert.assertEquals(labelFromDb.size(), 2);
}
Also used : Label(org.wso2.carbon.apimgt.core.models.Label) ArrayList(java.util.ArrayList) LabelDAO(org.wso2.carbon.apimgt.core.dao.LabelDAO) Test(org.testng.annotations.Test)

Example 72 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase 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);
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    API api = SampleTestObjectCreator.createDefaultAPI().hasOwnGateway(true).lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    APIStoreImpl apiStore = getApiStoreImpl(apiDAO, labelDAO);
    DedicatedGateway dedicatedGateway = SampleTestObjectCreator.createDedicatedGateway(uuid, false, api.getCreatedBy());
    apiStore.updateDedicatedGateway(dedicatedGateway);
    List<String> labelSet = new ArrayList<>();
    labelSet.add(APIMgtConstants.DEFAULT_LABEL_NAME);
    Mockito.verify(apiDAO, Mockito.times(1)).updateDedicatedGateway(dedicatedGateway, labelSet);
}
Also used : 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) BeforeTest(org.testng.annotations.BeforeTest)

Example 73 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testUpdateDedicatedGateway.

@Test(description = "Update dedicated gateway")
public void testUpdateDedicatedGateway() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    String autoGenLabelName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + uuid;
    Mockito.when(labelDAO.getLabelByName(autoGenLabelName)).thenReturn(null);
    APIStoreImpl apiStore = getApiStoreImpl(apiDAO, labelDAO);
    DedicatedGateway dedicatedGateway = SampleTestObjectCreator.createDedicatedGateway(uuid, true, api.getCreatedBy());
    apiStore.updateDedicatedGateway(dedicatedGateway);
    List<String> labelSet = new ArrayList<>();
    labelSet.add(autoGenLabelName);
    Mockito.verify(apiDAO, Mockito.times(1)).updateDedicatedGateway(dedicatedGateway, labelSet);
    Mockito.verify(labelDAO, Mockito.times(1)).addLabels(Mockito.anyList());
}
Also used : 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) BeforeTest(org.testng.annotations.BeforeTest)

Example 74 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testUpdateDedicatedGatewayForException.

@Test(description = "Update dedicated gateway for exception", expectedExceptions = APIManagementException.class)
public void testUpdateDedicatedGatewayForException() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    String autoGenLabelName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + uuid;
    Mockito.when(labelDAO.getLabelByName(autoGenLabelName)).thenReturn(null);
    APIStoreImpl apiStore = getApiStoreImpl(apiDAO, labelDAO);
    DedicatedGateway dedicatedGateway = SampleTestObjectCreator.createDedicatedGateway(uuid, true, api.getCreatedBy());
    List<String> labelSet = new ArrayList<>();
    labelSet.add(autoGenLabelName);
    Mockito.doThrow(APIMgtDAOException.class).when(apiDAO).updateDedicatedGateway(dedicatedGateway, labelSet);
    apiStore.updateDedicatedGateway(dedicatedGateway);
}
Also used : 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) BeforeTest(org.testng.annotations.BeforeTest)

Example 75 with LabelDAO

use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.

the class APIStoreImplTestCase method testUpdateDedicatedGatewayWhenLabelIsNotNull.

@Test(description = "Update dedicated gateway when label is not null and present in the system")
public void testUpdateDedicatedGatewayWhenLabelIsNotNull() throws APIManagementException {
    ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
    LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
    API api = SampleTestObjectCreator.createDefaultAPI().lifeCycleStatus(APIStatus.PUBLISHED.getStatus()).build();
    String uuid = api.getId();
    Mockito.when(apiDAO.getAPI(uuid)).thenReturn(api);
    String autoGenLabelName = ContainerBasedGatewayConstants.PRIVATE_JET_API_PREFIX + uuid;
    Label label = new Label.Builder().id(java.util.UUID.randomUUID().toString()).name(autoGenLabelName).accessUrls(null).build();
    Mockito.when(labelDAO.getLabelByName(autoGenLabelName)).thenReturn(label);
    APIStoreImpl apiStore = getApiStoreImpl(apiDAO, labelDAO);
    DedicatedGateway dedicatedGateway = SampleTestObjectCreator.createDedicatedGateway(uuid, true, api.getCreatedBy());
    apiStore.updateDedicatedGateway(dedicatedGateway);
    List<String> labelSet = new ArrayList<>();
    labelSet.add(autoGenLabelName);
    Mockito.verify(apiDAO, Mockito.times(1)).updateDedicatedGateway(dedicatedGateway, labelSet);
    Mockito.verify(labelDAO, Mockito.times(0)).addLabels(Mockito.anyList());
}
Also used : APIBuilder(org.wso2.carbon.apimgt.core.models.API.APIBuilder) WorkflowExtensionsConfigBuilder(org.wso2.carbon.apimgt.core.workflow.WorkflowExtensionsConfigBuilder) 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) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)71 Test (org.testng.annotations.Test)70 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)45 API (org.wso2.carbon.apimgt.core.models.API)44 ArrayList (java.util.ArrayList)33 Label (org.wso2.carbon.apimgt.core.models.Label)33 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)28 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)26 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)26 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)26 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)17 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)16 LifecycleState (org.wso2.carbon.lcm.core.impl.LifecycleState)15 HashMap (java.util.HashMap)14 DedicatedGateway (org.wso2.carbon.apimgt.core.models.DedicatedGateway)14 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)14 BeforeTest (org.testng.annotations.BeforeTest)13 IdentityProvider (org.wso2.carbon.apimgt.core.api.IdentityProvider)11 CompositeAPI (org.wso2.carbon.apimgt.core.models.CompositeAPI)11 WorkflowExtensionsConfigBuilder (org.wso2.carbon.apimgt.core.workflow.WorkflowExtensionsConfigBuilder)11