@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())); }
@BeforeMethod public void readPackageTree() { defaultPackage = PackageImpl.defaultPackage; PackageImpl org = new PackageImpl("org", "the org package", null); molgenis = new PackageImpl("molgenis", "the molgenis package", org); org.addSubPackage(molgenis); PackageImpl molgenis2 = new PackageImpl("molgenis2", "the molgenis2 package", org); org.addSubPackage(molgenis2); DefaultEntityMetaData personMetaData = new DefaultEntityMetaData("Person"); personMetaData.setDescription("A person"); personMetaData.setPackage(molgenis); molgenis.addEntity(personMetaData); MapEntity personEntity = new MapEntity(); personEntity.set(EntityMetaDataMetaData.PACKAGE, molgenis.toEntity()); personEntity.set(EntityMetaDataMetaData.DESCRIPTION, "A person"); personEntity.set(EntityMetaDataMetaData.FULL_NAME, "org_molgenis_Person"); personEntity.set(EntityMetaDataMetaData.SIMPLE_NAME, "Person"); personEntity.set(EntityMetaDataMetaData.ABSTRACT, true); DataServiceImpl dataService = new DataServiceImpl(); metaDataServiceImpl = new MetaDataServiceImpl(dataService); AppSettings appSettings = Mockito.mock(AppSettings.class); metaDataServiceImpl.setLanguageService(new LanguageService(dataService, appSettings)); metaDataServiceImpl.setDefaultBackend(manageableCrudRepositoryCollection); assertEquals(metaDataServiceImpl.getRootPackages(), Arrays.asList(defaultPackage)); }