List of usage examples for junit.framework Assert fail
static public void fail(String message)
From source file:de.hybris.vjdbc.VirtualDriverTest.java
@Test public void testConnectWithAcceptedFlexUrlWithSomeParams() throws Exception { final Properties props = new Properties(); Mockito.when(commandSinkProvider.create( Mockito.eq("http://localhost:9001/vjdbc/vjdbcServlet?tenant=my¶m=X&flexMode=true"), Mockito.eq(OF_EMPTY_MAP))).thenThrow(new ExpectedException()); try {//from w w w . ja v a2 s .com driver.connect( "jdbc:hybris:flexiblesearch:http://localhost:9001/vjdbc/vjdbcServlet?tenant=my¶m=X,booSystem", props); Assert.fail("should have failed"); } catch (SQLException e) { assertFirstLineOfSQLException("de.hybris.vjdbc.VirtualDriverTest$ExpectedException", e); } Mockito.verify(virtualConnectionBuilder).setProperties(props); Mockito.verify(virtualConnectionBuilder, Mockito.times(0)).setUrl(""); Mockito.verify(virtualConnectionBuilder).setDataSourceString(Mockito.eq("booSystem")); }
From source file:com.hoccer.tools.TestHelper.java
public static void assertSmaller(String message, double maximum, double measured) { if (maximum < measured) { Assert.fail(message + " but " + maximum + " is smaller than " + measured); }/*ww w .ja v a 2 s.com*/ }
From source file:io.fabric8.quickstarts.fabric.rest.secure.CrmSecureTest.java
/** * HTTP POST http://localhost:8181/cxf/crm/customerservice/customers is used to upload the contents of * the add_customer.xml file to add a new customer to the system. * <p/>// ww w .j a va 2 s .c o m * On the server side, it matches the CustomerService's addCustomer() method * * @throws Exception */ @Test public void postCustomerTest() throws IOException { LOG.info("============================================"); LOG.info("Sent HTTP POST request to add customer"); String inputFile = this.getClass().getResource("/add_customer.xml").getFile(); File input = new File(inputFile); PostMethod post = new PostMethod(CUSTOMER_SERVICE_URL); post.getHostAuthState().setAuthScheme(scheme); post.addRequestHeader("Accept", "text/xml"); RequestEntity entity = new FileRequestEntity(input, "text/xml; charset=ISO-8859-1"); post.setRequestEntity(entity); 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:amqp.spring.camel.component.SpringAMQPConsumerTest.java
@Test public void testHandleException() { try {/* w ww. java2s . c o m*/ Object result = context().createProducerTemplate().requestBody("spring-amqp::test.f", "testBody"); Assert.fail("Should have thrown exception up to caller but received object: " + result); } catch (RuntimeException e) { // success } }
From source file:com.ibm.jaggr.service.impl.config.BundleVersionsHashTest.java
@Test public void testBundleVersionsHash() throws Exception { URI tmpDir = new File(System.getProperty("user.dir")).toURI(); IAggregator mockAggregator = TestUtils.createMockAggregator(); InitParams initParams = new InitParams(Arrays .asList(new InitParam[] { new InitParam("propName", "getBundleVersionsHash", mockAggregator) })); BundleVersionsHash bvh = new BundleVersionsHash(); IServiceReference mockServiceReference = EasyMock.createNiceMock(IServiceReference.class); IServiceReference[] serviceReferences = new IServiceReference[] { mockServiceReference }; IPlatformServices mockPlatformServices = EasyMock.createNiceMock(IPlatformServices.class); IAggregatorExtension mockExtension = EasyMock.createMock(IAggregatorExtension.class); EasyMock.expect(mockAggregator.getPlatformServices()).andReturn(mockPlatformServices).anyTimes(); EasyMock.replay(mockAggregator);/*from w ww . j a v a 2 s . c o m*/ Dictionary<String, String> dict = new Hashtable<String, String>(); dict.put("name", mockAggregator.getName()); EasyMock.expect(mockPlatformServices.getService(mockServiceReference)).andReturn(bvh).anyTimes(); EasyMock.expect(mockExtension.getInitParams()).andReturn(initParams).anyTimes(); EasyMock.expect(mockPlatformServices.getServiceReferences(IConfigScopeModifier.class.getName(), "(name=" + mockAggregator.getName() + ")")).andReturn(serviceReferences).anyTimes(); EasyMock.replay(mockServiceReference, mockPlatformServices, mockExtension); bvh.initialize(mockAggregator, mockExtension, null); EasyMock.verify(mockPlatformServices); Bundle mockBundle1 = EasyMock.createMock(Bundle.class); Bundle mockBundle2 = EasyMock.createMock(Bundle.class); PowerMock.mockStatic(Platform.class); EasyMock.expect(Platform.getBundle("com.test.bundle1")).andReturn(mockBundle1).anyTimes(); EasyMock.expect(Platform.getBundle("com.test.bundle2")).andReturn(mockBundle2).anyTimes(); EasyMock.expect(Platform.getBundle("com.test.bundle3")).andReturn(null).anyTimes(); final Dictionary<String, String> bundle1Headers = new Hashtable<String, String>(); final Dictionary<String, String> bundle2Headers = new Hashtable<String, String>(); EasyMock.expect(mockBundle1.getHeaders()).andAnswer(new IAnswer<Dictionary<String, String>>() { @Override public Dictionary<String, String> answer() throws Throwable { return bundle1Headers; } }).anyTimes(); EasyMock.expect(mockBundle2.getHeaders()).andAnswer(new IAnswer<Dictionary<String, String>>() { @Override public Dictionary<String, String> answer() throws Throwable { return bundle2Headers; } }).anyTimes(); PowerMock.replay(Platform.class, mockBundle1, mockBundle2); bundle1Headers.put("Bnd-LastModified", "123456789"); bundle2Headers.put("Bnd-LastModified", "234567890"); bundle1Headers.put("Bundle-Version", "1.2.3.20140414"); bundle2Headers.put("Bundle-Version", "1.2.3.20140412"); String config = "{cacheBust:getBundleVersionsHash(['Bundle-Version', 'Bnd-LastModified'], 'com.test.bundle1', 'com.test.bundle2')}"; ConfigImpl cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); String cacheBust = cfg.getCacheBust(); bundle1Headers.put("Bnd-LastModified", "123456780"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertFalse(cacheBust.equals(cfg.getCacheBust())); bundle1Headers.put("Bnd-LastModified", "123456789"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertEquals(cacheBust, cfg.getCacheBust()); bundle2Headers.put("Bundle-Version", "1.2.4"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertFalse(cacheBust.equals(cfg.getCacheBust())); bundle2Headers.put("Bundle-Version", "1.2.3.20140412"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertEquals(cacheBust, cfg.getCacheBust()); // Test that when header names are not specified, it defaults to 'Bundle-Version'. config = "{cacheBust:getBundleVersionsHash('com.test.bundle1', 'com.test.bundle2')}"; cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); cacheBust = cfg.getCacheBust(); bundle1Headers.put("Bnd-LastModified", "123456780"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertEquals(cacheBust, cfg.getCacheBust()); bundle2Headers.put("Bundle-Version", "1.2.4"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertFalse(cacheBust.equals(cfg.getCacheBust())); bundle2Headers.put("Bundle-Version", "1.2.3.20140412"); cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertEquals(cacheBust, cfg.getCacheBust()); // Ensure exception thrown if a specified bundle is not found config = "{cacheBust:getBundleVersionsHash('com.test.bundle1', 'com.test.bundle2', 'com.test.bundle3')}"; try { cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.fail("Expected exception"); } catch (WrappedException ex) { Assert.assertTrue(NotFoundException.class.isInstance(ex.getCause())); } // ensure exception thrown if argument is wrong type config = "{cacheBust:getBundleVersionsHash({})}"; try { cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.fail("Expected exception"); } catch (WrappedException ex) { Assert.assertTrue(IllegalArgumentException.class.isInstance(ex.getCause())); } // ensure value is null if no bundle names specified config = "{cacheBust:getBundleVersionsHash()}"; cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertNull(cfg.getCacheBust()); config = "{cacheBust:getBundleVersionsHash(['Bundle-Version'])}"; cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertNull(cfg.getCacheBust()); config = "{}"; cfg = new ConfigImpl(mockAggregator, tmpDir, config, true); Assert.assertNull(cfg.getCacheBust()); // Ensure that cacheBust is a base64 encoded array of 16 bytes. byte[] bytes = Base64.decodeBase64(cacheBust); Assert.assertEquals(16, bytes.length); }
From source file:com.mnxfst.testing.server.cfg.TestPTestServerConfigurationParser.java
@Test public void testEvaluateNodeListWithNullInput() { try {//from ww w . j a v a 2 s . c o m (new PTestServerConfigurationParser()).evaluateNodeList(null, null); Assert.fail("Expression is null and document is null"); } catch (XPathExpressionException e) { } }
From source file:org.opencastproject.remotetest.server.LtiAuthenticationTest.java
@Test public void testLtiLaunchFromUnknownConsumer() throws Exception { // Construct a POST message with the oauth parameters String nonce = UUID.randomUUID().toString(); String timestamp = Long.toString(TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis())); OAuthMessage oauthMessage = new OAuthMessage(OAuthMessage.POST, Main.BASE_URL + "/lti", null); oauthMessage.addParameter(OAuth.OAUTH_CONSUMER_KEY, CONSUMER_KEY); oauthMessage.addParameter(OAuth.OAUTH_SIGNATURE_METHOD, OAuth.HMAC_SHA1); oauthMessage.addParameter(OAuth.OAUTH_NONCE, nonce); oauthMessage.addParameter(OAuth.OAUTH_TIMESTAMP, timestamp); // Add some LTI parameters oauthMessage.addParameter("user_id", LTI_CONSUMER_USER); oauthMessage.addParameter("context_id", LTI_CONSUMER_CONTEXT); oauthMessage.addParameter("custom_test", "true"); // Sign the request OAuthConsumer consumer = new OAuthConsumer(null, CONSUMER_KEY, "wrong secret", null); OAuthAccessor accessor = new OAuthAccessor(consumer); oauthMessage.sign(accessor);/*from w w w. ja v a 2s .c o m*/ // Get the response try { oauthClient.invoke(oauthMessage, ParameterStyle.BODY); Assert.fail("OAuth with a bad signature should result in an exception"); } catch (OAuthProblemException e) { // expected } }
From source file:org.sakaiproject.crudplus.logic.test.CrudPlusLogicImplTest.java
/** * Test method for {@link org.sakaiproject.crudplus.logic.impl.CrudPlusLogicImpl#getItemById(java.lang.Long)}. *///from ww w. j a va 2 s .c om public void testGetItemById() { CrudPlusItem item = logicImpl.getItemById(item1.getId()); Assert.assertNotNull(item); Assert.assertEquals(item, item1); CrudPlusItem baditem = logicImpl.getItemById(new Long(9999999)); Assert.assertNull(baditem); try { logicImpl.getItemById(null); Assert.fail("Should have thrown IllegalArgumentException"); } catch (IllegalArgumentException e) { Assert.assertNotNull(e.getMessage()); log.info("Could not get null item (this is correct)"); } }
From source file:de.hybris.platform.commercefacades.customer.DefaultCustomerFacadeIntegrationTest.java
@Test public void testUpdatePassword() throws TokenInvalidatedException { final CustomerModel customerModel = userService.getUserForUID(TEST_USER_UID, CustomerModel.class); Assert.assertNull(customerModel.getToken()); customerFacade.forgottenPassword("DeJol"); modelService.refresh(customerModel); final String token = customerModel.getToken(); Assert.assertNotNull(token);/*from w ww. j a v a 2s.c o m*/ customerFacade.updatePassword(token, NEW_PASSWORD); modelService.refresh(customerModel); Assert.assertNull(customerModel.getToken()); final String expected = passwordEncoderService.encode(customerModel, NEW_PASSWORD, "md5"); Assert.assertEquals(expected, customerModel.getEncodedPassword()); try { customerFacade.updatePassword(token, NEW_PASSWORD_2); Assert.fail("TokenInvalidatedException expected"); } catch (final TokenInvalidatedException e) { modelService.refresh(customerModel); Assert.assertEquals(expected, customerModel.getEncodedPassword()); } }
From source file:com.aliyun.oss.integrationtests.ImageTest.java
@Test public void testFormatImage() { String style = "image/format,png"; // ? try {/*from w w w .j ava2s . c om*/ GetObjectRequest request = new GetObjectRequest(bucketName, originalImage); request.addParameter("x-oss-process", style); OSSObject ossObject = ossClient.getObject(request); ossClient.putObject(bucketName, newImage, ossObject.getObjectContent()); ImageInfo imageInfo = getImageInfo(bucketName, newImage); Assert.assertEquals(imageInfo.getHeight(), 267); Assert.assertEquals(imageInfo.getWidth(), 400); Assert.assertEquals(imageInfo.getSize(), 160733); Assert.assertEquals(imageInfo.getFormat(), "png"); } catch (Exception e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }