use of org.ligoj.app.plugin.prov.model.ProvUsage in project plugin-prov by ligoj.
the class ProvQuoteUsageResourceTest method updateAttachedInstance.
@Test
public void updateAttachedInstance() {
attachUsageToQuote();
// Usage -> 50% (attach the quote to a 50% usage)
final QuoteEditionVo quote = new QuoteEditionVo();
quote.setName("any");
quote.setLocation("region-1");
quote.setUsage("Dev");
checkCost(resource.update(subscription, quote), 1802.425, 3666.425, false);
checkCost(subscription, 1802.425, 3666.425, false);
em.flush();
em.clear();
// Usage -> 75% (update the usage's rate from 50% to 75%)
final UsageEditionVo usage = new UsageEditionVo();
usage.setName("DevV2");
usage.setRate(75);
checkCost(uResource.update(subscription, "Dev", usage).getTotalCost(), 2483.913, 4640.713, false);
checkCost(subscription, 2483.913, 4640.713, false);
final ProvUsage entity = usageRepository.findByName("DevV2");
Assertions.assertEquals("DevV2", entity.getName());
Assertions.assertEquals(subscription, entity.getConfiguration().getSubscription().getId().intValue());
Assertions.assertEquals(75, entity.getRate().intValue());
}
use of org.ligoj.app.plugin.prov.model.ProvUsage in project plugin-prov by ligoj.
the class ProvQuoteUsageResourceTest method updateRateAndQuote.
@Test
public void updateRateAndQuote() {
// Usage = 100%
checkCost(resource.refresh(subscription), 3165.4, 5615.0, false);
// Usage -> 50% (attach the quote to a 50% usage)
final QuoteEditionVo quote = new QuoteEditionVo();
quote.setName("any");
quote.setLocation("region-1");
quote.setUsage("Dev");
// Min = (3165.4 - 322.33 - 175.2[1y term])*.5 + 322.33 + 91.25 [1y term]
checkCost(resource.update(subscription, quote), 1743.865, 3607.865, false);
checkCost(subscription, 1743.865, 3607.865, false);
em.flush();
em.clear();
// Usage -> 75% (update the usage's rate from 50% to 75%)
UsageEditionVo usage = new UsageEditionVo();
usage.setName("DevV2");
usage.setRate(75);
// Min = (3165.4 - 322.33 - 175.2[1y term])*.75 + 322.33 + 91.25 [1y term]
checkCost(uResource.update(subscription, "Dev", usage).getTotalCost(), 2454.633, 4611.433, false);
checkCost(subscription, 2454.633, 4611.433, false);
em.flush();
em.clear();
// Usage back to -> 100%
usage.setRate(100);
checkCost(uResource.update(subscription, "DevV2", usage).getTotalCost(), 3165.4, 5615.0, false);
resource.refresh(subscription);
// Usage -> duration extended to 12 month, the term is updated, cheapest monthly bill
usage.setDuration(12);
uResource.update(subscription, "DevV2", usage);
checkCost(resource.refresh(subscription), 2982.4, 5139.2, false);
final ProvUsage entity = usageRepository.findByName("DevV2");
Assertions.assertEquals(subscription, entity.getConfiguration().getSubscription().getId().intValue());
Assertions.assertEquals("DevV2", entity.getName());
Assertions.assertEquals(subscription, entity.getConfiguration().getSubscription().getId().intValue());
Assertions.assertEquals(100, entity.getRate().intValue());
Assertions.assertEquals(12, entity.getDuration().intValue());
}
use of org.ligoj.app.plugin.prov.model.ProvUsage in project plugin-prov by ligoj.
the class ProvQuoteUsageResourceTest method create.
@Test
public void create() {
final UsageEditionVo usage = new UsageEditionVo();
usage.setName("DevV2");
usage.setRate(75);
final int id = uResource.create(subscription, usage);
checkCost(subscription, 4704.758, 7154.358, false);
resource.refresh(subscription);
checkCost(subscription, 3165.4, 5615.0, false);
final ProvUsage entity = usageRepository.findByName("DevV2");
Assertions.assertEquals("DevV2", entity.getName());
Assertions.assertEquals(id, entity.getId().intValue());
Assertions.assertEquals(subscription, entity.getConfiguration().getSubscription().getId().intValue());
Assertions.assertEquals(75, entity.getRate().intValue());
Assertions.assertEquals(12, entity.getConfiguration().getUsages().size());
entity.getConfiguration().setUsages(Collections.emptyList());
}
use of org.ligoj.app.plugin.prov.model.ProvUsage in project plugin-prov-azure by ligoj.
the class ProvAzurePriceImportResourceTest method prepareData.
@BeforeEach
public void prepareData() throws IOException {
persistSystemEntities();
persistEntities("csv", new Class[] { Node.class, Project.class, CacheCompany.class, CacheUser.class, DelegateNode.class, Parameter.class, ProvLocation.class, Subscription.class, ParameterValue.class, ProvQuote.class }, StandardCharsets.UTF_8.name());
this.subscription = getSubscription("gStack");
// Disable inner transaction
this.resource = new ProvAzurePriceImportResource();
applicationContext.getAutowireCapableBeanFactory().autowireBean(resource);
this.resource.initRate();
this.resource.initVmTenancy();
this.resource.initRegion();
this.resource.setImportCatalogResource(new ImportCatalogResource());
applicationContext.getAutowireCapableBeanFactory().autowireBean(this.resource.getImportCatalogResource());
configuration.delete(ProvAzurePriceImportResource.CONF_REGIONS);
initSpringSecurityContext(DEFAULT_USER);
resetImportTask();
final ProvUsage usage = new ProvUsage();
usage.setName("36month");
usage.setRate(100);
usage.setDuration(36);
usage.setConfiguration(repository.findBy("subscription.id", subscription));
em.persist(usage);
em.flush();
em.clear();
}
Aggregations