use of org.uberfire.ext.editor.commons.version.impl.PortableVersionRecord in project drools-wb by kiegroup.
the class GuidedDecisionTableEditorServiceImplTest method checkSaveAndUpdateGraphEntries.
@Test
@SuppressWarnings("unchecked")
public void checkSaveAndUpdateGraphEntries() {
// Setup Decision Table
final Path path = mock(Path.class);
final GuidedDecisionTable52 model = new GuidedDecisionTable52();
final Metadata metadata = mock(Metadata.class);
final String comment = "comment";
final String headPathUri = "default://project/src/main/resources/mypackage/dtable.gdst";
final String versionPathUri = "default://0123456789@project/src/main/resources/mypackage/dtable.gdst";
when(path.toURI()).thenReturn(headPathUri);
when(path.getFileName()).thenReturn("dtable.gdst");
// Setup Decision Table versions
final List<VersionRecord> versions = new ArrayList<>();
versions.add(new PortableVersionRecord("0123456789", "manstis", "manstis@email.com", "comment", Calendar.getInstance().getTime(), versionPathUri));
when(versionRecordService.load(any(org.uberfire.java.nio.file.Path.class))).thenReturn(versions);
// Setup Decision Table Graph
final URI dtGraphPathUri = URI.create("default://project/src/main/resources/mypackage/graph1.gdst-set");
final org.uberfire.java.nio.file.Path dtGraphPath = mock(org.uberfire.java.nio.file.Path.class);
when(dtGraphPath.toUri()).thenReturn(dtGraphPathUri);
when(dtGraphPath.getFileName()).thenReturn(dtGraphPath);
when(dtGraphPath.getFileSystem()).thenReturn(fileSystem);
final List<org.uberfire.java.nio.file.Path> dtGraphPaths = new ArrayList<>();
dtGraphPaths.add(dtGraphPath);
when(ioService.newDirectoryStream(any(org.uberfire.java.nio.file.Path.class), any(FileExtensionFilter.class))).thenReturn(new MockDirectoryStream(dtGraphPaths));
final GuidedDecisionTableEditorGraphModel dtGraphModel = new GuidedDecisionTableEditorGraphModel();
dtGraphModel.getEntries().add(new GuidedDecisionTableEditorGraphModel.GuidedDecisionTableGraphEntry(path, path));
when(dtableGraphService.load(any(Path.class))).thenReturn(dtGraphModel);
// Test save
service.saveAndUpdateGraphEntries(path, model, metadata, comment);
verify(ioService, times(1)).startBatch(any(FileSystem.class));
verify(ioService, times(1)).write(any(org.uberfire.java.nio.file.Path.class), any(String.class), any(Map.class), any(CommentedOption.class));
verify(ioService, times(1)).endBatch();
assertEquals("mypackage", model.getPackageName());
assertEquals(1, dtGraphModel.getEntries().size());
assertEquals(versions.get(0).uri(), dtGraphModel.getEntries().iterator().next().getPathVersion().toURI());
}
use of org.uberfire.ext.editor.commons.version.impl.PortableVersionRecord in project drools-wb by kiegroup.
the class GuidedDecisionTableGraphEditorPresenterTest method checkInitialiseVersionManager.
@Test
public void checkInitialiseVersionManager() {
doNothing().when(presenter).reload();
when(versionRecordManager.isLatest(any(VersionRecord.class))).thenReturn(true);
presenter.initialiseVersionManager();
verify(versionRecordManager, times(1)).init(eq(null), eq(presenter.editorPath), versionRecordCallbackCaptor.capture());
final Callback<VersionRecord> versionRecordCallback = versionRecordCallbackCaptor.getValue();
assertNotNull(versionRecordCallback);
versionRecordCallback.callback(new PortableVersionRecord("id", "author", "email", "comment", mock(Date.class), "uri"));
verify(versionRecordManager, times(1)).setVersion(eq("id"));
verify(registeredDocumentsMenuBuilder, times(1)).setReadOnly(eq(false));
verify(presenter, times(1)).reload();
assertFalse(presenter.access.isReadOnly());
}
Aggregations