@Test public void testAddAndGetEntity() { readPackageTree(); PackageImpl defaultPackage = (PackageImpl) PackageImpl.defaultPackage; DefaultEntityMetaData coderMetaData = new DefaultEntityMetaData("Coder"); coderMetaData.setDescription("A coder"); coderMetaData.setExtends(metaDataServiceImpl.getEntityMetaData("org_molgenis_Person")); coderMetaData.setPackage(defaultPackage); coderMetaData.addAttribute("ID", ROLE_ID); coderMetaData.addAttribute("simple"); DefaultAttributeMetaData compoundAttribute = new DefaultAttributeMetaData("compound", COMPOUND); coderMetaData.addAttributeMetaData(compoundAttribute); compoundAttribute.addAttributePart(new DefaultAttributeMetaData("c1")); compoundAttribute.addAttributePart(new DefaultAttributeMetaData("c2")); assertEquals(coderMetaData.getIdAttribute().getName(), "ID"); metaDataServiceImpl.addEntityMeta(coderMetaData); DefaultEntityMetaData retrieved = metaDataServiceImpl.getEntityMetaData("Coder"); assertEquals(retrieved, coderMetaData); assertEquals(retrieved.getIdAttribute().getName(), "ID"); // reboot DataServiceImpl dataService = new DataServiceImpl(); metaDataServiceImpl = new MetaDataServiceImpl(dataService); AppSettings appSettings = Mockito.mock(AppSettings.class); metaDataServiceImpl.setLanguageService(new LanguageService(dataService, appSettings)); metaDataServiceImpl.setDefaultBackend(manageableCrudRepositoryCollection); retrieved = metaDataServiceImpl.getEntityMetaData("Coder"); assertEquals(retrieved.getIdAttribute().getName(), "ID"); assertTrue( Iterables.elementsEqual( retrieved.getAtomicAttributes(), coderMetaData.getAtomicAttributes())); }
@Test public void resolve() { DefaultEntityMetaData e1 = new DefaultEntityMetaData("e1"); DefaultEntityMetaData e2 = new DefaultEntityMetaData("e2"); DefaultEntityMetaData e3 = new DefaultEntityMetaData("e3"); DefaultEntityMetaData e4 = new DefaultEntityMetaData("e4"); DefaultEntityMetaData e5 = new DefaultEntityMetaData("e5"); e1.addAttribute("ref").setDataType(MolgenisFieldTypes.XREF).setRefEntity(e5); e5.setExtends(e3); e3.addAttribute("ref").setDataType(MolgenisFieldTypes.XREF).setRefEntity(e4); e3.addAttribute("refSelf").setDataType(MolgenisFieldTypes.XREF).setRefEntity(e3); e4.addAttribute("ref").setDataType(MolgenisFieldTypes.XREF).setRefEntity(e2); List<EntityMetaData> resolved = DependencyResolver.resolve(Sets.<EntityMetaData>newHashSet(e1, e2, e3, e4, e5)); assertEquals(resolved, Arrays.asList(e2, e4, e3, e5, e1)); }