List of usage examples for org.hibernate.exception GenericJDBCException GenericJDBCException
public GenericJDBCException(String string, SQLException root)
From source file:es.tid.fiware.rss.exceptionhandles.FactoryResponseTest.java
License:Open Source License
/** * /* ww w . j a va 2s .c om*/ */ @Test public void catchNewConnectionJson() throws Exception { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://www.test.com/go")); GenericJDBCException exception = new GenericJDBCException("sql", new SQLException("reason")); Response bean = FactoryResponse.catchNewConnectionJson(rssProps, mockUriInfo, exception, "message", "resource"); Assert.assertTrue(true); }
From source file:es.tid.fiware.rss.exceptionhandles.JsonExceptionMapperTest.java
License:Open Source License
@Test public void toResponse() throws Exception { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getAbsolutePath()).thenReturn(new URI("http://www.test.com/go")); ReflectionTestUtils.setField(mapper, "uriInfo", mockUriInfo); RSSException e = new RSSException("RssException"); Response response = mapper.toResponse(e); Assert.assertTrue(true);// w w w .j a v a 2 s. co m GenericJDBCException ex = new GenericJDBCException("sql", new SQLException("reason")); response = mapper.toResponse(ex); Assert.assertTrue(true); JDBCConnectionException ex1 = new JDBCConnectionException("sql", new SQLException("reason")); response = mapper.toResponse(ex1); Assert.assertTrue(true); NotFoundException ex2 = new NotFoundException(); response = mapper.toResponse(ex2); Assert.assertTrue(true); Exception ex3 = new Exception("RssException"); response = mapper.toResponse(ex3); Assert.assertTrue(true); Exception ex4 = new Exception("RssException", ex); response = mapper.toResponse(ex4); Assert.assertTrue(true); Exception ex5 = new Exception("RssException", ex1); response = mapper.toResponse(ex5); Assert.assertTrue(true); }
From source file:es.tid.fiware.rss.expenditureLimit.server.exceptionhandles.test.ExpenditureLimitExceptionMapperTest.java
License:Open Source License
@Test public void toResponse() throws Exception { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getAbsolutePath()).thenReturn(new URI("http://www.test.com/go")); ReflectionTestUtils.setField(mapper, "ui", mockUriInfo); RSSException e = new RSSException("RssException"); Response response = mapper.toResponse(e); Assert.assertTrue(true);//from w w w .j av a2s. c o m GenericJDBCException ex = new GenericJDBCException("sql", new SQLException("reason")); response = mapper.toResponse(ex); Assert.assertTrue(true); JDBCConnectionException ex1 = new JDBCConnectionException("sql", new SQLException("reason")); response = mapper.toResponse(ex1); Assert.assertTrue(true); NotFoundException ex2 = new NotFoundException(); response = mapper.toResponse(ex2); Assert.assertTrue(true); Exception ex3 = new Exception("RssException"); response = mapper.toResponse(ex3); Assert.assertTrue(true); Exception ex4 = new Exception("RssException", ex); response = mapper.toResponse(ex4); Assert.assertTrue(true); Exception ex5 = new Exception("RssException", ex1); response = mapper.toResponse(ex5); Assert.assertTrue(true); }
From source file:es.tid.fiware.rss.expenditureLimit.server.manager.common.test.FactoryResponseTest.java
License:Open Source License
/** * /*from w ww .j a va2 s . com*/ */ @Test public void catchNewConnectionJson() throws Exception { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://www.test.com/go")); GenericJDBCException exception = new GenericJDBCException("sql", new SQLException("reason")); Response bean = FactoryResponse.catchNewConnectionJson(appProperties, mockUriInfo, exception, "message", "resource"); Assert.assertTrue(true); }
From source file:es.upm.fiware.rss.exceptionhandles.FactoryResponseTest.java
License:Open Source License
/** * // w ww . jav a 2s .c o m */ @Test public void catchNewConnectionJson() throws Exception { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getBaseUri()).thenReturn(new URI("http://www.test.com/go")); GenericJDBCException exception = new GenericJDBCException("sql", new SQLException("reason")); Response bean = FactoryResponse.catchNewConnectionJson(mockUriInfo, exception, "message", "resource"); Assert.assertTrue(true); }
From source file:es.upm.fiware.rss.expenditureLimit.server.exceptionhandles.test.ExpenditureLimitExceptionMapperTest.java
License:Open Source License
public void toResponse() throws Exception { UriInfo mockUriInfo = Mockito.mock(UriInfo.class); Mockito.when(mockUriInfo.getAbsolutePath()).thenReturn(new URI("http://www.test.com/go")); ReflectionTestUtils.setField(mapper, "ui", mockUriInfo); RSSException e = new RSSException("RssException"); Response response = mapper.toResponse(e); Assert.assertTrue(true);// www. j a v a 2 s .co m GenericJDBCException ex = new GenericJDBCException("sql", new SQLException("reason")); response = mapper.toResponse(ex); Assert.assertTrue(true); JDBCConnectionException ex1 = new JDBCConnectionException("sql", new SQLException("reason")); response = mapper.toResponse(ex1); Assert.assertTrue(true); NotFoundException ex2 = new NotFoundException(); response = mapper.toResponse(ex2); Assert.assertTrue(true); Exception ex3 = new Exception("RssException"); response = mapper.toResponse(ex3); Assert.assertTrue(true); Exception ex4 = new Exception("RssException", ex); response = mapper.toResponse(ex4); Assert.assertTrue(true); Exception ex5 = new Exception("RssException", ex1); response = mapper.toResponse(ex5); Assert.assertTrue(true); }
From source file:org.springframework.orm.hibernate3.HibernateTemplateTests.java
License:Apache License
@Test public void testFallbackExceptionTranslation() throws HibernateException { SQLException sqlEx = new SQLException("argh", "27"); final GenericJDBCException gjex = new GenericJDBCException("mymsg", sqlEx); try {/* w ww .j av a2 s .c o m*/ hibernateTemplate.execute(new HibernateCallback<Object>() { @Override public Object doInHibernate(org.hibernate.Session session) throws HibernateException { throw gjex; } }); fail("Should have thrown DataIntegrityViolationException"); } catch (DataIntegrityViolationException ex) { // expected assertEquals(sqlEx, ex.getCause()); assertTrue(ex.getMessage().indexOf("mymsg") != -1); } }
From source file:org.springframework.orm.hibernate3.HibernateTransactionManagerTests.java
License:Apache License
private void doTestTransactionCommitWithFlushFailure(boolean fallbackTranslation) throws Exception { Connection con = mock(Connection.class); final SessionFactory sf = mock(SessionFactory.class); Session session = mock(Session.class); Transaction tx = mock(Transaction.class); given(sf.openSession()).willReturn(session); given(session.beginTransaction()).willReturn(tx); given(session.isOpen()).willReturn(true); SQLException sqlEx = new SQLException("argh", "27"); Exception rootCause = null;//from w w w .j a v a2s .c om if (fallbackTranslation) { GenericJDBCException jdbcEx = new GenericJDBCException("mymsg", sqlEx); rootCause = sqlEx; willThrow(jdbcEx).given(tx).commit(); } else { ConstraintViolationException jdbcEx = new ConstraintViolationException("mymsg", sqlEx, null); rootCause = jdbcEx; willThrow(jdbcEx).given(tx).commit(); } given(session.isConnected()).willReturn(true); given(session.connection()).willReturn(con); HibernateTransactionManager tm = new HibernateTransactionManager(sf); TransactionTemplate tt = new TransactionTemplate(tm); final List l = new ArrayList(); l.add("test"); assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf)); assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive()); try { tt.execute(new TransactionCallback() { @Override public Object doInTransaction(TransactionStatus status) { assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf)); HibernateTemplate ht = new HibernateTemplate(sf); return ht.executeFind(new HibernateCallback() { @Override public Object doInHibernate(org.hibernate.Session session) throws HibernateException { return l; } }); } }); fail("Should have thrown DataIntegrityViolationException"); } catch (DataIntegrityViolationException ex) { // expected assertEquals(rootCause, ex.getCause()); assertTrue(ex.getMessage().contains("mymsg")); } assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf)); assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive()); verify(session).close(); verify(tx).rollback(); }
From source file:testerGeneral.Main.java
public static void init() { File archivoDeConexionDBRemota = new File(System.getProperty("user.dir") + File.separator + "db_param.cfg"); ConexionManagerTesterGeneral datasource = (ConexionManagerTesterGeneral) ContextManager .getBizObject("dataSource"); try {//from w ww . j a v a 2 s . c o m try { datasource.getConnection(); Util.SMALL_ICON = Constantes.IMG_ICON_SMALL; Util.obtenerNombrePC(); AuditoriaDefinition auditoriaService = (AuditoriaDefinition) ContextManager .getBizObject("auditoriaService"); Auditoria auditoria = new Auditoria(); auditoria.setAudFecha(new Date()); auditoriaService.getAll(auditoria); // Se borra el log anterior a los das especificados en el panel de // control. testerGeneral.persistence.impl.Util.borrarAuditoriasAnterioresAXDias(); /* * Si la actualizacin anterior inclua ejecutar un archivo de * script (actualizar_db.sql), se actualiza con ese archivo la DB * del programa. */ GestorDBBackup.ejecutarSentenciaSQL(); try { /* Si se baj una nueva versin del GestorActualizaciones.jar, se la activa.*/ //GestorActualizacionesUtil.actualizarGestorActualizaciones(); /* Se revisa si hay una nueva versin del sistema al iniciar.*/ GestorActualizaciones gestorActualizaciones = new GestorActualizaciones(); gestorActualizaciones.start(); } catch (Exception ex) { } // Hilo de backup automtico al iniciar GestorDBBackup gestorBackup = new GestorDBBackup(); Thread hiloBackupAutomatico = new Thread(gestorBackup); hiloBackupAutomatico.start(); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { ToolTipManager.sharedInstance().setInitialDelay(500); ToolTipManager.sharedInstance().setDismissDelay(15000); try { UIManager.setLookAndFeel(new SubstanceCremeLookAndFeel()); } catch (Exception e) { throw new RuntimeException(e); } new FrameContenedor().setVisible(true); Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler()); System.setProperty("sun.awt.exception.handler", MyExceptionHandler.class.getName()); } }); } catch (Exception e) { if (archivoDeConexionDBRemota.exists()) mostrarFrameJDBCRemoto(); else throw new GenericJDBCException(null, null); } } catch (GenericJDBCException ex) { mostrarError( "Se ha detectado que existe otra instancia de la aplicacin que se est ejecutando. Por favor cierre dicha instancia antes de continuar."); log.error(ex.getMessage(), ex); System.exit(1); } catch (Exception exc) { throw new RuntimeException(exc); } }