Search in sources :

Example 6 with ProvUsage

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());
}
Also used : ProvUsage(org.ligoj.app.plugin.prov.model.ProvUsage) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 7 with ProvUsage

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());
}
Also used : ProvUsage(org.ligoj.app.plugin.prov.model.ProvUsage) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 8 with ProvUsage

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());
}
Also used : ProvUsage(org.ligoj.app.plugin.prov.model.ProvUsage) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 9 with ProvUsage

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();
}
Also used : ProvUsage(org.ligoj.app.plugin.prov.model.ProvUsage) ImportCatalogResource(org.ligoj.app.plugin.prov.in.ImportCatalogResource) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ProvUsage (org.ligoj.app.plugin.prov.model.ProvUsage)9 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 Path (javax.ws.rs.Path)4 Test (org.junit.jupiter.api.Test)4 AbstractAppTest (org.ligoj.app.AbstractAppTest)4 ProvQuote (org.ligoj.app.plugin.prov.model.ProvQuote)4 Map (java.util.Map)3 Function (java.util.function.Function)3 Transactional (javax.transaction.Transactional)3 DELETE (javax.ws.rs.DELETE)3 GET (javax.ws.rs.GET)3 PUT (javax.ws.rs.PUT)3 PathParam (javax.ws.rs.PathParam)3 Produces (javax.ws.rs.Produces)3 Context (javax.ws.rs.core.Context)3 MediaType (javax.ws.rs.core.MediaType)3 UriInfo (javax.ws.rs.core.UriInfo)3 ProvUsageRepository (org.ligoj.app.plugin.prov.dao.ProvUsageRepository)3 TableItem (org.ligoj.bootstrap.core.json.TableItem)3