本文整理汇总了Java中org.ligoj.app.resource.ServicePluginLocator类的典型用法代码示例。如果您正苦于以下问题:Java ServicePluginLocator类的具体用法?Java ServicePluginLocator怎么用?Java ServicePluginLocator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ServicePluginLocator类属于org.ligoj.app.resource包,在下文中一共展示了ServicePluginLocator类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateCatalogFailed
import org.ligoj.app.resource.ServicePluginLocator; //导入依赖的package包/类
@Test
public void updateCatalogFailed() throws Exception {
final ImportCatalogResource resource = new ImportCatalogResource() {
@Override
public ImportCatalogStatus nextStep(final String node, final Consumer<ImportCatalogStatus> stepper) {
return super.nextStep(node, stepper);
}
};
applicationContext.getAutowireCapableBeanFactory().autowireBean(resource);
// Replace the locator for the custom provider
resource.locator = Mockito.mock(ServicePluginLocator.class);
final ImportCatalogService service = Mockito.mock(ImportCatalogService.class);
Mockito.when(resource.locator.getResource("service:prov:test", ImportCatalogService.class)).thenReturn(service);
Mockito.doThrow(new IOException()).when(service).updateCatalog("service:prov:test");
final ImportCatalogStatus status = resource.updateCatalog("service:prov:test:account");
Assert.assertEquals(DEFAULT_USER, status.getAuthor());
Assert.assertNull(status.getEnd());
Assert.assertNull(status.getLocation());
Assert.assertEquals("service:prov:test", status.getLocked().getId());
Assert.assertNotNull(status.getStart());
Assert.assertEquals(0, status.getDone());
Assert.assertEquals(0, status.getWorkload());
}
示例2: applyTerraformError
import org.ligoj.app.resource.ServicePluginLocator; //导入依赖的package包/类
/**
* IOException during the asynchronous execution
*/
@Test
public void applyTerraformError() {
final TerraformResource resource = new TerraformResource() {
@Override
protected File applyTerraform(final Subscription entity, final Terraforming terra, final QuoteVo configuration)
throws IOException, InterruptedException {
throw new IOException();
}
};
super.applicationContext.getAutowireCapableBeanFactory().autowireBean(resource);
// Mock to disable inner transactions for this test
resource.resource = Mockito.mock(ProvResource.class);
final ServicePluginLocator locator = Mockito.mock(ServicePluginLocator.class);
// Replace the plugin locator
resource.locator = locator;
Mockito.when(locator.getResource("service:prov:test:account", Terraforming.class)).thenReturn(Mockito.mock(Terraforming.class));
resource.applyTerraform(subscription);
}
示例3: authenticateSecondaryAccept
import org.ligoj.app.resource.ServicePluginLocator; //导入依赖的package包/类
@Test
public void authenticateSecondaryAccept() throws Exception {
final Authentication authentication = new UsernamePasswordAuthenticationToken("user1", "secret");
final Authentication authentication2 = new UsernamePasswordAuthenticationToken("user1v2", "secret");
final IdentityServicePlugin servicePlugin = Mockito.mock(IdentityServicePlugin.class);
final NodeBasedIamProvider provider = new NodeBasedIamProvider();
provider.configuration = configuration;
provider.servicePluginLocator = Mockito.mock(ServicePluginLocator.class);
Mockito.when(provider.servicePluginLocator.getResource("service:id:ldap:adu", IdentityServicePlugin.class))
.thenReturn(servicePlugin);
Mockito.when(servicePlugin.accept(authentication, "service:id:ldap:adu")).thenReturn(true);
Mockito.when(servicePlugin.authenticate(authentication, "service:id:ldap:adu", false))
.thenReturn(authentication2);
Assert.assertSame(authentication2, provider.authenticate(authentication));
Mockito.verify(provider.servicePluginLocator, VerificationModeFactory.times(0))
.getResource("service:id:ldap:dig", IdentityServicePlugin.class);
}
示例4: authenticateSecondaryDontAccept
import org.ligoj.app.resource.ServicePluginLocator; //导入依赖的package包/类
@Test
public void authenticateSecondaryDontAccept() throws Exception {
final Authentication authentication = new UsernamePasswordAuthenticationToken("user1", "secret");
final Authentication authentication2 = new UsernamePasswordAuthenticationToken("user1v2", "secret");
final IdentityServicePlugin servicePluginSecondary = Mockito.mock(IdentityServicePlugin.class);
final IdentityServicePlugin servicePluginPrimary = Mockito.mock(IdentityServicePlugin.class);
final NodeBasedIamProvider provider = new NodeBasedIamProvider();
provider.configuration = configuration;
provider.servicePluginLocator = Mockito.mock(ServicePluginLocator.class);
Mockito.when(provider.servicePluginLocator.getResource("service:id:ldap:adu", IdentityServicePlugin.class))
.thenReturn(servicePluginSecondary);
Mockito.when(servicePluginPrimary.authenticate(authentication, "service:id:ldap:dig", true))
.thenReturn(authentication2);
Mockito.when(
provider.servicePluginLocator.getResourceExpected("service:id:ldap:dig", IdentityServicePlugin.class))
.thenReturn(servicePluginPrimary);
Assert.assertSame(authentication2, provider.authenticate(authentication));
Mockito.verify(servicePluginSecondary, VerificationModeFactory.times(0)).authenticate(authentication,
"service:id:ldap:adu", false);
}
示例5: updateCatalog
import org.ligoj.app.resource.ServicePluginLocator; //导入依赖的package包/类
@Test
public void updateCatalog() throws Exception {
final ImportCatalogResource resource = new ImportCatalogResource() {
@Override
public ImportCatalogStatus getTask(@PathParam("node") final String node) {
return getTaskRepository().findBy("locked.id", node);
}
};
applicationContext.getAutowireCapableBeanFactory().autowireBean(resource);
// Replace the locator for the custom provider
resource.locator = Mockito.mock(ServicePluginLocator.class);
final ImportCatalogService service = Mockito.mock(ImportCatalogService.class);
Mockito.when(resource.locator.getResource("service:prov:test", ImportCatalogService.class)).thenReturn(service);
final ImportCatalogStatus status = resource.updateCatalog("service:prov:test:account");
Assert.assertEquals(DEFAULT_USER, status.getAuthor());
Assert.assertNull(status.getEnd());
Assert.assertNull(status.getLocation());
Assert.assertEquals("service:prov:test", status.getLocked().getId());
Assert.assertNotNull(status.getStart());
Assert.assertNull(status.getLocation());
Assert.assertEquals(0, status.getDone());
Assert.assertEquals(0, status.getWorkload());
Assert.assertFalse(resource.getTask("service:prov:test").isFinished());
Thread.sleep(100);
Mockito.verify(service).updateCatalog("service:prov:test");
}
示例6: authenticateNoSecondary
import org.ligoj.app.resource.ServicePluginLocator; //导入依赖的package包/类
@Test
public void authenticateNoSecondary() throws Exception {
final Authentication authentication = new UsernamePasswordAuthenticationToken("user1", "secret");
final Authentication authentication2 = new UsernamePasswordAuthenticationToken("user1v2", "secret");
final NodeBasedIamProvider provider = new NodeBasedIamProvider();
final IdentityServicePlugin servicePlugin = Mockito.mock(IdentityServicePlugin.class);
provider.configuration = configuration;
provider.servicePluginLocator = Mockito.mock(ServicePluginLocator.class);
Mockito.when(
provider.servicePluginLocator.getResourceExpected("service:id:ldap:dig", IdentityServicePlugin.class))
.thenReturn(servicePlugin);
Mockito.when(servicePlugin.authenticate(authentication, "service:id:ldap:dig", true))
.thenReturn(authentication2);
Assert.assertSame(authentication2, provider.authenticate(authentication));
}
示例7: getConfiguration
import org.ligoj.app.resource.ServicePluginLocator; //导入依赖的package包/类
@Test
public void getConfiguration() {
final NodeBasedIamProvider provider = new NodeBasedIamProvider();
provider.configuration = configuration;
provider.servicePluginLocator = Mockito.mock(ServicePluginLocator.class);
final IamConfiguration iamConfiguration = Mockito.mock(IamConfiguration.class);
final IamConfigurationProvider servicePlugin = Mockito.mock(IamConfigurationProvider.class);
Mockito.when(servicePlugin.getConfiguration("service:id:ldap:dig")).thenReturn(iamConfiguration);
Mockito.when(provider.servicePluginLocator.getResourceExpected("service:id:ldap:dig",
IamConfigurationProvider.class)).thenReturn(servicePlugin);
Assert.assertSame(iamConfiguration, provider.getConfiguration());
}
示例8: findAll
import org.ligoj.app.resource.ServicePluginLocator; //导入依赖的package包/类
@Test
public void findAll() {
final ImportCatalogResource resource = newResource();
// Add importable provider
resource.locator = Mockito.mock(ServicePluginLocator.class);
final ImportCatalogService service = Mockito.mock(ImportCatalogService.class);
Mockito.when(resource.locator.getResource("service:prov:test", ImportCatalogService.class)).thenReturn(service);
// Add not updatable provider node
final Node notImportNode = new Node();
notImportNode.setId("service:prov:any");
notImportNode.setName("Cannot import");
notImportNode.setRefined(nodeRepository.findOneExpected("service:prov"));
nodeRepository.saveAndFlush(notImportNode);
final List<CatalogVo> catalogs = resource.findAll();
Assert.assertEquals(3, catalogs.size());
// This provider does not support catalog update
Assert.assertEquals(0, catalogs.get(0).getStatus().getNbInstancePrices().intValue());
Assert.assertNull(catalogs.get(0).getStatus().getEnd());
Assert.assertNull(catalogs.get(0).getStatus().getStart());
Assert.assertEquals("service:prov:any", catalogs.get(0).getNode().getId());
Assert.assertFalse(catalogs.get(0).isCanImport());
Assert.assertEquals(0, catalogs.get(0).getNbQuotes());
// This provider supports catalog update
Assert.assertNotNull(catalogs.get(1).getStatus());
Assert.assertEquals("service:prov:test", catalogs.get(1).getNode().getId());
Assert.assertTrue(catalogs.get(1).isCanImport());
Assert.assertEquals(2, catalogs.get(1).getNbQuotes());
// This provider does not support catalog update
Assert.assertEquals("service:prov:x", catalogs.get(2).getNode().getId());
Assert.assertFalse(catalogs.get(2).isCanImport());
Assert.assertNull(catalogs.get(2).getStatus().getEnd());
Assert.assertNull(catalogs.get(2).getStatus().getStart());
Assert.assertEquals(1, catalogs.get(2).getNbQuotes());
final ImportCatalogStatus status = catalogs.get(1).getStatus();
Assert.assertEquals(DEFAULT_USER, status.getAuthor());
Assert.assertNull(status.getEnd());
Assert.assertNull(status.getLocation());
Assert.assertEquals("service:prov:test", status.getLocked().getId());
Assert.assertNotNull(status.getStart());
Assert.assertEquals(0, status.getDone());
Assert.assertEquals(0, status.getWorkload());
}
示例9: newResource
import org.ligoj.app.resource.ServicePluginLocator; //导入依赖的package包/类
private TerraformResource newResource(final Terraforming providerResource, final BiFunction<Subscription, String[], File> toFile,
final boolean dryRun, final String... customArgs) {
final TerraformResource resource = new TerraformResource() {
@Override
protected File toFile(final Subscription subscription, final String file) throws IOException {
return toFile.apply(subscription, new String[] { file });
}
/**
* Prepare the Terraform environment to apply the new environment. Note there is
* no concurrency check.
*/
@Override
protected File applyTerraform(final Subscription entity, final Terraforming terra, final QuoteVo configuration)
throws IOException, InterruptedException {
if (dryRun) {
// Ignore this call
return null;
}
return super.applyTerraform(entity, terra, configuration);
}
};
super.applicationContext.getAutowireCapableBeanFactory().autowireBean(resource);
// Replace the plugin locator
final ServicePluginLocator locator = Mockito.mock(ServicePluginLocator.class);
resource.locator = locator;
// Replace the runner
resource.runner = new TerraformRunnerResource();
super.applicationContext.getAutowireCapableBeanFactory().autowireBean(resource.runner);
Mockito.when(locator.getResource("service:prov:test:account", Terraforming.class)).thenReturn(providerResource);
// Replace the CLI runner
resource.terraformUtils = new TerraformUtils() {
@Override
protected ProcessBuilder newBuilder(String... args) {
return new ProcessBuilder(
ArrayUtils.addAll(new String[] { "java", "-cp", MOCK_PATH.getParent(), "org.ligoj.app.plugin.prov.terraform.Main" },
customArgs.length > 0 ? customArgs : args));
}
};
return resource;
}