コード例 #1
0
 /** data set without columns can't create import table */
 @Test(expectedExceptions = NoColumnsException.class)
 public void emptyDataSetTable() {
   DataSet dataSet =
       new DataSetImpl(
           service, builder.buildDataSetNode(id, name, description, owner, lastChange));
   dataSet.createDataTable();
 }
コード例 #2
0
  /** data set attributes can load values just like report attributes */
  @Test
  public void loadAttributeValues() {
    ObjectNode node = builder.buildDataSetNode(dataSetId, name, description, owner, lastChange);
    node.put(
        "attributes",
        new ObjectMapper()
            .createArrayNode()
            .add(builder.buildAttributeNode(id, name, code, "string")));
    server.register(dataSetsUri + "/" + dataSetId, node.toString());
    DataSet dataSet = service.loadDataSet(dataSetId);
    Attribute attribute = dataSet.getAttributes().get(0);

    String label = "label";
    String value = "value";
    final ObjectNode valueNode = new ObjectMapper().createObjectNode();
    valueNode.put(
        "values",
        new ObjectMapper().createArrayNode().add(builder.buildAttributeValueNode(label, value)));

    server.register(
        dataSetsUri + "/" + dataSetId + "/attributes/" + code + "/values", valueNode.toString());

    List<AttributeValue> values = attribute.getValues().load().get();
    assertEquals(values.size(), 1);

    assertEquals(values.get(0).getLabel(), label);
    assertEquals(values.get(0).getValue(), value);

    assertEquals(attribute.toString(), name);
    assertEquals(values.get(0).toString(), label);
  }
コード例 #3
0
  /** Empty attributes array means no attributes. */
  public void attributesEmpty() {
    ObjectNode node = builder.buildDataSetNode(dataSetId, name, description, owner, lastChange);
    node.put("attributes", new ObjectMapper().createArrayNode());
    server.register(dataSetsUri + "/" + dataSetId, node.toString());
    DataSet dataSet = service.loadDataSet(dataSetId);

    assertEquals(dataSet.getAttributes(), Collections.emptyList());
  }
コード例 #4
0
  /** No attributes field means no attributes. */
  public void attributesMissing() {
    server.register(
        dataSetsUri + "/" + dataSetId,
        builder.buildDataSetNode(dataSetId, name, description, owner, lastChange).toString());
    DataSet dataSet = service.loadDataSet(dataSetId);

    assertEquals(dataSet.getAttributes(), Collections.emptyList());
  }
コード例 #5
0
  /** Invalid indicators are ignored. */
  @Test(dataProvider = "invalidIndicators")
  public void indicatorInvalid(JsonNode indicator) {
    ObjectNode node = builder.buildDataSetNode(dataSetId, name, description, owner, lastChange);
    node.put("indicators", new ObjectMapper().createArrayNode().add(indicator));
    server.register(dataSetsUri + "/" + dataSetId, node.toString());
    DataSet dataSet = service.loadDataSet(dataSetId);

    assertEquals(dataSet.getIndicators(), Collections.emptyList());
  }
コード例 #6
0
  /** Valid attribute types are parsed correctly. */
  @Test(dataProvider = "attributeTypes")
  public void attributeTypes(String jsonType, AttributeType type) {
    ObjectNode node = builder.buildDataSetNode(dataSetId, name, description, owner, lastChange);
    node.put(
        "attributes",
        new ObjectMapper()
            .createArrayNode()
            .add(builder.buildAttributeNode(id, name, code, jsonType)));
    server.register(dataSetsUri + "/" + dataSetId, node.toString());
    DataSet dataSet = service.loadDataSet(dataSetId);

    assertEquals(dataSet.getAttributes().size(), 1);

    Attribute attribute = dataSet.getAttributes().get(0);
    assertEquals(attribute.getId(), id);
    assertEquals(attribute.getName(), name);
    assertEquals(attribute.getCode(), code);
    assertEquals(attribute.getType(), type);
  }
コード例 #7
0
  /** Indicator groups are parsed correctly. */
  public void groupIndicator() {
    ObjectNode node = builder.buildDataSetNode(dataSetId, name, description, owner, lastChange);
    node.put(
        "indicators",
        new ObjectMapper()
            .createArrayNode()
            .add(builder.buildIndicatorNode(id, name, code, formula, "indicator_group")));
    server.register(dataSetsUri + "/" + dataSetId, node.toString());
    DataSet dataSet = service.loadDataSet(dataSetId);

    assertEquals(dataSet.getIndicators().size(), 1);

    Indicator indicator = dataSet.getIndicators().get(0);
    assertEquals(indicator.getId(), id);
    assertEquals(indicator.getName(), name);
    assertEquals(indicator.getCode(), null);
    assertEquals(indicator.getFormula(), null);
    assertEquals(indicator.getType(), IndicatorType.GROUP);
  }