use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.
the class TransientResolverTest method testGetDataService.
private void testGetDataService(String fileSeparator) throws Exception {
RepositoryDirectoryInterface directory = mock(RepositoryDirectoryInterface.class);
when(root.findDirectory(fileSeparator + "path" + fileSeparator + "to")).thenReturn(directory);
when(repository.getTransformationID("name", directory)).thenReturn(objectId);
when(repository.loadTransformation(objectId, null)).thenReturn(transMeta);
String transientId = TransientResolver.buildTransient(fileSeparator + "path" + fileSeparator + "to" + fileSeparator + "name", "data_service");
DataServiceMeta dataServiceMeta = transientResolver.getDataService(transientId);
assertNotNull(dataServiceMeta);
assertThat(dataServiceMeta.getStepname(), is("data_service"));
assertFalse(dataServiceMeta.isUserDefined());
assertThat(dataServiceMeta, hasServiceCacheOptimization());
int rowLimit = 1000;
transientId = TransientResolver.buildTransient(fileSeparator + "path" + fileSeparator + "to" + fileSeparator + "name", "data_service", rowLimit);
dataServiceMeta = transientResolver.getDataService(transientId);
assertEquals(rowLimit, dataServiceMeta.getRowLimit());
}
use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceMetaStoreUtilTest method testCheckConflict.
@Test
public void testCheckConflict() throws Exception {
final ServiceTrans published = mock(ServiceTrans.class);
when(published.getName()).thenReturn("PUBLISHED_SERVICE");
metaStoreUtil = new DataServiceMetaStoreUtil(metaStoreUtil) {
@Override
protected MetaStoreFactory<ServiceTrans> getServiceTransFactory(IMetaStore metaStore) {
return new MetaStoreFactory<ServiceTrans>(ServiceTrans.class, metaStore, NAMESPACE) {
@Override
public List<ServiceTrans> getElements() throws MetaStoreException {
return ImmutableList.of(published);
}
};
}
};
DataServiceMeta local = createDataService("OTHER_SERVICE", transMeta);
local.setStepname("OTHER_STEP");
metaStoreUtil.getDataServiceFactory(transMeta).saveElement(local);
// New data service with different properties
metaStoreUtil.checkConflict(dataService, null);
// Editing a data service with all new properties
metaStoreUtil.checkConflict(dataService, local.getName());
try {
// New data service with the same name as an local data service
dataService.setName(local.getName());
metaStoreUtil.checkConflict(dataService, null);
fail("Expected DataServiceAlreadyExistsException");
} catch (DataServiceAlreadyExistsException e) {
assertThat(e.getDataServiceMeta(), sameInstance(dataService));
}
// Editing a data service, no name change
metaStoreUtil.checkConflict(dataService, local.getName());
dataService = createDataService(DATA_SERVICE_NAME, transMeta);
metaStoreUtil.checkConflict(dataService, null);
try {
// New data service with conflicting output step
dataService.setStepname(local.getStepname());
metaStoreUtil.checkConflict(dataService, null);
fail("Expected DataServiceAlreadyExistsException");
} catch (DataServiceAlreadyExistsException e) {
assertThat(e.getDataServiceMeta(), sameInstance(dataService));
}
// Editing data service with same output step
metaStoreUtil.checkConflict(dataService, local.getName());
dataService = createDataService(DATA_SERVICE_NAME, transMeta);
metaStoreUtil.checkConflict(dataService, null);
dataService.setName(published.getName());
when(published.getReferences()).thenReturn(ImmutableList.<ServiceTrans.Reference>of());
metaStoreUtil.checkConflict(dataService, null);
ServiceTrans.Reference reference = mock(ServiceTrans.Reference.class);
when(reference.exists(repository)).thenReturn(false, true);
when(published.getReferences()).thenReturn(ImmutableList.of(reference));
metaStoreUtil.checkConflict(dataService, null);
try {
// New Data service with conflicting name in metastore
metaStoreUtil.checkConflict(dataService, null);
fail("Expected DataServiceAlreadyExistsException");
} catch (DataServiceAlreadyExistsException e) {
assertThat(e.getDataServiceMeta(), sameInstance(dataService));
}
try {
// Editing Data service with conflicting name in metastore
metaStoreUtil.checkConflict(dataService, local.getName());
fail("Expected DataServiceAlreadyExistsException");
} catch (DataServiceAlreadyExistsException e) {
assertThat(e.getDataServiceMeta(), sameInstance(dataService));
}
}
use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceMetaStoreUtilTest method testClearReferences.
@Test
public void testClearReferences() throws Exception {
MetaStoreFactory<DataServiceMeta> dataServiceFactory = metaStoreUtil.getDataServiceFactory(transMeta);
MetaStoreFactory<ServiceTrans> serviceTransFactory = metaStoreUtil.getServiceTransFactory(metaStore);
String otherName = "OTHER";
DataServiceMeta other = createDataService(otherName, transMeta);
dataServiceFactory.saveElement(dataService);
dataServiceFactory.saveElement(other);
serviceTransFactory.saveElement(ServiceTrans.create(dataService));
serviceTransFactory.saveElement(ServiceTrans.create(other.getName(), mock(TransMeta.class)));
assertThat(metaStoreUtil.getDataServiceNames(transMeta), containsInAnyOrder(DATA_SERVICE_NAME, otherName));
assertThat(metaStoreUtil.getDataServiceNames(metaStore), containsInAnyOrder(DATA_SERVICE_NAME, otherName));
metaStoreUtil.clearReferences(transMeta);
// Local unchanged
assertThat(metaStoreUtil.getDataServiceNames(transMeta), containsInAnyOrder(DATA_SERVICE_NAME, otherName));
// Published data service should be removed from the metaStore
assertThat(metaStoreUtil.getDataServiceNames(metaStore), contains(otherName));
}
use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceReferenceSynchronizerTest method mockDataServiceMetas.
private List<DataServiceMeta> mockDataServiceMetas(String... names) {
List<DataServiceMeta> metas = new ArrayList<>();
for (String name : names) {
DataServiceMeta meta = mock(DataServiceMeta.class);
when(meta.getName()).thenReturn(name);
when(meta.getServiceTrans()).thenReturn(transMeta);
metas.add(meta);
}
return metas;
}
use of org.pentaho.di.trans.dataservice.DataServiceMeta in project pdi-dataservice-server-plugin by pentaho.
the class CachedServiceTest method setUp.
@Before
public void setUp() throws Exception {
rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaString("ID"));
rowMeta.addValueMeta(new ValueMetaInteger("A"));
rowMeta.addValueMeta(new ValueMetaInteger("B"));
testData = Lists.newArrayListWithExpectedSize(100);
for (long i = 0; i < 100; i++) {
testData.add(new RowMetaAndData(rowMeta, String.valueOf(i), i % 13, i % 17));
}
when(serviceTrans.findRunThread(SERVICE_STEP)).thenReturn(serviceStep);
when(serviceStep.getTrans()).thenReturn(serviceTrans);
when(sqlTransGenerator.getInjectorStepName()).thenReturn(INJECTOR_STEP);
transMeta = serviceTrans.getTransMeta();
when(transMeta.getCacheVersion()).thenReturn(1);
dataServiceMeta = new DataServiceMeta(transMeta);
dataServiceMeta.setName(SERVICE_NAME);
dataServiceMeta.setStepname(SERVICE_STEP);
when(transMeta.getStepFields(SERVICE_STEP)).thenReturn(rowMeta);
}
Aggregations