use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method getAllLabelsException.
@Test(description = "get all labels Exception", expectedExceptions = Exception.class)
public void getAllLabelsException() 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.getLabels()).thenReturn(labels);
Mockito.doThrow(new LabelException("Error occurred while retrieving labels ")).when(labelDao).getLabels();
apiStore.getAllLabels();
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetLabelInfo.
@Test(description = "Retrieve labels")
public void testGetLabelInfo() throws APIManagementException {
LabelDAO labelDAO = Mockito.mock(LabelDAO.class);
APIStore apiStore = getApiStoreImpl(labelDAO);
List<Label> labelList = new ArrayList<>();
List<String> labelNames = new ArrayList<>();
Label label = SampleTestObjectCreator.createLabel("Public", SampleTestObjectCreator.LABEL_TYPE_STORE).build();
labelList.add(label);
labelNames.add(label.getName());
Mockito.when(labelDAO.getLabelsByName(labelNames)).thenReturn(labelList);
List<Label> returnedLabels = apiStore.getLabelInfo(labelNames, USER_NAME);
Assert.assertEquals(returnedLabels, labelList);
Mockito.verify(labelDAO, Mockito.times(1)).getLabelsByName(labelNames);
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetLabelByID.
@Test(description = "Get Label by ID")
public void testGetLabelByID() throws APIManagementException {
LabelDAO labelDAO = mock(LabelDAO.class);
Label label = SampleTestObjectCreator.createLabel(LABEL_NAME, SampleTestObjectCreator.LABEL_TYPE_STORE).build();
AbstractAPIManager apiManager = getApiPublisherImpl(labelDAO);
when(labelDAO.getLabelByID(label.getId())).thenReturn(label);
apiManager.getLabelByID(label.getId());
verify(labelDAO, times(1)).getLabelByID(label.getId());
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class APIStoreImplTestCase method testGetAPIWSDL.
@Test(description = "Retrieve a WSDL of an API")
public void testGetAPIWSDL() 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.getWSDL(api.getId())).thenReturn(new String(SampleTestObjectCreator.createDefaultWSDL11Content()));
String expectedEndpoint = SampleTestObjectCreator.ACCESS_URL + labelName + (api.getContext().startsWith("/") ? api.getContext() : "/" + api.getContext());
String updatedWSDL = apiStore.getAPIWSDL(api.getId(), label.getName());
Assert.assertTrue(updatedWSDL.contains(expectedEndpoint));
}
use of org.wso2.carbon.apimgt.core.dao.LabelDAO in project carbon-apimgt by wso2.
the class APIPublisherImplTestCase method testAddResourceLevelEndpointWhileResourceEndpointAlreadyExistsWhileDatabaseFailure.
@Test(description = "Test add api with Api Specific Endpoint", expectedExceptions = { APIManagementException.class })
public void testAddResourceLevelEndpointWhileResourceEndpointAlreadyExistsWhileDatabaseFailure() throws APIManagementException, LifecycleException {
/**
* this test method verify the API Add with correct API object get invoked correctly
*/
ApiDAO apiDAO = Mockito.mock(ApiDAO.class);
GatewaySourceGenerator gatewaySourceGenerator = Mockito.mock(GatewaySourceGenerator.class);
APILifecycleManager apiLifecycleManager = Mockito.mock(APILifecycleManager.class);
Endpoint globalEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("testEndpoint").applicableLevel(APIMgtConstants.GLOBAL_ENDPOINT).build();
Endpoint apiEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("apiEndpoint").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
Endpoint resourceEndpoint = new Endpoint.Builder().id(UUID.randomUUID().toString()).name("resourceEndpoint").applicableLevel(APIMgtConstants.API_SPECIFIC_ENDPOINT).build();
Map<String, Endpoint> endpointMap = new HashMap();
endpointMap.put(APIMgtConstants.PRODUCTION_ENDPOINT, globalEndpoint);
endpointMap.put(APIMgtConstants.SANDBOX_ENDPOINT, apiEndpoint);
Map<String, Endpoint> resourceEndpoints = new HashMap();
resourceEndpoints.put(APIMgtConstants.SANDBOX_ENDPOINT, resourceEndpoint);
Map<String, UriTemplate> uriTemplateMap = SampleTestObjectCreator.getMockUriTemplates();
uriTemplateMap.forEach((k, v) -> {
UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(v);
uriTemplateBuilder.endpoint(resourceEndpoints);
uriTemplateMap.replace(k, uriTemplateBuilder.build());
});
API.APIBuilder apiBuilder = SampleTestObjectCreator.createDefaultAPI().endpoint(endpointMap).uriTemplates(uriTemplateMap);
Mockito.when(apiLifecycleManager.addLifecycle(APIMgtConstants.API_LIFECYCLE, USER)).thenReturn(new LifecycleState());
APIGateway gateway = Mockito.mock(APIGateway.class);
LabelDAO labelDao = Mockito.mock(LabelDAO.class);
APIPublisherImpl apiPublisher = getApiPublisherImpl(null, apiDAO, null, null, null, apiLifecycleManager, labelDao, null, null, null, gatewaySourceGenerator, gateway);
Mockito.when(apiDAO.getEndpoint(globalEndpoint.getId())).thenReturn(globalEndpoint);
Mockito.when(apiDAO.getEndpointByName(apiEndpoint.getName())).thenReturn(null);
Mockito.when(apiDAO.getEndpointByName(resourceEndpoint.getName())).thenThrow(APIMgtDAOException.class);
Mockito.when(apiDAO.isAPINameExists(apiBuilder.getName(), USER)).thenReturn(false);
apiPublisher.addAPI(apiBuilder);
Mockito.verify(apiDAO, Mockito.times(1)).addAPI(apiBuilder.build());
Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(apiEndpoint.getName());
Mockito.verify(apiDAO, Mockito.times(1)).getEndpointByName(resourceEndpoint.getName());
}
Aggregations