use of org.ligoj.app.model.Parameter in project ligoj-api by ligoj.
the class ParameterResourceTest method getNotProvidedParametersWithDependencies.
@Test
public void getNotProvidedParametersWithDependencies() {
// c_16->[c_10], c_10->[c_15, c8,c2], c8->c2, c2->[c7], c7->[c14]
repository.findOneExpected("c_16").getDepends().add(repository.findOneExpected("c_10"));
repository.findOneExpected("c_10").getDepends().add(repository.findOneExpected("c_15"));
repository.findOneExpected("c_10").getDepends().add(repository.findOneExpected("c_8"));
repository.findOneExpected("c_10").getDepends().add(repository.findOneExpected("c_2"));
repository.findOneExpected("c_8").getDepends().add(repository.findOneExpected("c_2"));
repository.findOneExpected("c_2").getDepends().add(repository.findOneExpected("c_7"));
repository.findOneExpected("c_7").getDepends().add(repository.findOneExpected("c_14"));
final List<ParameterVo> parameters = resource.getNotProvidedParameters("service:bt:jira:6", SubscriptionMode.LINK);
// Dependency order check
Assertions.assertTrue(indexOf("c_16", parameters) > indexOf("c_10", parameters));
Assertions.assertTrue(indexOf("c_10", parameters) > indexOf("c_15", parameters));
Assertions.assertTrue(indexOf("c_10", parameters) > indexOf("c_8", parameters));
Assertions.assertTrue(indexOf("c_10", parameters) > indexOf("c_2", parameters));
Assertions.assertTrue(indexOf("c_8", parameters) > indexOf("c_2", parameters));
Assertions.assertTrue(indexOf("c_7", parameters) > indexOf("c_14", parameters));
Assertions.assertTrue(indexOf("c_2", parameters) > indexOf("c_7", parameters));
Assertions.assertTrue(indexOf("c_8", parameters) > indexOf("c_2", parameters));
// Natural order check
Assertions.assertTrue(indexOf("c_12", parameters) > indexOf("c_11", parameters));
Assertions.assertTrue(indexOf("c_18", parameters) > indexOf("c_17", parameters));
// Coverage only
new Parameter().setDepends(Collections.emptyList());
}
use of org.ligoj.app.model.Parameter in project ligoj-api by ligoj.
the class NodeResource method toVoParameters.
/**
* JPA {@link Node} associated to {@link ParameterValue} to detailed {@link NodeVo} converter. This not a one to one
* {@link Function}.
*
* @param nodesAndValues
* Nodes with values.
* @return The corresponding VO objects with recursive redefined reference.
*/
public static Map<String, NodeVo> toVoParameters(final List<Object[]> nodesAndValues) {
// Build the nodes
final Map<String, NodeVo> nodes = new HashMap<>();
final Map<String, Node> entities = new HashMap<>();
for (final Object[] resultSet : nodesAndValues) {
final Node node = (Node) resultSet[0];
final NodeVo vo = nodes.computeIfAbsent(node.getId(), id -> {
// Build the first encountered parameter for this node
entities.put(id, node);
return toVoParameter(node);
});
// Copy the parameter value if present
Optional.ofNullable((ParameterValue) resultSet[1]).ifPresent(v -> vo.getParameters().put(v.getParameter().getId(), ParameterValueResource.parseValue(v, new ParameterValueVo())));
}
// Complete the hierarchy
entities.entrySet().stream().filter(entry -> entry.getValue().isRefining()).forEach(entry -> {
// Complete the hierarchy for this node
final NodeVo node = nodes.get(entry.getKey());
final NodeVo parent = nodes.get(entry.getValue().getRefined().getId());
node.setRefined(parent);
node.getParameters().putAll(parent.getParameters());
});
return nodes;
}
use of org.ligoj.app.model.Parameter in project ligoj-api by ligoj.
the class ParameterValueResourceTest method checkOwnership.
@Test
public void checkOwnership() {
final Node node = new Node();
node.setId("service:id");
final Parameter parameter = new Parameter();
parameter.setOwner(node);
final Node node2 = new Node();
node2.setId("service:id:sub");
node2.setRefined(node);
resource.checkOwnership(parameter, node2);
}
use of org.ligoj.app.model.Parameter in project ligoj-api by ligoj.
the class ParameterValueResourceTest method findInvalidJSonData.
@Test
public void findInvalidJSonData() {
final Parameter parameter = parameterRepository.findOne("c_22");
final ParameterValue parameterValueEntity = newParameterValue("'", parameter);
Assertions.assertThrows(TechnicalException.class, () -> {
resource.toVo(parameterValueEntity);
});
}
use of org.ligoj.app.model.Parameter in project ligoj-api by ligoj.
the class ParameterValueResourceTest method findInteger.
@Test
public void findInteger() {
final Parameter parameter = parameterRepository.findOne("c_4");
final ParameterValue parameterValueEntity = newParameterValue("1", parameter);
em.persist(parameterValueEntity);
em.flush();
final ParameterValueVo valueVo = resource.toVo(parameterValueEntity);
Assertions.assertEquals(parameter.getId(), valueVo.getParameter().getId());
Assertions.assertEquals(1, valueVo.getInteger().intValue());
Assertions.assertNotNull(valueVo.getCreatedDate());
Assertions.assertNotNull(valueVo.getCreatedBy());
}
Aggregations