use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class APIUtilTest method testGetCustomFaultSequence.
@Test
public void testGetCustomFaultSequence() throws Exception {
APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry registry = Mockito.mock(UserRegistry.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);
Collection collection = Mockito.mock(Collection.class);
String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "fault" + RegistryConstants.PATH_SEPARATOR;
Mockito.when(registry.get(eq(path))).thenReturn(collection);
String[] childPaths = { "test" };
Mockito.when(collection.getChildren()).thenReturn(childPaths);
InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("sampleSequence.xml").getFile());
Resource resource = Mockito.mock(Resource.class);
Mockito.when(registry.get(eq("test"))).thenReturn(resource);
Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);
OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "fault", apiIdentifier);
Assert.assertNotNull(customSequence);
sampleSequence.close();
}
use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class APIUtilTest method testGetCustomSequenceNull.
@Test
public void testGetCustomSequenceNull() throws Exception {
APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry registry = Mockito.mock(UserRegistry.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);
Collection collection = Mockito.mock(Collection.class);
String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR;
Mockito.when(registry.get(eq(path))).thenReturn(null, null);
String[] childPaths = { "test" };
Mockito.when(collection.getChildren()).thenReturn(childPaths);
String expectedUUID = UUID.randomUUID().toString();
InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("sampleSequence.xml").getFile());
Resource resource = Mockito.mock(Resource.class);
Mockito.when(registry.get(eq("test"))).thenReturn(resource);
Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);
Mockito.when(resource.getUUID()).thenReturn(expectedUUID);
OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "custom", apiIdentifier);
Assert.assertNull(customSequence);
sampleSequence.close();
}
use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class APIUtilTest method testGetMediationSequenceUuidCustomSequenceNotFound.
@Test
public void testGetMediationSequenceUuidCustomSequenceNotFound() throws Exception {
APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry registry = Mockito.mock(UserRegistry.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);
Collection collection = Mockito.mock(Collection.class);
String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR;
Mockito.when(registry.get(eq(path))).thenReturn(null, collection);
String[] childPaths = { "test" };
Mockito.when(collection.getChildren()).thenReturn(childPaths);
String expectedUUID = UUID.randomUUID().toString();
InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("sampleSequence.xml").getFile());
Resource resource = Mockito.mock(Resource.class);
Mockito.when(registry.get(eq("test"))).thenReturn(resource);
Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);
Mockito.when(resource.getUUID()).thenReturn(expectedUUID);
String actualUUID = APIUtil.getMediationSequenceUuid("sample", 1, "custom", apiIdentifier);
Assert.assertEquals(expectedUUID, actualUUID);
sampleSequence.close();
}
use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class APIUtilTest method testIsPerAPISequence.
@Test
public void testIsPerAPISequence() throws Exception {
APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry registry = Mockito.mock(UserRegistry.class);
String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "in" + RegistryConstants.PATH_SEPARATOR;
PowerMockito.mockStatic(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);
Mockito.when(registry.resourceExists(eq(path))).thenReturn(true);
Collection collection = Mockito.mock(Collection.class);
Mockito.when(registry.get(eq(path))).thenReturn(collection);
String[] childPaths = { "test" };
Mockito.when(collection.getChildren()).thenReturn(childPaths);
InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("sampleSequence.xml").getFile());
Resource resource = Mockito.mock(Resource.class);
Mockito.when(registry.get(eq("test"))).thenReturn(resource);
Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);
boolean isPerAPiSequence = APIUtil.isPerAPISequence("sample", 1, apiIdentifier, "in");
Assert.assertTrue(isPerAPiSequence);
}
use of org.wso2.carbon.registry.core.Collection in project carbon-apimgt by wso2.
the class APIUtilTest method testGetCustomSequenceNotFound.
@Test
public void testGetCustomSequenceNotFound() throws Exception {
APIIdentifier apiIdentifier = Mockito.mock(APIIdentifier.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
RegistryService registryService = Mockito.mock(RegistryService.class);
UserRegistry registry = Mockito.mock(UserRegistry.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getRegistryService()).thenReturn(registryService);
Mockito.when(registryService.getGovernanceSystemRegistry(eq(1))).thenReturn(registry);
Collection collection = Mockito.mock(Collection.class);
String artifactPath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getApiName() + RegistryConstants.PATH_SEPARATOR + apiIdentifier.getVersion();
String path = artifactPath + RegistryConstants.PATH_SEPARATOR + "custom" + RegistryConstants.PATH_SEPARATOR;
Mockito.when(registry.get(eq(path))).thenReturn(null, collection);
String[] childPaths = { "test" };
Mockito.when(collection.getChildren()).thenReturn(childPaths);
String expectedUUID = UUID.randomUUID().toString();
InputStream sampleSequence = new FileInputStream(Thread.currentThread().getContextClassLoader().getResource("sampleSequence.xml").getFile());
Resource resource = Mockito.mock(Resource.class);
Mockito.when(registry.get(eq("test"))).thenReturn(resource);
Mockito.when(resource.getContentStream()).thenReturn(sampleSequence);
Mockito.when(resource.getUUID()).thenReturn(expectedUUID);
OMElement customSequence = APIUtil.getCustomSequence("sample", 1, "custom", apiIdentifier);
Assert.assertNotNull(customSequence);
sampleSequence.close();
}
Aggregations