use of org.molgenis.data.DataService in project molgenis by molgenis.
the class DataServiceTokenServiceTest method beforeMethod.
@BeforeMethod
public void beforeMethod() {
tokenGenerator = mock(TokenGenerator.class);
dataService = mock(DataService.class);
userDetailsService = mock(UserDetailsService.class);
TokenFactory tokenFactory = mock(TokenFactory.class);
when(tokenFactory.create()).thenAnswer(invocation -> mock(Token.class));
tokenService = new DataServiceTokenService(tokenGenerator, dataService, userDetailsService, tokenFactory);
}
use of org.molgenis.data.DataService in project molgenis by molgenis.
the class PluginInterceptorTest method createMolgenisPluginController.
private PluginController createMolgenisPluginController(String uri) {
PluginController pluginController = new PluginController(uri) {
};
DataService dataService = mock(DataService.class);
pluginController.setDataService(dataService);
return pluginController;
}
use of org.molgenis.data.DataService in project molgenis by molgenis.
the class PostgreSqlQueryUtils method isPersistedInPostgreSql.
/**
* Returns whether the given entity is persisted in PostgreSQL
*
* @param entityType entity meta data
* @return true is the entity is persisted in PostgreSQL
*/
static boolean isPersistedInPostgreSql(EntityType entityType) {
String backend = entityType.getBackend();
if (backend == null) {
// TODO remove this check after getBackend always returns the backend
if (null != getApplicationContext()) {
DataService dataService = getApplicationContext().getBean(DataService.class);
backend = dataService.getMeta().getDefaultBackend().getName();
} else {
// A workaround for the integration tests. getApplicationContext() should not be null
return true;
}
}
return backend.equals(PostgreSqlRepositoryCollection.POSTGRESQL);
}
use of org.molgenis.data.DataService in project molgenis by molgenis.
the class DataPersisterImplTest method setUpBeforeMethod.
@SuppressWarnings("unchecked")
@BeforeMethod
public void setUpBeforeMethod() {
dataService = mock(DataService.class, RETURNS_DEEP_STUBS);
dataPersisterImpl = new DataPersisterImpl(metaDataService, dataService, entityTypeDependencyResolver);
String entityTypeId0 = "entityTypeId0";
entityType0 = mock(EntityType.class);
when(entityType0.getId()).thenReturn(entityTypeId0).getMock();
String entityTypeId1 = "entityTypeId1";
entityType1 = mock(EntityType.class);
when(entityType1.getId()).thenReturn(entityTypeId1).getMock();
String entityTypeId2 = "entityTypeId2";
entityType2 = mock(EntityType.class);
when(entityType2.getId()).thenReturn(entityTypeId2).getMock();
when(dataProvider.getEntityTypes()).thenReturn(Stream.of(entityType0, entityType1, entityType2));
when(dataProvider.hasEntities(entityType0)).thenReturn(true);
Entity entity0a = mock(Entity.class);
Entity entity0b = mock(Entity.class);
when(dataProvider.getEntities(entityType0)).thenReturn(Stream.of(entity0a, entity0b));
when(dataProvider.hasEntities(entityType1)).thenReturn(true);
Entity entity1a = mock(Entity.class);
Entity entity1b = mock(Entity.class);
Entity entity1c = mock(Entity.class);
when(dataProvider.getEntities(entityType1)).thenReturn(Stream.of(entity1a, entity1b, entity1c));
when(dataProvider.hasEntities(entityType2)).thenReturn(false);
when(entityTypeDependencyResolver.resolve(asList(entityType0, entityType1, entityType2))).thenReturn(asList(entityType2, entityType1, entityType0));
doAnswer(invocation -> {
Stream<Entity> entityStream = (Stream<Entity>) invocation.getArguments()[1];
try {
// noinspection ResultOfMethodCallIgnored
entityStream.collect(toList());
} catch (IllegalStateException ignored) {
}
return null;
}).when(dataService).add(anyString(), any(Stream.class));
doAnswer(invocation -> {
Stream<Entity> entityStream = (Stream<Entity>) invocation.getArguments()[1];
try {
// noinspection ResultOfMethodCallIgnored
entityStream.collect(toList());
} catch (IllegalStateException ignored) {
}
return null;
}).when(dataService).update(anyString(), any(Stream.class));
}
use of org.molgenis.data.DataService in project molgenis by molgenis.
the class OneToManyCategoryAlgorithmGeneratorTest method init.
@BeforeMethod
public void init() {
DataService dataService = Mockito.mock(DataService.class);
categoryAlgorithmGenerator = new OneToManyCategoryAlgorithmGenerator(dataService);
EntityType targetRefEntityType = entityTypeFactory.create("POTATO_REF");
Attribute targetCodeAttribute = attrMetaFactory.create().setName("code").setDataType(INT);
Attribute targetLabelAttribute = attrMetaFactory.create().setName("label");
targetRefEntityType.addAttribute(targetCodeAttribute, ROLE_ID);
targetRefEntityType.addAttribute(targetLabelAttribute, ROLE_LABEL);
targetAttribute = attrMetaFactory.create().setName("Current Consumption Frequency of Potatoes").setDataType(CATEGORICAL);
targetAttribute.setRefEntity(targetRefEntityType);
Entity targetEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Almost daily + daily"));
Entity targetEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "Several times a week"));
Entity targetEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "About once a week"));
Entity targetEntity4 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "Never + fewer than once a week"));
Entity targetEntity5 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "missing"));
Mockito.when(dataService.findAll(targetRefEntityType.getId())).thenAnswer(invocation -> Stream.of(targetEntity1, targetEntity2, targetEntity3, targetEntity4, targetEntity5));
targetEntityType = entityTypeFactory.create("target");
targetEntityType.addAttribute(targetAttribute);
EntityType sourceRefEntityType = createEntityType("LifeLines_POTATO_REF");
sourceAttribute = attrMetaFactory.create().setName("MESHED_POTATO").setDataType(CATEGORICAL);
sourceAttribute.setLabel("How often did you eat boiled or mashed potatoes (also in stew) in the past month? Baked potatoes are asked later");
sourceAttribute.setRefEntity(sourceRefEntityType);
Entity sourceEntity1 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "Not this month"));
Entity sourceEntity2 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "1 day per month"));
Entity sourceEntity3 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "2-3 days per month"));
Entity sourceEntity4 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "1 day per week"));
Entity sourceEntity5 = new DynamicEntity(targetRefEntityType, of("code", 5, "label", "2-3 days per week"));
Entity sourceEntity6 = new DynamicEntity(targetRefEntityType, of("code", 6, "label", "4-5 days per week"));
Entity sourceEntity7 = new DynamicEntity(targetRefEntityType, of("code", 7, "label", "6-7 days per week"));
Mockito.when(dataService.findAll(sourceRefEntityType.getId())).thenAnswer(invocation -> Stream.of(sourceEntity1, sourceEntity2, sourceEntity3, sourceEntity4, sourceEntity5, sourceEntity6, sourceEntity7));
EntityType sourceRefEntityType1 = createEntityType("Mitchelstown_POTATO_REF");
sourceAttribute1 = attrMetaFactory.create().setName("MESHED_POTATO_1").setDataType(CATEGORICAL);
sourceAttribute1.setLabel("How often did you eat boiled or mashed potatoes (also in stew) in the past month? Baked potatoes are asked later");
sourceAttribute1.setRefEntity(sourceRefEntityType1);
Entity sourceEntity8 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "never/less than 1 per month"));
Entity sourceEntity9 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "1-3 per month"));
Entity sourceEntity10 = new DynamicEntity(targetRefEntityType, of("code", 3, "label", "once a week"));
Entity sourceEntity11 = new DynamicEntity(targetRefEntityType, of("code", 4, "label", "2-4 per week"));
Entity sourceEntity12 = new DynamicEntity(targetRefEntityType, of("code", 5, "label", "5-6 per week"));
Entity sourceEntity13 = new DynamicEntity(targetRefEntityType, of("code", 6, "label", "once a day"));
Entity sourceEntity14 = new DynamicEntity(targetRefEntityType, of("code", 7, "label", "2-3 per day"));
Entity sourceEntity15 = new DynamicEntity(targetRefEntityType, of("code", 8, "label", "4-5 per day"));
Entity sourceEntity16 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "6+ per day"));
Mockito.when(dataService.findAll(sourceRefEntityType1.getId())).thenAnswer(invocation -> Stream.of(sourceEntity8, sourceEntity9, sourceEntity10, sourceEntity11, sourceEntity12, sourceEntity13, sourceEntity14, sourceEntity15, sourceEntity16));
EntityType sourceRefEntityType2 = createEntityType("Mitchelstown_Stroke_REF");
sourceAttribute2 = attrMetaFactory.create().setName("Stroke").setDataType(CATEGORICAL);
sourceAttribute2.setLabel("History of stroke");
sourceAttribute2.setRefEntity(sourceRefEntityType2);
Entity sourceEntity17 = new DynamicEntity(targetRefEntityType, of("code", 1, "label", "yes"));
Entity sourceEntity18 = new DynamicEntity(targetRefEntityType, of("code", 2, "label", "no"));
Entity sourceEntity19 = new DynamicEntity(targetRefEntityType, of("code", 9, "label", "missing"));
Mockito.when(dataService.findAll(sourceRefEntityType2.getId())).thenAnswer(invocation -> Stream.of(sourceEntity17, sourceEntity18, sourceEntity19));
sourceEntityType = entityTypeFactory.create("source");
sourceEntityType.addAttributes(Lists.newArrayList(sourceAttribute, sourceAttribute1, sourceAttribute2));
}
Aggregations