use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetCustomOutSequences1.
@Test
public void testGetCustomOutSequences1() throws Exception {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
mockSequences(APIConstants.API_CUSTOM_OUTSEQUENCE_LOCATION, APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT, apiId);
List<String> sequenceList = apiProvider.getCustomOutSequences();
Assert.assertNotNull(sequenceList);
Assert.assertEquals(1, sequenceList.size());
// OMException when building OMElement
PowerMockito.when(APIUtil.buildOMElement(any(InputStream.class))).thenThrow(new OMException());
apiProvider.getCustomOutSequences();
// 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_OUTSEQUENCE_LOCATION)).thenThrow(org.wso2.carbon.registry.api.RegistryException.class);
String msg = "Error while processing the out in the registry";
try {
apiProvider.getCustomOutSequences();
} 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.getCustomOutSequences();
} catch (APIManagementException e) {
Assert.assertEquals(msg1, e.getMessage());
}
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetCustomOutSequences.
@Test
public void testGetCustomOutSequences() throws Exception {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
mockSequences(APIConstants.API_CUSTOM_OUTSEQUENCE_LOCATION, APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT, apiId);
List<String> sequenceList = apiProvider.getCustomOutSequences(apiId);
Assert.assertNotNull(sequenceList);
Assert.assertEquals(2, sequenceList.size());
Assert.assertTrue(sequenceList.contains("fault-seq"));
Assert.assertTrue(sequenceList.contains("custom-fault-seq"));
// OMException when building OMElement
PowerMockito.when(APIUtil.buildOMElement(any(InputStream.class))).thenThrow(new OMException());
apiProvider.getCustomOutSequences(apiId);
// 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_OUTSEQUENCE_LOCATION)).thenThrow(org.wso2.carbon.registry.api.RegistryException.class);
String msg = "Issue is in getting custom OutSequences from the Registry";
try {
apiProvider.getCustomOutSequences(apiId);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
// Registry Exception
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenThrow(RegistryException.class);
try {
apiProvider.getCustomOutSequences(apiId);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImplTest method testGetCustomInSequences.
@Test
public void testGetCustomInSequences() throws Exception {
APIIdentifier apiId = new APIIdentifier("admin", "API1", "1.0.1");
APIProviderImplWrapper apiProvider = new APIProviderImplWrapper(apimgtDAO, scopesDAO);
mockSequences(APIConstants.API_CUSTOM_INSEQUENCE_LOCATION, APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN, apiId);
List<String> sequenceList = apiProvider.getCustomInSequences(apiId);
Assert.assertNotNull(sequenceList);
Assert.assertEquals(2, sequenceList.size());
Assert.assertTrue(sequenceList.contains("fault-seq"));
Assert.assertTrue(sequenceList.contains("custom-fault-seq"));
// OMException when building OMElement
PowerMockito.when(APIUtil.buildOMElement(any(InputStream.class))).thenThrow(new OMException());
apiProvider.getCustomInSequences(apiId);
// 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_INSEQUENCE_LOCATION)).thenThrow(org.wso2.carbon.registry.api.RegistryException.class);
String msg = "Issue is in getting custom InSequences from the Registry";
try {
apiProvider.getCustomInSequences(apiId);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
// Registry Exception
PowerMockito.when(registryService.getGovernanceSystemRegistry(Matchers.anyInt())).thenThrow(RegistryException.class);
try {
apiProvider.getCustomInSequences(apiId);
} catch (APIManagementException e) {
Assert.assertEquals(msg, e.getMessage());
}
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImpl method getCustomInSequences.
/**
* Get the list of Custom InSequences including API defined in sequences.
*
* @return List of available sequences
* @throws APIManagementException
*/
public List<String> getCustomInSequences() throws APIManagementException {
Set<String> sequenceList = new TreeSet<>();
try {
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
if (registry.resourceExists(APIConstants.API_CUSTOM_INSEQUENCE_LOCATION)) {
org.wso2.carbon.registry.api.Collection inSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(APIConstants.API_CUSTOM_INSEQUENCE_LOCATION);
if (inSeqCollection != null) {
String[] inSeqChildPaths = inSeqCollection.getChildren();
Arrays.sort(inSeqChildPaths);
for (String inSeqChildPath : inSeqChildPaths) {
Resource inSequence = registry.get(inSeqChildPath);
try {
OMElement seqElment = APIUtil.buildOMElement(inSequence.getContentStream());
sequenceList.add(seqElment.getAttributeValue(new QName("name")));
} catch (OMException e) {
log.info("Error occurred when reading the sequence '" + inSeqChildPath + "' from the registry.", e);
}
}
}
}
} catch (RegistryException e) {
String msg = "Error while retrieving registry for tenant " + tenantId;
log.error(msg);
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.registry.api.RegistryException e) {
String msg = "Error while processing the " + APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN + " in the registry";
log.error(msg);
throw new APIManagementException(msg, e);
} catch (Exception e) {
log.error(e.getMessage());
throw new APIManagementException(e.getMessage(), e);
}
return new ArrayList<>(sequenceList);
}
use of org.apache.axiom.om.OMException in project carbon-apimgt by wso2.
the class APIProviderImpl method getCustomOutSequences.
/**
* Get the list of Custom InSequences including API defined in sequences.
*
* @return List of available sequences
* @throws APIManagementException
*/
public List<String> getCustomOutSequences() throws APIManagementException {
Set<String> sequenceList = new TreeSet<>();
try {
UserRegistry registry = ServiceReferenceHolder.getInstance().getRegistryService().getGovernanceSystemRegistry(tenantId);
if (registry.resourceExists(APIConstants.API_CUSTOM_OUTSEQUENCE_LOCATION)) {
org.wso2.carbon.registry.api.Collection outSeqCollection = (org.wso2.carbon.registry.api.Collection) registry.get(APIConstants.API_CUSTOM_OUTSEQUENCE_LOCATION);
if (outSeqCollection != null) {
String[] outSeqChildPaths = outSeqCollection.getChildren();
Arrays.sort(outSeqChildPaths);
for (String outSeqChildPath : outSeqChildPaths) {
Resource outSequence = registry.get(outSeqChildPath);
try {
OMElement seqElment = APIUtil.buildOMElement(outSequence.getContentStream());
sequenceList.add(seqElment.getAttributeValue(new QName("name")));
} catch (OMException e) {
log.info("Error occurred when reading the sequence '" + outSeqChildPath + "' from the registry.", e);
}
}
}
}
} catch (RegistryException e) {
String msg = "Error while retrieving registry for tenant " + tenantId;
log.error(msg);
throw new APIManagementException(msg, e);
} catch (org.wso2.carbon.registry.api.RegistryException e) {
String msg = "Error while processing the " + APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT + " in the registry";
log.error(msg);
throw new APIManagementException(msg, e);
} catch (Exception e) {
log.error(e.getMessage());
throw new APIManagementException(e.getMessage(), e);
}
return new ArrayList<>(sequenceList);
}
Aggregations