use of org.ligoj.app.model.Subscription in project plugin-prov by ligoj.
the class TerraformResourceTest method applyTerraformError.
/**
* 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 {
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);
}
use of org.ligoj.app.model.Subscription in project plugin-vm by ligoj.
the class VmScheduleResource method checkAndSave.
private VmSchedule checkAndSave(final int subscription, final VmScheduleVo schedule, final VmSchedule entity) {
// Check the subscription is visible
final Subscription subscriptionEntity = subscriptionResource.checkVisibleSubscription(subscription);
if (schedule.getCron().split(" ").length == 6) {
// Add the missing "seconds" part
schedule.setCron(schedule.getCron() + " *");
}
// Check expressions first
if (!CronExpression.isValidExpression(schedule.getCron())) {
throw new ValidationJsonException("cron", "vm-cron");
}
// Every second is not accepted
if (schedule.getCron().startsWith("* ")) {
throw new ValidationJsonException("cron", "vm-cron-second");
}
entity.setSubscription(subscriptionEntity);
entity.setOperation(schedule.getOperation());
entity.setCron(schedule.getCron());
// Persist the new schedules for each provided CRON
repository.saveAndFlush(entity);
return entity;
}
use of org.ligoj.app.model.Subscription in project plugin-vm by ligoj.
the class VmResourceTest method delete.
@Test
public void delete() throws SchedulerException {
final Project project = new Project();
project.setName("TEST");
project.setPkey("test");
em.persist(project);
final Subscription subscription = new Subscription();
subscription.setProject(project);
subscription.setNode(nodeRepository.findOneExpected("service:vm"));
em.persist(subscription);
Assertions.assertEquals(1, subscriptionRepository.findAllByProject(project.getId()).size());
em.flush();
em.clear();
resource.delete(subscription.getId(), false);
subscriptionRepository.delete(subscription);
em.flush();
em.clear();
Assertions.assertEquals(0, subscriptionRepository.findAllByProject(project.getId()).size());
Assertions.assertEquals(0, vmScheduleRepository.findBySubscription(subscription.getId()).size());
Assertions.assertEquals(0, vmExecutionRepository.findAllBy("subscription.id", subscription.getId()).size());
}
use of org.ligoj.app.model.Subscription in project plugin-vm by ligoj.
the class VmResourceTest method executeDefault.
/**
* Coverage only
*/
@Test
public void executeDefault() throws Exception {
final VmExecution execution = new VmExecution();
final Subscription subscription = new Subscription();
subscription.setId(1);
execution.setSubscription(subscription);
new VmServicePlugin() {
@Override
public String getKey() {
return null;
}
@Override
public Vm getVmDetails(Map<String, String> parameters) throws Exception {
return null;
}
}.execute(execution);
}
use of org.ligoj.app.model.Subscription in project plugin-vm by ligoj.
the class VmResourceTest method executeUnavailablePlugin.
@Test
public void executeUnavailablePlugin() throws Exception {
final VmResource resource = new VmResource();
final Subscription entity = subscriptionRepository.findOneExpected(subscription);
final Node node = new Node();
node.setId("_deleted_plugin_");
node.setName("any");
nodeRepository.saveAndFlush(node);
entity.setNode(node);
subscriptionRepository.saveAndFlush(entity);
applicationContext.getAutowireCapableBeanFactory().autowireBean(resource);
resource.locator = mockServicePluginLocator;
final Integer id = resource.execute(entity, VmOperation.OFF);
// Execution is logged but failed
final VmExecution execution = vmExecutionRepository.findOneExpected(id);
Assertions.assertNull(execution.getVm());
Assertions.assertNull(execution.getVm());
Assertions.assertFalse(execution.isSucceed());
Assertions.assertEquals("fdaugan", execution.getTrigger());
Assertions.assertEquals(VmOperation.OFF, execution.getOperation());
Assertions.assertEquals("Plugin issue for _deleted_plugin_:Not found", execution.getError());
}
Aggregations