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