List of usage examples for junit.framework Assert fail
static public void fail(String message)
From source file:eu.trentorise.smartcampus.ac.provider.repository.persistence.AcDaoPersistenceImplTest.java
public void testCreateUser() { User user = new User(); user.setAuthToken("token_test"); user.setExpTime((long) 3600); user.setSocialId((long) 1004); // test user definition Authority auth1 = new Authority(); auth1.setName("auth1"); auth1.setRedirectUrl("url_auth1"); Attribute attr = new Attribute(); attr.setKey("projectName"); attr.setValue("SC"); attr.setAuthority(auth1);//from www .j a v a2s .c om List<Attribute> attrs = new ArrayList<Attribute>(); attrs.add(attr); user.setAttributes(attrs); Assert.assertNull(dao.readUser("token_test")); dao.create(user); Assert.assertNotNull(dao.readUser("token_test")); user = new User(); user.setAuthToken("token_test1"); user.setExpTime((long) 3600); user.setSocialId((long) 1004); try { dao.create(user); Assert.fail("Eception not throw"); } catch (IllegalArgumentException e) { } }
From source file:org.opencastproject.remotetest.server.YoutubeDistributionRestEndpointTest.java
private void retract() throws Exception, UnsupportedEncodingException, IOException, InterruptedException { HttpPost postStart = new HttpPost(BASE_URL + "/youtube/retract"); ArrayList<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("mediapackage", getSampleMediaPackage())); formParams.add(new BasicNameValuePair("elementId", "track-1")); postStart.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); // Ensure we get a 200 OK HttpResponse response = client.execute(postStart); Assert.assertEquals("Error during retract", 200, response.getStatusLine().getStatusCode()); String jobXML = EntityUtils.toString(response.getEntity()); long jobId = getJobId(jobXML); // Check if job is finished // Ensure that the job finishes successfully int attempts = 0; while (true) { if (++attempts == 20) Assert.fail("ServiceRegistry rest endpoint test has hung"); HttpGet getJobMethod = new HttpGet(BASE_URL + "/services/job/" + jobId + ".xml"); String getResponse = EntityUtils.toString(client.execute(getJobMethod).getEntity()); String state = getJobStatus(getResponse); if ("FINISHED".equals(state)) break; if ("FAILED".equals(state)) Assert.fail("Retract from youtube failed! (Job " + jobId + "). Do it manually for video!"); System.out.println("Job " + jobId + " is " + state); Thread.sleep(5000);/*w ww. j a v a2 s.c o m*/ } }
From source file:org.opencastproject.remotetest.server.YouTubePublicationRestEndpointTest.java
private void retract(String mediaPackageXml) throws Exception, UnsupportedEncodingException, IOException, InterruptedException { HttpPost postStart = new HttpPost(BASE_URL + "/youtube/retract"); ArrayList<NameValuePair> formParams = new ArrayList<NameValuePair>(); formParams.add(new BasicNameValuePair("mediapackage", mediaPackageXml)); postStart.setEntity(new UrlEncodedFormEntity(formParams, "UTF-8")); // Ensure we get a 200 OK HttpResponse response = client.execute(postStart); Assert.assertEquals("Error during retract", 200, response.getStatusLine().getStatusCode()); String jobXML = EntityUtils.toString(response.getEntity()); long jobId = getJobId(jobXML); // Check if job is finished // Ensure that the job finishes successfully int attempts = 0; while (true) { if (++attempts == 20) Assert.fail("ServiceRegistry rest endpoint test has hung"); HttpGet getJobMethod = new HttpGet(BASE_URL + "/services/job/" + jobId + ".xml"); String getResponse = EntityUtils.toString(client.execute(getJobMethod).getEntity()); String state = getJobStatus(getResponse); if ("FINISHED".equals(state)) { // Get Mediapackage Publication String payload = getPayloadFromJob(jobXML); Assert.assertNotNull(payload); break; }//from ww w. ja v a2 s. co m if ("FAILED".equals(state)) Assert.fail("Retract from youtube failed! (Job " + jobId + "). Do it manually for video!"); System.out.println("Job " + jobId + " is " + state); Thread.sleep(5000); } }
From source file:org.jasig.schedassist.impl.SchedulingAssistantServiceImplTest.java
/** * Expect a DataAccessException to bubble up. * @throws Exception//from w ww. j av a 2s .c om */ @Test public void testScheduleAppointmentAvailableScheduleDaoUnavailable() throws Exception { // construct a schedule owner MockCalendarAccount ownerAccount = new MockCalendarAccount(); ownerAccount.setUsername("user1"); DefaultScheduleOwnerImpl owner = new DefaultScheduleOwnerImpl(ownerAccount, 1); // construct a schedule visitor MockCalendarAccount visitorAccount = new MockCalendarAccount(); visitorAccount.setUsername("user2"); DefaultScheduleVisitorImpl visitor = new DefaultScheduleVisitorImpl(visitorAccount); // construct target availableblock for appointment AvailableBlock targetBlock = AvailableBlockBuilder.createBlock("20091111-1330", "20091111-1400", 1); AvailableScheduleDao mockScheduleDao = EasyMock.createMock(AvailableScheduleDao.class); EasyMock.expect(mockScheduleDao.retrieveTargetBlock(owner, targetBlock.getStartTime())) .andThrow(new CannotGetJdbcConnectionException("database unavailable", new SQLException())); EasyMock.replay(mockScheduleDao); SchedulingAssistantServiceImpl serviceImpl = new SchedulingAssistantServiceImpl(); serviceImpl.setAvailableScheduleDao(mockScheduleDao); try { serviceImpl.scheduleAppointment(visitor, owner, targetBlock, "description"); Assert.fail("expected CannotGetJdbcConnectionException not thrown"); } catch (CannotGetJdbcConnectionException e) { // success } EasyMock.verify(mockScheduleDao); }
From source file:com.cubusmail.server.user.UserAccountDaoTest.java
@Test public void testDeleteIdentities() { try {/* w w w. j a v a2 s. c o m*/ int identityCount = this.testUserAccount.getIdentities().size(); this.userAccountDao.saveIdentities(this.testUserAccount); List<Long> ids = new ArrayList<Long>(); ids.add(this.testUserAccount.getIdentities().get(0).getId()); ids.add(this.testUserAccount.getIdentities().get(1).getId()); this.userAccountDao.deleteIdentities(ids); UserAccount testUserAccount2 = this.userAccountDao.getUserAccountByUsername("testuser"); Assert.assertEquals(testUserAccount2.getIdentities().size(), identityCount - 2); } catch (Exception e) { log.error(e.getMessage(), e); Assert.fail(e.getMessage()); } }
From source file:cz.PA165.vozovyPark.dao.ServiceIntervalDAOTest.java
/** * *//*from www. ja va 2 s . co m*/ @Test public void testValidCreateAndGetById() { try { Vehicle toyota = ServiceIntervalDAOTest.getVehicle("Toyota", 20000, "V-8", "Supra", UserClassEnum.MANAGER, "78-88as-ouu899", 2004); vehicleDao.createVehicle(toyota); ServiceInterval interval1 = ServiceIntervalDAOTest.getServiceInterval(new ArrayList<Date>(), "Prehodeni koles", 7, toyota); serviceIntervalDAO.createSI(interval1); System.out.println("Id to load: " + interval1.getId()); ServiceInterval loaded = serviceIntervalDAO.getById(interval1.getId()); Assert.assertEquals("Inserted entity is not same as loaded", interval1, loaded); } catch (Exception ex) { Assert.fail("Unexpected exception was throwed: " + ex + " " + ex.getMessage()); } }
From source file:BQJDBC.QueryResultTest.QueryResultTest.java
@Test public void QueryResultTest02() { final String sql = "SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus ORDER BY corpus LIMIT 5"; final String description = "The book names of shakespeare #GROUP_BY #ORDER_BY"; String[][] expectation = new String[][] { { "1kinghenryiv", "1kinghenryvi", "2kinghenryiv", "2kinghenryvi", "3kinghenryvi" } }; this.logger.info("Test number: 02"); this.logger.info("Running query:" + sql); java.sql.ResultSet Result = null; try {/*from ww w. ja v a2 s. c om*/ Result = QueryResultTest.con.createStatement().executeQuery(sql); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail("SQLException" + e.toString()); } Assert.assertNotNull(Result); this.logger.debug(description); HelperFunctions.printer(expectation); try { Assert.assertTrue("Comparing failed in the String[][] array", this.comparer(expectation, BQSupportMethods.GetQueryResult(Result))); } catch (SQLException e) { this.logger.error("SQLexception" + e.toString()); Assert.fail(e.toString()); } }
From source file:com.redhat.demo.CrmTest.java
/** * HTTP POST http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of * the add_customer.json file to add a new customer to the system. * <p/>/* w w w. j av a2 s . com*/ * On the server side, it matches the CustomerService's addCustomer() method * * @throws Exception */ @Test public void postCustomerTestJson() throws IOException { LOG.info("Sent HTTP POST request to add customer"); String inputFile = this.getClass().getResource("/add_customer.json").getFile(); File input = new File(inputFile); PostMethod post = new PostMethod(CUSTOMER_SERVICE_URL); post.addRequestHeader("Accept", "application/json"); RequestEntity entity = new FileRequestEntity(input, "application/json; charset=ISO-8859-1"); post.setRequestEntity(entity); HttpClient httpclient = new HttpClient(); String res = ""; try { int result = httpclient.executeMethod(post); LOG.info("Response status code: " + result); LOG.info("Response body: "); res = post.getResponseBodyAsString(); LOG.info(res); } catch (IOException e) { LOG.error("Error connecting to {}", CUSTOMER_SERVICE_URL); LOG.error( "You should build the 'rest' quick start and deploy it to a local Fabric8 before running this test"); LOG.error("Please read the README.md file in 'rest' quick start root"); Assert.fail("Connection error"); } finally { // Release current connection to the connection pool once you are // done post.releaseConnection(); } Assert.assertTrue(res.contains("Jack")); }
From source file:org.atemsource.atem.utility.compare.OrderableCollectionComparatorTest.java
@Test public void testAddedAndChangedUsingId() { EntityA a1 = createEntityA();/*from w ww .j av a 2 s.co m*/ EntityB b1 = createEntityB(); EntityA a2 = createEntityA(); EntityB b2 = createEntityB(); EntityB b3 = createEntityB(); b1.setInteger(1); b1.setId("1"); b2.setInteger(5); b2.setId("2"); b3.setInteger(2); b3.setId("1"); a2.getList().add(b1); a2.getList().add(b2); a1.getList().add(b3); Set<Difference> differences = comparisonAssociativeId.getDifferences(a1, a2); Assert.assertEquals(2, differences.size()); for (Difference difference : differences) { if (difference instanceof Addition) { Assert.assertEquals("list.1", ((Addition) difference).getPath().toString()); } else if (difference instanceof AttributeChange) { Assert.assertEquals("list.0.integer", ((AttributeChange) difference).getPath().toString()); } else { Assert.fail("we expect a change and an addition"); } } }
From source file:eu.stratosphere.pact.runtime.task.CoGroupTaskTest.java
@Test public void testSortBoth2CoGroupTask() { int keyCnt1 = 200; int valCnt1 = 2; int keyCnt2 = 200; int valCnt2 = 4; super.initEnvironment(6 * 1024 * 1024); super.addInput(new UniformPactRecordGenerator(keyCnt1, valCnt1, false), 1); super.addInput(new UniformPactRecordGenerator(keyCnt2, valCnt2, false), 2); super.addOutput(this.outList); CoGroupTask<PactRecord, PactRecord, PactRecord> testTask = new CoGroupTask<PactRecord, PactRecord, PactRecord>(); super.getTaskConfig().setLocalStrategy(LocalStrategy.SORT_BOTH_MERGE); super.getTaskConfig().setMemorySize(6 * 1024 * 1024); super.getTaskConfig().setNumFilehandles(4); final int[] keyPos1 = new int[] { 0 }; final int[] keyPos2 = new int[] { 0 }; @SuppressWarnings("unchecked") final Class<? extends Key>[] keyClasses = (Class<? extends Key>[]) new Class[] { PactInteger.class }; PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(0), keyPos1, keyClasses); PactRecordComparatorFactory.writeComparatorSetupToConfig(super.getTaskConfig().getConfiguration(), super.getTaskConfig().getPrefixForInputParameters(1), keyPos2, keyClasses); super.registerTask(testTask, MockCoGroupStub.class); try {/*from ww w . j a va2 s. c o m*/ testTask.invoke(); } catch (Exception e) { LOG.debug(e); Assert.fail("Invoke method caused exception."); } int expCnt = valCnt1 * valCnt2 * Math.min(keyCnt1, keyCnt2) + Math.max(keyCnt1, keyCnt2) - Math.min(keyCnt1, keyCnt2); Assert.assertTrue("Resultset size was " + this.outList.size() + ". Expected was " + expCnt, this.outList.size() == expCnt); this.outList.clear(); }