Search in sources :

Example 1 with Root

use of org.iobserve.model.test.storage.one.Root in project iobserve-analysis by research-iobserve.

the class EvalProxyDBTest method test.

@Test
public void test() throws IOException, DBException {
    new File(EvalProxyDBTest.MODEL_ONE).delete();
    // create model
    final Root modelOne = TestModelData.createModelOne();
    final Two modelTwo = TestModelData.createModelTwo();
    final Registry resourceRegistry = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map = resourceRegistry.getExtensionToFactoryMap();
    map.put("*", new XMIResourceFactoryImpl());
    final ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.setResourceFactoryRegistry(resourceRegistry);
    // put in resources
    final Resource resourceOne = resourceSet.createResource(URI.createFileURI(EvalProxyDBTest.MODEL_ONE));
    resourceOne.getContents().add(modelOne);
    final Resource resourceTwo = resourceSet.createResource(URI.createFileURI(EvalProxyDBTest.MODEL_TWO));
    resourceTwo.getContents().add(modelTwo);
    // save models
    resourceOne.save(null);
    resourceTwo.save(null);
    // store in DB
    final Neo4JModelResource<Root> dbResourceOne = ModelProviderTestUtils.prepareResource("testStoreGraphCreate1", this.prefix, TwoPackage.eINSTANCE);
    dbResourceOne.storeModelPartition(modelOne);
    final Neo4JModelResource<Two> dbResourceTwo = ModelProviderTestUtils.prepareResource("testStoreGraphCreate2", this.prefix, TwoPackage.eINSTANCE);
    dbResourceTwo.storeModelPartition(modelTwo);
    // retrieve model two
    final Two retrievedModelTwo = dbResourceTwo.getModelRootNode(Two.class, TwoPackage.Literals.TWO);
    this.checkProxies("A", retrievedModelTwo);
    ModelNeo4JUtil.printModel(retrievedModelTwo);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Root(org.iobserve.model.test.storage.one.Root) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Neo4JModelResource(org.iobserve.model.persistence.neo4j.Neo4JModelResource) Resource(org.eclipse.emf.ecore.resource.Resource) Registry(org.eclipse.emf.ecore.resource.Resource.Factory.Registry) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Two(org.iobserve.model.test.storage.two.Two) File(java.io.File) Test(org.junit.Test)

Example 2 with Root

use of org.iobserve.model.test.storage.one.Root in project iobserve-analysis by research-iobserve.

the class ECoreNeo4JTest method createWithReferenceThenUpdate.

@Test
public void createWithReferenceThenUpdate() throws Exception {
    final Neo4JModelResource<Root> oneResource = ModelProviderTestUtils.prepareResource("createWithReferenceThenUpdate-one", this.prefix, OnePackage.eINSTANCE);
    final Neo4JModelResource<Two> twoResource = ModelProviderTestUtils.prepareResource("createWithReferenceThenUpdate-two", this.prefix, TwoPackage.eINSTANCE);
    oneResource.storeModelPartition(this.modelOne);
    twoResource.storeModelPartition(this.modelTwo);
    this.modelTwo.getLinks().add(TestModelData.createLink(TestModelData.SECOND_OTHER));
    twoResource.updatePartition(this.modelTwo);
    final Two two = twoResource.getModelRootNode(Two.class, TwoPackage.Literals.TWO);
    Assert.assertThat("Different number of links", two.getLinks().size(), Is.is(this.modelTwo.getLinks().size()));
    for (int i = 0; i < two.getLinks().size(); i++) {
        final Link newLink = two.getLinks().get(i);
        final Link oldLink = this.modelTwo.getLinks().get(i);
        oneResource.resolve(newLink.getReference());
        Assert.assertThat("Links differ", newLink.getReference().getName(), Is.is(oldLink.getReference().getName()));
    }
}
Also used : Root(org.iobserve.model.test.storage.one.Root) Two(org.iobserve.model.test.storage.two.Two) Link(org.iobserve.model.test.storage.two.Link) Test(org.junit.Test)

Example 3 with Root

use of org.iobserve.model.test.storage.one.Root in project iobserve-analysis by research-iobserve.

the class EvalProxyTest method test.

@Test
public void test() throws IOException {
    new File(EvalProxyTest.MODEL_ONE).delete();
    new File(EvalProxyTest.MODEL_X_ONE).delete();
    // create model
    final Root modelOne = TestModelData.createModelOne();
    final Two modelTwo = TestModelData.createModelTwo();
    final Registry resourceRegistry = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map = resourceRegistry.getExtensionToFactoryMap();
    map.put("*", new XMIResourceFactoryImpl());
    final ResourceSet resourceSet = new ResourceSetImpl();
    resourceSet.setResourceFactoryRegistry(resourceRegistry);
    // put in resources
    final Resource resourceOne = resourceSet.createResource(URI.createFileURI(EvalProxyTest.MODEL_ONE));
    resourceOne.getContents().add(modelOne);
    final Resource resourceTwo = resourceSet.createResource(URI.createFileURI(EvalProxyTest.MODEL_TWO));
    resourceTwo.getContents().add(modelTwo);
    // save models
    resourceOne.save(null);
    resourceTwo.save(null);
    this.rename(EvalProxyTest.MODEL_ONE, EvalProxyTest.MODEL_X_ONE);
    TwoPackage.eINSTANCE.eClass();
    OnePackage.eINSTANCE.eClass();
    // read model two
    final Registry resourceRegistry2 = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map2 = resourceRegistry2.getExtensionToFactoryMap();
    map2.put("*", new XMIResourceFactoryImpl());
    final ResourceSet resourceSet2 = new ResourceSetImpl();
    resourceSet2.setResourceFactoryRegistry(resourceRegistry2);
    final Resource resourceTwo2 = resourceSet2.getResource(URI.createFileURI(EvalProxyTest.MODEL_TWO), true);
    resourceTwo2.load(resourceSet2.getLoadOptions());
    // check proxies
    this.checkProxies("A", resourceTwo2);
    // read model one
    this.rename(EvalProxyTest.MODEL_X_ONE, EvalProxyTest.MODEL_ONE);
    final Resource resourceOne2 = resourceSet2.getResource(URI.createFileURI(EvalProxyTest.MODEL_ONE), true);
    resourceTwo2.load(resourceSet2.getLoadOptions());
    resourceOne2.load(resourceSet2.getLoadOptions());
    // check proxies
    this.checkProxies("B", resourceTwo2);
    // resolve proxies
    for (final Resource a : resourceSet2.getResources()) {
        System.out.println("resource " + a.getURI());
    }
    EcoreUtil.resolveAll(resourceTwo2);
    // check proxies
    this.checkProxies("C", resourceTwo2);
    // do it again
    final Registry resourceRegistry3 = Resource.Factory.Registry.INSTANCE;
    final Map<String, Object> map3 = resourceRegistry2.getExtensionToFactoryMap();
    map3.put("*", new XMIResourceFactoryImpl());
    final ResourceSet resourceSet3 = new ResourceSetImpl();
    resourceSet3.setResourceFactoryRegistry(resourceRegistry3);
    final Resource resourceTwo3 = resourceSet3.getResource(URI.createFileURI(EvalProxyTest.MODEL_TWO), true);
    resourceTwo3.load(resourceSet3.getLoadOptions());
    // check proxies
    this.checkProxies("D", resourceTwo3);
    final Resource resourceOne3 = resourceSet3.getResource(URI.createFileURI(EvalProxyTest.MODEL_ONE), true);
    resourceOne3.load(resourceSet3.getLoadOptions());
    // check proxies
    this.checkProxies("E", resourceTwo3);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Root(org.iobserve.model.test.storage.one.Root) XMIResourceFactoryImpl(org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl) Resource(org.eclipse.emf.ecore.resource.Resource) EObject(org.eclipse.emf.ecore.EObject) Registry(org.eclipse.emf.ecore.resource.Resource.Factory.Registry) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) File(java.io.File) Two(org.iobserve.model.test.storage.two.Two) Test(org.junit.Test)

Example 4 with Root

use of org.iobserve.model.test.storage.one.Root in project iobserve-analysis by research-iobserve.

the class TestModelData method createModelOne.

/**
 * Create model one.
 *
 * @return returns model one
 */
public static Root createModelOne() {
    final Root modelOne = OneFactory.eINSTANCE.createRoot();
    modelOne.setEnumerate(EnumValueExample.B);
    modelOne.setFixed("fixed value");
    modelOne.setName("root name");
    modelOne.getLabels().add("label 1");
    modelOne.getLabels().add("label 2");
    modelOne.getLabels().add("label 3");
    modelOne.getOthers().add(TestModelData.FIRST_OTHER);
    modelOne.getOthers().add(TestModelData.SECOND_OTHER);
    modelOne.getIfaceOthers().add(TestModelData.createSpecialA(TestModelData.FIRST_OTHER));
    modelOne.getIfaceOthers().add(TestModelData.createSpecialB());
    return modelOne;
}
Also used : Root(org.iobserve.model.test.storage.one.Root)

Example 5 with Root

use of org.iobserve.model.test.storage.one.Root in project iobserve-analysis by research-iobserve.

the class ECoreNeo4JTest method createThenCloneThenRead.

/**
 * Test create, clone and read sequence.
 *
 * @throws DBException
 */
@Test
public void createThenCloneThenRead() throws DBException {
    final Neo4JModelResource<Root> storeResource = ModelProviderTestUtils.prepareResource("createThenCloneThenRead", this.prefix, OnePackage.eINSTANCE);
    storeResource.storeModelPartition(this.modelOne);
    storeResource.getGraphDatabaseService().shutdown();
    final Neo4JModelResource<Root> newVersionResource = ModelProviderUtil.createNewModelResourceVersion(OnePackage.eINSTANCE, storeResource);
    final Root clonedModel = newVersionResource.getModelRootNode(Root.class, OnePackage.Literals.ROOT);
    newVersionResource.getGraphDatabaseService().shutdown();
    Assert.assertTrue(this.equalityHelper.comparePartition(this.modelOne, clonedModel, clonedModel.eClass()));
}
Also used : Root(org.iobserve.model.test.storage.one.Root) Test(org.junit.Test)

Aggregations

Root (org.iobserve.model.test.storage.one.Root)5 Test (org.junit.Test)4 Two (org.iobserve.model.test.storage.two.Two)3 File (java.io.File)2 Resource (org.eclipse.emf.ecore.resource.Resource)2 Registry (org.eclipse.emf.ecore.resource.Resource.Factory.Registry)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)2 XMIResourceFactoryImpl (org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl)2 EObject (org.eclipse.emf.ecore.EObject)1 Neo4JModelResource (org.iobserve.model.persistence.neo4j.Neo4JModelResource)1 Link (org.iobserve.model.test.storage.two.Link)1