use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.
the class GeoJsonAttributesCheckTest method setUpTest.
@BeforeEach
public void setUpTest() {
organisationUnit = new OrganisationUnit();
organisationUnit.setName("A");
attribute = new Attribute();
attribute.setUid("geoJson");
attribute.setName("geoJson");
validationContext = Mockito.mock(ValidationContext.class);
Schema schema = new Schema(OrganisationUnit.class, "organisationUnit", "organisationUnits");
Property property = new Property();
property.setPersisted(true);
schema.getPropertyMap().put("attributeValues", property);
SchemaService schemaService = Mockito.mock(SchemaService.class);
when(schemaService.getDynamicSchema(OrganisationUnit.class)).thenReturn(schema);
when(validationContext.getSchemaService()).thenReturn(schemaService);
Preheat preheat = Mockito.mock(Preheat.class);
when(preheat.getAttributeIdsByValueType(OrganisationUnit.class, ValueType.GEOJSON)).thenReturn(Sets.newSet("geoJson"));
objectBundle = Mockito.mock(ObjectBundle.class);
when(objectBundle.getPreheat()).thenReturn(preheat);
}
use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.
the class MetadataExportControllerUtilsTest method getWithDependenciesAsDownload.
@Test
void getWithDependenciesAsDownload() {
final Map<String, List<String>> parameterValuesMap = new HashMap<>();
final MetadataExportParams exportParams = new MetadataExportParams();
final Attribute attribute = new Attribute();
final ObjectNode rootNode = JacksonObjectMapperConfig.jsonMapper.createObjectNode();
Mockito.when(contextService.getParameterValuesMap()).thenReturn(parameterValuesMap);
Mockito.when(exportService.getParamsFromMap(Mockito.same(parameterValuesMap))).thenReturn(exportParams);
Mockito.when(exportService.getMetadataWithDependenciesAsNode(Mockito.same(attribute), Mockito.same(exportParams))).thenReturn(rootNode);
final ResponseEntity<JsonNode> responseEntity = MetadataExportControllerUtils.getWithDependencies(contextService, exportService, attribute, true);
Assertions.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
Assertions.assertSame(rootNode, responseEntity.getBody());
Assertions.assertEquals("attachment; filename=metadata", responseEntity.getHeaders().getFirst(HttpHeaders.CONTENT_DISPOSITION));
}
use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.
the class MetadataExportControllerUtilsTest method getWithDependencies.
@Test
void getWithDependencies() {
final Map<String, List<String>> parameterValuesMap = new HashMap<>();
final MetadataExportParams exportParams = new MetadataExportParams();
final Attribute attribute = new Attribute();
final ObjectNode rootNode = JacksonObjectMapperConfig.jsonMapper.createObjectNode();
Mockito.when(contextService.getParameterValuesMap()).thenReturn(parameterValuesMap);
Mockito.when(exportService.getParamsFromMap(Mockito.same(parameterValuesMap))).thenReturn(exportParams);
Mockito.when(exportService.getMetadataWithDependenciesAsNode(Mockito.same(attribute), Mockito.same(exportParams))).thenReturn(rootNode);
final ResponseEntity<JsonNode> responseEntity = MetadataExportControllerUtils.getWithDependencies(contextService, exportService, attribute, false);
Assertions.assertEquals(HttpStatus.OK, responseEntity.getStatusCode());
Assertions.assertSame(rootNode, responseEntity.getBody());
Assertions.assertFalse(responseEntity.getHeaders().containsKey(HttpHeaders.CONTENT_DISPOSITION));
}
use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.
the class DataElementStoreTest method testDataElementByUniqueAttributeValue.
@Test
public void testDataElementByUniqueAttributeValue() throws NonUniqueAttributeValueException {
Attribute attribute = new Attribute("cid", ValueType.TEXT);
attribute.setDataElementAttribute(true);
attribute.setUnique(true);
attributeService.addAttribute(attribute);
DataElement dataElementA = createDataElement('A');
DataElement dataElementB = createDataElement('B');
DataElement dataElementC = createDataElement('C');
dataElementStore.save(dataElementA);
dataElementStore.save(dataElementB);
dataElementStore.save(dataElementC);
AttributeValue attributeValueA = new AttributeValue("CID1", attribute);
AttributeValue attributeValueB = new AttributeValue("CID2", attribute);
AttributeValue attributeValueC = new AttributeValue("CID3", attribute);
attributeService.addAttributeValue(dataElementA, attributeValueA);
attributeService.addAttributeValue(dataElementB, attributeValueB);
attributeService.addAttributeValue(dataElementC, attributeValueC);
dataElementStore.update(dataElementA);
dataElementStore.update(dataElementB);
dataElementStore.update(dataElementC);
assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID1"));
assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID2"));
assertNotNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID3"));
assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID4"));
assertNull(dataElementStore.getByUniqueAttributeValue(attribute, "CID5"));
assertEquals("DataElementA", dataElementStore.getByUniqueAttributeValue(attribute, "CID1").getName());
assertEquals("DataElementB", dataElementStore.getByUniqueAttributeValue(attribute, "CID2").getName());
assertEquals("DataElementC", dataElementStore.getByUniqueAttributeValue(attribute, "CID3").getName());
}
use of org.hisp.dhis.attribute.Attribute in project dhis2-core by dhis2.
the class DataElementStoreTest method testAttributeValueFromAttribute.
@Test
public void testAttributeValueFromAttribute() throws NonUniqueAttributeValueException {
Attribute attribute = new Attribute("test", ValueType.TEXT);
attribute.setDataElementAttribute(true);
attributeService.addAttribute(attribute);
DataElement dataElementA = createDataElement('A');
DataElement dataElementB = createDataElement('B');
DataElement dataElementC = createDataElement('C');
dataElementStore.save(dataElementA);
dataElementStore.save(dataElementB);
dataElementStore.save(dataElementC);
AttributeValue attributeValueA = new AttributeValue("SOME VALUE", attribute);
AttributeValue attributeValueB = new AttributeValue("SOME VALUE", attribute);
AttributeValue attributeValueC = new AttributeValue("ANOTHER VALUE", attribute);
attributeService.addAttributeValue(dataElementA, attributeValueA);
attributeService.addAttributeValue(dataElementB, attributeValueB);
attributeService.addAttributeValue(dataElementC, attributeValueC);
dataElementStore.update(dataElementA);
dataElementStore.update(dataElementB);
dataElementStore.update(dataElementC);
List<AttributeValue> values = dataElementStore.getAttributeValueByAttribute(attribute);
assertEquals(3, values.size());
}
Aggregations