X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2Fsupport%2FundoRedoSupport%2FUndoTest20.java;fp=tests%2Forg.simantics.db.tests%2Fsrc%2Forg%2Fsimantics%2Fdb%2Ftests%2Fapi%2Fsupport%2FundoRedoSupport%2FUndoTest20.java;h=f2252190750dbfff194be012260ae7428e161d8e;hb=67fd62f9c742337ec80eef658192db198a0efaac;hp=0000000000000000000000000000000000000000;hpb=cde82ba81327d5515fdca362f7f4c70f5103ae80;p=simantics%2Fplatform.git diff --git a/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest20.java b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest20.java new file mode 100644 index 000000000..f22521907 --- /dev/null +++ b/tests/org.simantics.db.tests/src/org/simantics/db/tests/api/support/undoRedoSupport/UndoTest20.java @@ -0,0 +1,124 @@ +/******************************************************************************* + * Copyright (c) 2007, 2010 Association for Decentralized Information Management + * in Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.db.tests.api.support.undoRedoSupport; + +import java.util.Arrays; + +import org.junit.Test; +import org.simantics.databoard.Bindings; +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.Session; +import org.simantics.db.WriteGraph; +import org.simantics.db.common.request.ReadRequest; +import org.simantics.db.common.request.WriteRequest; +import org.simantics.db.exception.DatabaseException; +import org.simantics.db.service.UndoRedoSupport; +import org.simantics.db.testing.base.ExistingDatabaseTest; +import org.simantics.layer0.Layer0; +import org.simantics.utils.DataContainer; + +/** + * Tests undo of deletion of large literal when done twice in sequence. + * This was added because of Bug #4591. + */ +public class UndoTest20 extends ExistingDatabaseTest { + private void initValue(byte[] value) { + for (int i=0; i subject1 = new DataContainer(); + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Layer0 b = Layer0.getInstance(graph); + Resource s1 = graph.newResource(); + graph.claim(s1, b.InstanceOf, b.Entity); + graph.claimValue(s1, value); + subject1.set(s1); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + testUndo(session, value, subject1); + testUndo(session, value, subject1); + } + public void testUndo(final Session session, final byte[] value, final DataContainer subject1) + throws Exception { + final UndoRedoSupport support = session.getService(UndoRedoSupport.class); + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t1, value)) + fail("Failed to verify value."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + try { + session.syncRequest(new WriteRequest() { + @Override + public void perform(WriteGraph graph) throws DatabaseException { + graph.markUndoPoint(); + Resource s1 = subject1.get(); + graph.denyValue(s1); + } + }); + } catch (Throwable e) { + fail("Write transaction threw an unknown exception ", e); + } + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getPossibleValue(s1, Bindings.BYTE_ARRAY); + if (null != t1) + fail("Failed to verify delettion of value."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + try { + support.undo(session, 1); + } catch (Throwable e) { + fail("Undo operation threw an unexpected exception.", e); + } + try { + session.syncRequest(new ReadRequest() { + @Override + public void run(ReadGraph graph) throws DatabaseException { + Resource s1 = subject1.get(); + byte[] t1 = graph.getValue(s1, Bindings.BYTE_ARRAY); + if (!Arrays.equals(t1, value)) + fail("Failed to verify value1."); + } + }); + } catch (Throwable e) { + fail("Read transaction threw an unexpected exception ", e); + } + } +}