EntityManagerImpl implements AbstractEntityManager, Wrapper { @Override public <T> T merge(final T entity) { final Descriptor d = new EntityDescriptor(); return merge(entity, d); } EntityManagerImpl(EntityManagerFactoryImpl emf, Configuration configuration, ServerSession serverSession); @Override void persist(final Object entity); @Override void persist(final Object entity, final Descriptor descriptor); @Override T merge(final T entity); @Override T merge(final T entity, final Descriptor descriptor); @Override void remove(Object object); @Override T find(Class<T> cls, Object identifier); @Override T find(Class<T> cls, Object identifier, Descriptor descriptor); @Override T getReference(Class<T> entityClass, Object identifier); @Override T getReference(Class<T> entityClass, Object identifier, Descriptor descriptor); @Override void flush(); @Override void refresh(Object entity); @Override void clear(); @Override void detach(Object entity); @Override boolean contains(Object entity); @Override void close(); @Override boolean isOpen(); @Override EntityTransaction getTransaction(); @Override EntityManagerFactoryImpl getEntityManagerFactory(); @Override Metamodel getMetamodel(); @Override boolean isLoaded(final Object object, final String attributeName); @Override boolean isLoaded(Object object); @Override QueryImpl createQuery(String qlString); @Override TypedQueryImpl<T> createQuery(String query, Class<T> resultClass); @Override QueryImpl createNativeQuery(String sparqlString); @Override TypedQueryImpl<T> createNativeQuery(String sparqlString, Class<T> resultClass); @Override QueryImpl createNativeQuery(String sparqlString, String resultSetMapping); @Override QueryImpl createNamedQuery(String name); @Override TypedQueryImpl<T> createNamedQuery(String name, Class<T> resultClass); @Override boolean isConsistent(URI context); @Override List<URI> getContexts(); @Override void setUseTransactionalOntologyForQueryProcessing(); @Override boolean useTransactionalOntologyForQueryProcessing(); @Override void setUseBackupOntologyForQueryProcessing(); @Override boolean useBackupOntologyForQueryProcessing(); @Override T unwrap(Class<T> cls); @Override Object getDelegate(); @Override UnitOfWorkImpl getCurrentPersistenceContext(); @Override void removeCurrentPersistenceContext(); @Override void transactionStarted(EntityTransaction t); @Override void transactionFinished(EntityTransaction t); @Override Configuration getConfiguration();  }
@Test void testCascadeMergeOnNullCollection() { final OWLClassJ j = new OWLClassJ(); j.setUri(URI.create("http: mocks.forOwlClassJ().setAttribute().getJavaField().setAccessible(true); assertNull(j.getOwlClassA()); em.merge(j); final ArgumentCaptor<OWLClassJ> argumentCaptor = ArgumentCaptor.forClass(OWLClassJ.class); verify(uow).mergeDetached(argumentCaptor.capture(), any(Descriptor.class)); assertSame(j, argumentCaptor.getValue()); }
@Test void mergeDetachedWithSingletonSet() { final OWLClassJ j = new OWLClassJ(); j.setUri(URI.create("http: final OWLClassA a = new OWLClassA(URI.create("http: j.setOwlClassA(Collections.singleton(a)); final OWLClassJ merged = em.merge(j); assertSame(j, merged); verify(uow).mergeDetached(eq(j), any()); verify(uow).mergeDetached(eq(a), any()); }
@Test void mergeDetachedWithSingletonList() { final OWLClassC c = new OWLClassC(URI.create("http: final OWLClassA a = new OWLClassA(URI.create("http: c.setSimpleList(Collections.singletonList(a)); when(mocks.forOwlClassC().simpleListAtt().getCascadeTypes()).thenReturn(new CascadeType[]{CascadeType.MERGE}); final OWLClassC merged = em.merge(c); assertSame(c, merged); verify(uow).mergeDetached(eq(c), any()); verify(uow).mergeDetached(eq(a), any()); }
@Test void mergeThrowsIllegalArgumentForNonEntity() { final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> em.merge(new UnknownEntity(), new EntityDescriptor())); assertEquals(NON_ENTITY_CLASS_EXCEPTION_MESSAGE, ex.getMessage()); }