Skip to content

Commit

Permalink
feat: Support Baseline view
Browse files Browse the repository at this point in the history
Refs: #305
  • Loading branch information
grigoriev committed Dec 9, 2024
1 parent 93cd2b6 commit f473020
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.polarion.platform.security.ISecurityService;
import com.polarion.platform.service.repository.IRepositoryService;
import com.polarion.portal.internal.server.navigation.TestManagementServiceAccessor;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -207,18 +206,19 @@ private boolean sameDocument(@Nullable String projectId, @NotNull String spaceId
return result;
}

@SneakyThrows
public <T> T executeInBaseline(@Nullable String baselineRevision, @NotNull ReadOnlyTransaction transaction, @NotNull Callable<T> callable) {
if (baselineRevision == null) {
return callable.call();
return callCallable(callable);
} else {
return transaction.utils().executeInBaseline(baselineRevision, () -> {
try {
return callable.call();
} catch (Exception e) {
throw new BaselineExecutionException("Error during callable execution", e);
}
});
return transaction.utils().executeInBaseline(baselineRevision, () -> callCallable(callable));
}
}

private static <T> T callCallable(@NotNull Callable<T> callable) {
try {
return callable.call();
} catch (Exception e) {
throw new BaselineExecutionException("Error during callable execution", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ch.sbb.polarion.extension.generic.settings.SettingName;
import ch.sbb.polarion.extension.generic.util.PObjectListStub;
import ch.sbb.polarion.extension.generic.util.ScopeUtils;
import ch.sbb.polarion.extension.pdf_exporter.exception.BaselineExecutionException;
import ch.sbb.polarion.extension.pdf_exporter.rest.model.attachments.TestRunAttachment;
import ch.sbb.polarion.extension.pdf_exporter.rest.model.collections.DocumentCollectionEntry;
import ch.sbb.polarion.extension.pdf_exporter.rest.model.settings.stylepackage.StylePackageModel;
Expand All @@ -14,6 +15,8 @@
import com.polarion.alm.shared.api.model.baselinecollection.BaselineCollection;
import com.polarion.alm.shared.api.model.baselinecollection.BaselineCollectionReference;
import com.polarion.alm.shared.api.transaction.ReadOnlyTransaction;
import com.polarion.alm.shared.api.utils.PolarionUtils;
import com.polarion.alm.shared.api.utils.RunnableWithResult;
import com.polarion.alm.tracker.ITestManagementService;
import com.polarion.alm.tracker.ITrackerService;
import com.polarion.alm.tracker.model.IModule;
Expand All @@ -26,6 +29,8 @@
import com.polarion.platform.security.ISecurityService;
import com.polarion.platform.service.repository.IRepositoryService;
import com.polarion.subterra.base.location.ILocation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.MockedConstruction;
Expand Down Expand Up @@ -287,4 +292,42 @@ void testGetDocumentsFromCollection() {
assertEquals("2", result.get(1).getRevision());
}
}

@Test
void testExecuteInBaseline() {
PolarionUtils polarionUtils = new PolarionUtils() {
@Override
public @Nullable <T> T executeInBaseline(@NotNull String s, @NotNull RunnableWithResult<T> runnableWithResult) {
return runnableWithResult.run();
}

@Override
public @Nullable <T> T executeOutsideBaseline(@NotNull RunnableWithResult<T> runnableWithResult) {
return null;
}

@Override
public @NotNull String convertToAscii(@Nullable String s) {
return "";
}

@Override
public @NotNull String convertToAscii(@Nullable String s, @Nullable String s1) {
return "";
}
};

ReadOnlyTransaction mockReadOnlyTransaction = mock(ReadOnlyTransaction.class);
when(mockReadOnlyTransaction.utils()).thenReturn(polarionUtils);

assertEquals("valueWithoutBaseline", service.executeInBaseline(null, mockReadOnlyTransaction, () -> "valueWithoutBaseline"));

assertEquals("valueInBaseline", service.executeInBaseline("1234", mockReadOnlyTransaction, () -> "valueInBaseline"));
assertThrows(BaselineExecutionException.class, () -> service.executeInBaseline("5678", mockReadOnlyTransaction, this::testCallable));
}

private String testCallable() throws Exception {
throw new Exception("argument");
}

}

0 comments on commit f473020

Please sign in to comment.