use of org.openlca.core.model.AbstractEntity in project olca-modules by GreenDelta.
the class BaseReferenceSearchTest method testAllReferencesSingleModel.
@Test
public void testAllReferencesSingleModel() {
AbstractEntity fullModel = createModel();
List<Reference> references = findReferences(Collections.singleton(fullModel.id));
Assert.assertNotNull(references);
for (Reference ref : expectedReferences) {
Reference reference = find(ref, references, fullModel.id);
String text = ref.getType().getName() + " " + ref.id + " not found";
Assert.assertNotNull(text, reference);
references.remove(reference);
}
for (Reference r : references) {
if (r.optional && r.id == 0)
continue;
Assert.fail("Unexpected: " + r.getType().getName() + " " + r.id);
}
}
use of org.openlca.core.model.AbstractEntity in project olca-modules by GreenDelta.
the class BaseParametrizedReferenceSearch method toReferences.
private List<Reference> toReferences(List<ParameterDescriptor> descriptors, boolean optional, Map<Long, Set<String>> names, Map<Long, Long> ownerIds, Class<? extends AbstractEntity> nestedType, String nestedProperty) {
Map<Long, Set<Long>> descriptorToOwnerIds = new HashMap<>();
for (ParameterDescriptor d : descriptors) {
for (long ownerId : names.keySet()) {
if (!names.get(ownerId).contains(d.name.toLowerCase()))
continue;
put(d.id, ownerId, descriptorToOwnerIds);
}
}
List<Reference> references = new ArrayList<>();
for (ParameterDescriptor descriptor : descriptors) {
Set<Long> set = descriptorToOwnerIds.get(descriptor.id);
if (set == null)
continue;
for (long ownerId : set) {
Class<? extends AbstractEntity> type = (Class<? extends AbstractEntity>) descriptor.type.getModelClass();
long id = descriptor.id;
long nestedOwnerId = 0;
if (ownerIds != null) {
nestedOwnerId = ownerId;
ownerId = ownerIds.get(ownerId);
}
Reference reference = new Reference(descriptor.name, type, id, this.type, ownerId, nestedProperty, nestedType, nestedOwnerId, optional);
references.add(reference);
}
}
return references;
}
use of org.openlca.core.model.AbstractEntity in project olca-modules by GreenDelta.
the class BaseReferenceSearchTest method testAllReferencesMultipleModel.
@Test
public void testAllReferencesMultipleModel() {
Set<Long> ids = new HashSet<>();
for (int i = 0; i < 3; i++) {
AbstractEntity fullModel = createModel();
referencesByOwner.put(fullModel.id, expectedReferences);
expectedReferences = new ArrayList<>();
ids.add(fullModel.id);
}
List<Reference> references = findReferences(ids);
Assert.assertNotNull(references);
for (long id : ids) {
List<Reference> refs = new ArrayList<>();
for (Reference reference : references) if (!isNestedSearchTest() && reference.ownerId == id)
refs.add(reference);
else if (isNestedSearchTest() && reference.nestedOwnerId == id)
refs.add(reference);
for (Reference ref : referencesByOwner.get(id)) {
Reference reference = find(ref, refs, id);
String text = ref.getType().getName() + " " + ref.id + " not found";
Assert.assertNotNull(text, reference);
refs.remove(reference);
}
for (Reference r : refs) {
if (r.optional && r.id == 0)
continue;
Assert.fail("Unexpected: " + r.getType().getName() + " " + r.id);
}
}
}
Aggregations