use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetAPIPolicyByUUID.
@Test
public void testGetAPIPolicyByUUID() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
APIPolicy apiPolicy = Mockito.mock(APIPolicy.class);
Mockito.when(apimgtDAO.getAPIPolicyByUUID("1111")).thenReturn(apiPolicy, null);
apiProvider.getAPIPolicyByUUID("1111");
try {
assertNotNull(apiProvider.getAPIPolicyByUUID("1111"));
} catch (APIManagementException e) {
assertEquals("Advanced Policy: 1111 was not found.", e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetBlockCondition.
@Test
public void testGetBlockCondition() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
Mockito.when(apimgtDAO.getBlockCondition(Mockito.anyInt())).thenReturn(blockConditionsDTO);
assertNotNull(apiProvider.getBlockCondition(Mockito.anyInt()));
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetCustomFaultSequences1.
@Test
public void testGetCustomFaultSequences1() throws Exception {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
mockSequences(APIConstants.API_CUSTOM_FAULTSEQUENCE_LOCATION, APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT, apiId);
List<String> sequenceList = apiProvider.getCustomFaultSequences();
Assert.assertNotNull(sequenceList);
Assert.assertEquals(1, sequenceList.size());
// OMException when building OMElement
PowerMockito.when(APIUtil.buildOMElement(any(InputStream.class))).thenThrow(new OMException());
apiProvider.getCustomFaultSequences();
// org.wso2.carbon.registry.api.RegistryException
ServiceReferenceHolder sh = PowerMockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(sh);
RegistryService registryService = Mockito.mock(RegistryService.class);
PowerMockito.when(sh.getRegistryService()).thenReturn(registryService);
UserRegistry registry = Mockito.mock(UserRegistry.class);
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenReturn(registry);
Mockito.when(registry.resourceExists(APIConstants.API_CUSTOM_FAULTSEQUENCE_LOCATION)).thenThrow(org.wso2.carbon.registry.api.RegistryException.class);
String msg = "Error while processing the fault in the registry";
try {
apiProvider.getCustomFaultSequences();
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
// Registry Exception
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenThrow(RegistryException.class);
String msg1 = "Error while retrieving registry for tenant -1";
try {
apiProvider.getCustomFaultSequences();
} catch (APIManagementException e) {
Assert.assertEquals(msg1, e.getMessage());
}
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testUpdateBlockCondition.
@Test
public void testUpdateBlockCondition() throws APIManagementException {
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
Mockito.when(apimgtDAO.updateBlockConditionState(1, "testState")).thenReturn(false, true);
BlockConditionsDTO blockConditionsDTO = new BlockConditionsDTO();
blockConditionsDTO.setConditionType("testType");
blockConditionsDTO.setConditionValue("USER");
PowerMockito.mockStatic(MultitenantUtils.class);
PowerMockito.when(MultitenantUtils.getTenantAwareUsername("User")).thenReturn("testValue");
Mockito.when(apimgtDAO.getBlockCondition(1)).thenReturn(blockConditionsDTO);
// updateState false
assertFalse(apiProvider.updateBlockCondition(1, "testState"));
// updateState true
assertTrue(apiProvider.updateBlockCondition(1, "testState"));
}
use of org.wso2.carbon.apimgt.impl.dao.ScopesDAO in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetSequenceFile.
@Test
public void testGetSequenceFile() throws Exception {
APIIdentifier apiIdentifier = new APIIdentifier("admin", "API1", "1.0");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
mockSequences(APIConstants.API_CUSTOM_FAULTSEQUENCE_LOCATION, APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT, apiIdentifier);
String sequenceContent = apiProvider.getSequenceFileContent(apiIdentifier, "fault", "custom-fault-seq");
Assert.assertNotNull(sequenceContent);
ServiceReferenceHolder sh = PowerMockito.mock(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(sh);
RegistryService registryService = Mockito.mock(RegistryService.class);
PowerMockito.when(sh.getRegistryService()).thenReturn(registryService);
UserRegistry registry = Mockito.mock(UserRegistry.class);
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenReturn(registry);
Mockito.when(registry.resourceExists(APIUtil.getSequencePath(apiIdentifier, APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT))).thenThrow(org.wso2.carbon.registry.api.RegistryException.class);
String msg = "Error while processing the " + APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT + " sequences of " + apiIdentifier + " in the registry";
try {
apiProvider.getSequenceFileContent(apiIdentifier, "fault", "custom-fault-seq");
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains(msg));
}
// Registry Exception
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenThrow(RegistryException.class);
String msg1 = "Error while retrieving registry for tenant -1";
try {
apiProvider.getSequenceFileContent(apiIdentifier, "fault", "custom-fault-seq");
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains(msg1));
}
}
Aggregations