Search in sources :

Example 11 with ParameterValue

use of org.ligoj.app.model.ParameterValue in project ligoj-api by ligoj.

the class ParameterValueResourceTest method newParameterValue.

/**
 * Create a new {@link ParameterValue} linked to a new {@link Node} without subscription.
 */
private ParameterValue newParameterValue() {
    final Node node = new Node();
    node.setName("create-test");
    node.setId("service:kpi:sonar:temp");
    node.setRefined(em.find(Node.class, "service:kpi:sonar"));
    em.persist(node);
    final ParameterValue value = new ParameterValue();
    value.setParameter(em.find(Parameter.class, "service:kpi:sonar:user"));
    value.setData("user");
    value.setNode(node);
    em.persist(value);
    em.flush();
    em.clear();
    return value;
}
Also used : ParameterValue(org.ligoj.app.model.ParameterValue) Node(org.ligoj.app.model.Node) Parameter(org.ligoj.app.model.Parameter)

Example 12 with ParameterValue

use of org.ligoj.app.model.ParameterValue in project ligoj-api by ligoj.

the class ParameterValueResourceTest method findWithNode.

@Test
public void findWithNode() {
    final Parameter parameter = parameterRepository.findOne("c_20");
    final ParameterValue parameterValueEntity = newParameterValue("true", parameter);
    parameterValueEntity.setNode(em.find(Node.class, "service:bt:jira:6"));
    em.persist(parameterValueEntity);
    em.flush();
    final ParameterValueVo valueVo = resource.toVo(parameterValueEntity);
    Assertions.assertEquals(parameter.getId(), valueVo.getParameter().getId());
    Assertions.assertEquals("service:bt:jira:6", valueVo.getNode().getId());
}
Also used : ParameterValue(org.ligoj.app.model.ParameterValue) Node(org.ligoj.app.model.Node) Parameter(org.ligoj.app.model.Parameter) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 13 with ParameterValue

use of org.ligoj.app.model.ParameterValue in project ligoj-api by ligoj.

the class ParameterValueResourceTest method findTags.

@Test
public void findTags() {
    final Parameter parameter = parameterRepository.findOne("c_22");
    final ParameterValue parameterValueEntity = newParameterValue("[\"A\",\"B\"]", parameter);
    em.persist(parameterValueEntity);
    em.flush();
    final ParameterValueVo valueVo = resource.toVo(parameterValueEntity);
    Assertions.assertEquals(parameter.getId(), valueVo.getParameter().getId());
    Assertions.assertEquals("[A, B]", valueVo.getTags().toString());
    Assertions.assertNotNull(valueVo.getCreatedDate());
    Assertions.assertNotNull(valueVo.getCreatedBy());
}
Also used : ParameterValue(org.ligoj.app.model.ParameterValue) Parameter(org.ligoj.app.model.Parameter) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 14 with ParameterValue

use of org.ligoj.app.model.ParameterValue in project ligoj-api by ligoj.

the class ParameterValueResourceTest method createInteger.

@Test
public void createInteger() {
    final ParameterValueCreateVo parameterValue = new ParameterValueCreateVo();
    parameterValue.setParameter(parameterRepository.findOne("c_4").getId());
    parameterValue.setInteger(1);
    final ParameterValue entity = resource.createInternal(parameterValue);
    Assertions.assertEquals(parameterValue.getParameter(), entity.getParameter().getId());
    Assertions.assertEquals("1", entity.getData());
}
Also used : ParameterValue(org.ligoj.app.model.ParameterValue) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Example 15 with ParameterValue

use of org.ligoj.app.model.ParameterValue in project ligoj-api by ligoj.

the class ParameterValueResourceTest method createMultiple.

@Test
public void createMultiple() {
    final ParameterValueCreateVo parameterValue = new ParameterValueCreateVo();
    parameterValue.setParameter(parameterRepository.findOne("c_23").getId());
    final List<Integer> tags = new ArrayList<>();
    tags.add(1);
    tags.add(2);
    parameterValue.setSelections(tags);
    final ParameterValue entity = resource.createInternal(parameterValue);
    Assertions.assertEquals(parameterValue.getParameter(), entity.getParameter().getId());
    Assertions.assertEquals("[1,2]", entity.getData());
}
Also used : ParameterValue(org.ligoj.app.model.ParameterValue) ArrayList(java.util.ArrayList) AbstractAppTest(org.ligoj.app.AbstractAppTest) Test(org.junit.jupiter.api.Test)

Aggregations

ParameterValue (org.ligoj.app.model.ParameterValue)35 Test (org.junit.jupiter.api.Test)28 AbstractAppTest (org.ligoj.app.AbstractAppTest)27 Parameter (org.ligoj.app.model.Parameter)16 ArrayList (java.util.ArrayList)7 Node (org.ligoj.app.model.Node)6 HashMap (java.util.HashMap)5 Subscription (org.ligoj.app.model.Subscription)4 Date (java.util.Date)3 List (java.util.List)3 Map (java.util.Map)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 NodeStatus (org.ligoj.app.api.NodeStatus)3 NodeVo (org.ligoj.app.api.NodeVo)3 Collection (java.util.Collection)2 Entry (java.util.Map.Entry)2 Optional (java.util.Optional)2 BiFunction (java.util.function.BiFunction)2 CacheRemoveAll (javax.cache.annotation.CacheRemoveAll)2