Search in sources :

Example 11 with ProvQuoteInstance

use of org.ligoj.app.plugin.prov.model.ProvQuoteInstance in project plugin-prov by ligoj.

the class ProvQuoteInstanceResourceTest method updateInstanceOsCompatible.

@Test
public void updateInstanceOsCompatible() {
    final QuoteInstanceEditionVo vo = new QuoteInstanceEditionVo();
    vo.setSubscription(subscription);
    vo.setId(qiRepository.findByNameExpected("server2").getId());
    vo.setPrice(ipRepository.findByExpected("code", "C9").getId());
    vo.setName("server2-bis");
    vo.setOs(VmOs.CENTOS);
    vo.setRam(1024);
    vo.setCpu(0.5);
    qiResource.update(vo);
    final ProvQuoteInstance instance = qiRepository.findOneExpected(vo.getId());
    Assertions.assertEquals(VmOs.CENTOS, instance.getOs());
}
Also used : ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 12 with ProvQuoteInstance

use of org.ligoj.app.plugin.prov.model.ProvQuoteInstance in project plugin-prov by ligoj.

the class ProvQuoteInstanceResourceTest method createInstance.

@Test
public void createInstance() {
    final QuoteInstanceEditionVo vo = new QuoteInstanceEditionVo();
    vo.setSubscription(subscription);
    vo.setPrice(ipRepository.findByExpected("code", "C10").getId());
    vo.setName("serverZ");
    vo.setDescription("serverZD");
    vo.setRam(1024);
    vo.setCpu(0.5);
    vo.setConstant(true);
    vo.setInternet(InternetAccess.PUBLIC);
    vo.setMaxVariableCost(210.9);
    vo.setEphemeral(true);
    vo.setMinQuantity(10);
    vo.setMaxQuantity(15);
    final UpdatedCost updatedCost = qiResource.create(vo);
    // Check the exact new cost
    checkCost(updatedCost.getTotalCost(), 6790.958, 10283.658, false);
    checkCost(updatedCost.getResourceCost(), 2086.2, 3129.3, false);
    Assertions.assertTrue(updatedCost.getRelatedCosts().isEmpty());
    checkCost(subscription, 6790.958, 10283.658, false);
    final ProvQuoteInstance instance = qiRepository.findOneExpected(updatedCost.getId());
    Assertions.assertEquals("serverZ", instance.getName());
    Assertions.assertTrue(instance.isEphemeral());
    Assertions.assertEquals("serverZD", instance.getDescription());
    Assertions.assertEquals(1024, instance.getRam().intValue());
    Assertions.assertEquals(0.5, instance.getCpu(), DELTA);
    Assertions.assertEquals(VmOs.WINDOWS, instance.getOs());
    Assertions.assertEquals(2086.2, instance.getCost(), DELTA);
    Assertions.assertEquals(3129.3, instance.getMaxCost(), DELTA);
    Assertions.assertTrue(instance.getConstant());
    Assertions.assertEquals(InternetAccess.PUBLIC, instance.getInternet());
    Assertions.assertEquals(210.9, instance.getMaxVariableCost(), DELTA);
    Assertions.assertEquals(10, instance.getMinQuantity().intValue());
    Assertions.assertEquals(15, instance.getMaxQuantity().intValue());
    Assertions.assertFalse(instance.isUnboundCost());
}
Also used : ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 13 with ProvQuoteInstance

use of org.ligoj.app.plugin.prov.model.ProvQuoteInstance in project plugin-prov by ligoj.

the class ProvQuoteInstanceResourceTest method uploadBoundQuantities.

@Test
public void uploadBoundQuantities() throws IOException {
    qiResource.upload(subscription, new ByteArrayInputStream("ANY;0.5;500;LINUX;1;true;1;1000;true".getBytes("UTF-8")), new String[] { "name", "cpu", "ram", "os", "disk", "constant", "minQuantity", "maxQuantity", "ephemeral" }, false, "Full Time 12 month", 1, "UTF-8");
    final QuoteVo configuration = resource.getConfiguration(subscription);
    Assertions.assertEquals(8, configuration.getInstances().size());
    final ProvQuoteInstance qi = configuration.getInstances().get(7);
    Assertions.assertEquals(1, qi.getMinQuantity().intValue());
    Assertions.assertTrue(qi.getPrice().getTerm().isEphemeral());
    Assertions.assertTrue(qi.getPrice().getTerm().isVariable());
    Assertions.assertEquals(1000, qi.getMaxQuantity().intValue());
    Assertions.assertEquals(5, configuration.getStorages().size());
    checkCost(configuration.getCost(), 4833.068, 135464.358, false);
    final Map<Integer, FloatingCost> storagesFloatingCost = toStoragesFloatingCost("ANY");
    Assertions.assertEquals(1, storagesFloatingCost.size());
    checkCost(storagesFloatingCost.values().iterator().next(), 0.21, 210, false);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 14 with ProvQuoteInstance

use of org.ligoj.app.plugin.prov.model.ProvQuoteInstance in project plugin-prov by ligoj.

the class ProvQuoteInstanceResourceTest method createUnboundInstance.

@Test
public void createUnboundInstance() {
    final QuoteInstanceEditionVo vo = new QuoteInstanceEditionVo();
    vo.setSubscription(subscription);
    vo.setPrice(ipRepository.findByExpected("code", "C10").getId());
    vo.setName("serverZ");
    vo.setRam(1024);
    vo.setCpu(0.5);
    vo.setMinQuantity(10);
    vo.setMaxQuantity(null);
    final UpdatedCost updatedCost = qiResource.create(vo);
    // Check the exact new cost
    checkCost(updatedCost.getTotalCost(), 6790.958, 9240.558, true);
    checkCost(updatedCost.getResourceCost(), 2086.2, 2086.2, true);
    Assertions.assertTrue(updatedCost.getRelatedCosts().isEmpty());
    checkCost(subscription, 6790.958, 9240.558, true);
    final ProvQuoteInstance instance = qiRepository.findOneExpected(updatedCost.getId());
    Assertions.assertNull(instance.getMaxVariableCost());
    Assertions.assertEquals(10, instance.getMinQuantity().intValue());
    Assertions.assertNull(instance.getMaxQuantity());
    Assertions.assertTrue(instance.isUnboundCost());
}
Also used : ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 15 with ProvQuoteInstance

use of org.ligoj.app.plugin.prov.model.ProvQuoteInstance in project plugin-prov by ligoj.

the class ProvQuoteUsageResourceTest method attachUsageToQuote.

private void attachUsageToQuote() {
    // Usage = 100%
    checkCost(resource.refresh(subscription), 3165.4, 5615.0, false);
    // Usage = 100% by default, but fixed for some instances
    final ProvQuoteInstance server1 = qiRepository.findByName("server1");
    server1.setUsage(usageRepository.findByName("Dev"));
    em.persist(server1);
    final ProvQuoteInstance server2 = qiRepository.findByName("server2");
    server2.setUsage(usageRepository.findByName("Full Time"));
    em.persist(server2);
    em.flush();
    em.clear();
    checkCost(resource.refresh(subscription), 3019.0, 4883.0, false);
}
Also used : ProvQuoteInstance(org.ligoj.app.plugin.prov.model.ProvQuoteInstance)

Aggregations

ProvQuoteInstance (org.ligoj.app.plugin.prov.model.ProvQuoteInstance)19 Test (org.junit.jupiter.api.Test)15 AbstractAppTest (org.ligoj.app.AbstractAppTest)14 ProvInstancePrice (org.ligoj.app.plugin.prov.model.ProvInstancePrice)5 ProvQuote (org.ligoj.app.plugin.prov.model.ProvQuote)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ProvQuoteStorage (org.ligoj.app.plugin.prov.model.ProvQuoteStorage)4 ProvInstanceType (org.ligoj.app.plugin.prov.model.ProvInstanceType)3 ProvLocation (org.ligoj.app.plugin.prov.model.ProvLocation)3 ProvStoragePrice (org.ligoj.app.plugin.prov.model.ProvStoragePrice)3 Optional (java.util.Optional)2 Function (java.util.function.Function)2 Transactional (javax.transaction.Transactional)2 Consumes (javax.ws.rs.Consumes)2 DELETE (javax.ws.rs.DELETE)2 DefaultValue (javax.ws.rs.DefaultValue)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2