use of org.apache.cayenne.project.upgrade.handlers.UpgradeHandler in project cayenne by apache.
the class CompatibilityUpgradeService method upgradeDataMap.
public Resource upgradeDataMap(Resource resource) {
List<UpgradeHandler> handlerList = getHandlersForVersion(loadProjectVersion(resource));
Document document = Util.readDocument(resource.getURL());
UpgradeUnit upgradeUnit = new UpgradeUnit(resource, document);
for (UpgradeHandler handler : handlerList) {
handler.processDataMapDom(upgradeUnit);
}
documentProvider.putDocument(upgradeUnit.getResource().getURL(), upgradeUnit.getDocument());
return upgradeUnit.getResource();
}
use of org.apache.cayenne.project.upgrade.handlers.UpgradeHandler in project cayenne by apache.
the class DefaultUpgradeService method upgradeDOM.
protected List<UpgradeUnit> upgradeDOM(Resource resource, List<UpgradeHandler> handlerList) {
List<UpgradeUnit> allUnits = new ArrayList<>();
// Load DOM for all resources
Document projectDocument = Util.readDocument(resource.getURL());
UpgradeUnit projectUnit = new UpgradeUnit(resource, projectDocument);
allUnits.add(projectUnit);
List<Resource> dataMapResources = getAdditionalDatamapResources(projectUnit);
List<UpgradeUnit> dataMapUnits = new ArrayList<>(dataMapResources.size());
for (Resource dataMapResource : dataMapResources) {
dataMapUnits.add(new UpgradeUnit(dataMapResource, Util.readDocument(dataMapResource.getURL())));
}
allUnits.addAll(dataMapUnits);
// Update DOM
for (UpgradeHandler handler : handlerList) {
handler.processProjectDom(projectUnit);
for (UpgradeUnit dataMapUnit : dataMapUnits) {
handler.processDataMapDom(dataMapUnit);
}
}
return allUnits;
}
use of org.apache.cayenne.project.upgrade.handlers.UpgradeHandler in project cayenne by apache.
the class DefaultUpgradeServiceTest method upgradeDOM.
@Test
public void upgradeDOM() throws Exception {
Resource resource = new URLResource(getClass().getResource("../cayenne-PROJECT1.xml"));
// Mock service so it will use actual reading but skip actual saving part
upgradeService = mock(DefaultUpgradeService.class);
when(upgradeService.upgradeDOM(any(Resource.class), ArgumentMatchers.<UpgradeHandler>anyList())).thenCallRealMethod();
when(upgradeService.getAdditionalDatamapResources(any(UpgradeUnit.class))).thenCallRealMethod();
upgradeService.upgradeDOM(resource, handlers);
// verify(upgradeService, times(3)).saveDocument(any(UpgradeUnit.class));
for (UpgradeHandler handler : handlers) {
verify(handler).getVersion();
verify(handler).processProjectDom(any(UpgradeUnit.class));
// two data maps
verify(handler, times(2)).processDataMapDom(any(UpgradeUnit.class));
verifyNoMoreInteractions(handler);
}
}
use of org.apache.cayenne.project.upgrade.handlers.UpgradeHandler in project cayenne by apache.
the class DefaultUpgradeServiceTest method createHandler.
private UpgradeHandler createHandler(String version) {
UpgradeHandler handler = mock(UpgradeHandler.class);
when(handler.getVersion()).thenReturn(version);
return handler;
}
use of org.apache.cayenne.project.upgrade.handlers.UpgradeHandler in project cayenne by apache.
the class CompatibilityUpgradeService method upgradeProject.
@Override
public Resource upgradeProject(Resource resource) {
List<UpgradeHandler> handlerList = getHandlersForVersion(loadProjectVersion(resource));
List<UpgradeUnit> upgradeUnits = upgradeDOM(resource, handlerList);
for (UpgradeUnit unit : upgradeUnits) {
documentProvider.putDocument(unit.getResource().getURL(), unit.getDocument());
}
return resource;
}
Aggregations