use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class LabelDAOImplIT method testAddGetLabels.
@Test
public void testAddGetLabels() throws Exception {
LabelDAO labelDAO = DAOFactory.getLabelDAO();
List<String> accessUrls = new ArrayList<>();
accessUrls.add("https://test.public");
accessUrls.add("http://test.public");
Label label1 = SampleTestObjectCreator.createLabel("public", SampleTestObjectCreator.LABEL_TYPE_GATEWAY).accessUrls(accessUrls).build();
LabelDAOImpl.addLabel(label1);
Label label2 = SampleTestObjectCreator.createLabel("private", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
List<Label> labelList = new ArrayList<>();
LabelDAOImpl.addLabel(label2);
List<Label> labelsFromDb = labelDAO.getLabels();
Assert.assertNotNull(labelsFromDb);
Assert.assertEquals(labelsFromDb.size(), 4);
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetLabelInfoException.
@Test(description = "Exception when retrieving labels", expectedExceptions = LabelException.class)
public void testGetLabelInfoException() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl(labelDAO);
List<String> labels = new ArrayList<>();
labels.add("label");
Mockito.when(labelDAO.getLabelsByName(labels)).thenThrow(new APIMgtDAOException("Error occurred while retrieving label information", new SQLException()));
apiStore.getLabelInfo(labels, USER_NAME);
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method getLabelsByTypeException.
@Test(description = "get labels by type Exception", expectedExceptions = Exception.class)
public void getLabelsByTypeException() throws Exception {
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl();
List<Label> labels = new ArrayList<>();
Label label = new Label.Builder().id("123").name("Default").type("STORE").accessUrls(new ArrayList<>()).build();
labels.add(label);
Mockito.when(labelDao.getLabelsByType("STORE")).thenReturn(labels);
Mockito.doThrow(new LabelException("Error occurred while retrieving labels ")).when(labelDao).getLabelsByType("STORE");
apiStore.getLabelsByType("STORE");
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method getLabelsByType.
@Test(description = "get labels by STORE type")
public void getLabelsByType() throws Exception {
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl(labelDao);
List<Label> labels = new ArrayList<>();
Label label = new Label.Builder().id("123").name("Default").type("STORE").accessUrls(new ArrayList<>()).build();
labels.add(label);
Mockito.when(labelDao.getLabelsByType("STORE")).thenReturn(labels);
List<Label> returnedLabels = apiStore.getLabelsByType("STORE");
Assert.assertNotNull(returnedLabels);
Mockito.verify(labelDao, Mockito.atLeastOnce()).getLabelsByType("STORE");
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetAPIWSDLArchive.
@Test(description = "Retrieve a WSDL archive of an API")
public void testGetAPIWSDLArchive() throws APIManagementException, IOException {
final String labelName = "SampleLabel";
Label label = SampleTestObjectCreator.createLabel(labelName, SampleTestObjectCreator.LABEL_TYPE_STORE).build();
List<String> labels = new ArrayList<>();
labels.add(label.getName());
API api = SampleTestObjectCreator.createDefaultAPI().labels(labels).build();
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl(apiDAO, labelDAO);
Mockito.when(apiDAO.getAPI(api.getId())).thenReturn(api);
Mockito.when(labelDAO.getLabelByName(labelName)).thenReturn(label);
Mockito.when(apiDAO.getWSDLArchive(api.getId())).thenReturn(SampleTestObjectCreator.createDefaultWSDL11ArchiveInputStream());
String expectedEndpoint = SampleTestObjectCreator.ACCESS_URL + labelName + (api.getContext().startsWith("/") ? api.getContext() : "/" + api.getContext());
WSDLArchiveInfo archiveInfo = apiStore.getAPIWSDLArchive(api.getId(), label.getName());
Assert.assertNotNull(archiveInfo);
Assert.assertNotNull(archiveInfo.getWsdlInfo());
Assert.assertNotNull(archiveInfo.getWsdlInfo().getEndpoints());
Map<String, String> endpoints = archiveInfo.getWsdlInfo().getEndpoints();
Assert.assertTrue(endpoints.containsValue(expectedEndpoint));
Assert.assertFalse(endpoints.containsValue(SampleTestObjectCreator.ORIGINAL_ENDPOINT_STOCK_QUOTE));
Assert.assertFalse(endpoints.containsValue(SampleTestObjectCreator.ORIGINAL_ENDPOINT_WEATHER));
}
Aggregations