/*******************************************************************************
* 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.readGraph.adapt;
import org.junit.Before;
import org.junit.Test;
import org.simantics.db.AsyncReadGraph;
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.ResourceAsyncRead;
import org.simantics.db.common.request.WriteRequest;
import org.simantics.db.exception.AdaptionException;
import org.simantics.db.exception.DatabaseException;
import org.simantics.db.procedure.AsyncProcedure;
import org.simantics.db.request.Read;
import org.simantics.db.services.GlobalServiceInitializer;
import org.simantics.db.testing.base.ExistingDatabaseTest;
import org.simantics.layer0.Layer0;
/**
* Checks that {@link ReadGraph#adapt(org.simantics.db.Resource, Class)},
* {@link ReadGraph#adaptUnique(org.simantics.db.Resource, Class)},
* AsyncReadGraph.forAdapted
fail as expected.
*
*
* Regression test for https://www.simulationsite.net/trac/simantics/ticket/617
*
* @author Tuukka Lehtonen
*/
public class AdaptionFailureTest extends ExistingDatabaseTest {
@Override
@Before
public void setUp() throws Exception {
super.setUp();
new GlobalServiceInitializer().initialize(getSession());
}
private Resource writeTypeless(Session session) throws DatabaseException {
final Resource[] typeless = { null };
session.syncRequest(new WriteRequest() {
@Override
public void perform(WriteGraph graph) throws DatabaseException {
Layer0 l0 = Layer0.getInstance(graph);
Resource tless = graph.newResource();
Resource name = graph.newResource();
graph.claim(name, l0.InstanceOf, null, l0.String);
graph.claimValue(name, "A Typeless Resource");
graph.claim(tless, l0.HasName, name);
typeless[0] = tless;
}
});
return typeless[0];
}
static abstract class Adapter {
String name;
public Adapter(String name) {
this.name = name;
}
public abstract