Example usage for junit.framework Assert fail

List of usage examples for junit.framework Assert fail

Introduction

In this page you can find the example usage for junit.framework Assert fail.

Prototype

static public void fail(String message) 

Source Link

Document

Fails a test with the given message.

Usage

From source file:de.akquinet.gomobile.androlog.test.PostReporterTest.java

public void setUp() {
    try {/* ww  w  . ja v a2  s  . c om*/
        Assert.assertTrue("No SDCard or not the permission to write",
                Environment.getExternalStorageDirectory().canWrite());
        // Create files
        Properties propsDefault = new Properties();
        propsDefault.setProperty(Constants.ANDROLOG_ACTIVE, "true");
        propsDefault.setProperty(Constants.ANDROLOG_REPORT_ACTIVE, "true");
        propsDefault.setProperty(Constants.ANDROLOG_REPORT_REPORTERS,
                "de.akquinet.android.androlog.reporter.NoopReporter");

        Properties propsActive = new Properties();
        propsActive.setProperty(Constants.ANDROLOG_ACTIVE, "true");
        propsActive.setProperty(Constants.ANDROLOG_REPORT_ACTIVE, "true");
        propsActive.setProperty(Constants.ANDROLOG_REPORT_REPORTERS,
                "de.akquinet.android.androlog.reporter.PostReporter");
        propsActive.setProperty(Constants.ANDROLOG_REPORT_EXCEPTION_HANDLER_PROPAGATION, "false");

        propsActive.setProperty(PostReporter.ANDROLOG_REPORTER_POST_URL, URL);

        testContext = new File(Environment.getExternalStorageDirectory(),
                getContext().getPackageName() + ".properties");
        testContext.createNewFile();
        (new File(Environment.getExternalStorageDirectory(), "tmp")).mkdir();

        FileOutputStream out = new FileOutputStream(testContext);
        propsActive.store(out, "Enable Androlog file");
        out.close();
    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:org.wso2.identity.integration.test.entitlement.EntitlementSecurityTestCase.java

@Test(alwaysRun = true, description = "Test reflected XSS in XACML policy editor")
public void testXSS() throws IOException {
    HttpGet request = new HttpGet(url);
    HttpResponse response = httpClient.execute(request);

    // If HTTP status code is 200...
    if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_OK) {
        BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line;/*w w w  .ja  v  a2  s  . co  m*/
        boolean success = false;
        while ((line = rd.readLine()) != null) {
            success = line.equals(StringEscapeUtils.escapeHtml(value));
            if (success) {
                break;
            }
        }

        rd.close();

        if (!success) {
            Assert.fail("Content is not encoded");
        }
    }

    // If HTTP status code is 405...
    else if (response.getStatusLine().getStatusCode() == HttpServletResponse.SC_METHOD_NOT_ALLOWED) {
        log.info("GET request to XACML policy editor is blocked as expected");
    }

    // If HTTP status code is neither 200 nor 405...
    else {
        log.info("Unknown response");
    }
}

From source file:dk.netarkivet.harvester.harvesting.MetadataFileWriterTester.java

public void testMetadataFileWriterArc() {
    File metafile = new File("metadata.arc");
    MetadataFileWriter mdfw = MetadataFileWriterArc.createWriter(metafile);

    String uri = "http://www.netarkivet.dk/";
    long ctm = System.currentTimeMillis();

    SecureRandom random = new SecureRandom();
    byte[] payload = new byte[8192];
    random.nextBytes(payload);//  w ww  . j a  va  2 s  .c o m

    try {
        mdfw.write(uri, "application/binary", "127.0.0.1", ctm, payload);
        mdfw.close();
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail("Unexpected exception!");
    }

    metafile.deleteOnExit();

    File metadataArcFile = new File(TestInfo.WORKING_DIR, "42-metadata-1.arc");
    MetadataFileWriter mfwa = MetadataFileWriterArc.createWriter(metadataArcFile);
    for (File f : logsDir.listFiles()) {
        mfwa.writeFileTo(f, "metadata://netarkivet.dk/crawl/logs/" + f.getName(), "text/plain");
    }
}

From source file:com.amazonaws.http.AmazonHttpClientRequestTimeoutTest.java

@Test(timeout = 10 * 1000)
public void testRequestTimeoutDisabled() {
    ProblematicServer server = new ProblematicServer(ProblematicServer.ServerIssue.UNRESPONSIVE);
    server.startServer();/*from w  w w .j  av a  2s  .  c  o  m*/

    String localhostEndpoint = "http://localhost:" + server.getPort();
    Request<?> request = new EmptyHttpRequest(localhostEndpoint, HttpMethodName.GET);

    AmazonHttpClient httpClient = new AmazonHttpClient(
            new ClientConfiguration().withSocketTimeout(1 * 1000).withRequestTimeout(0).withMaxErrorRetry(0));

    try {
        httpClient.execute(request, new NullResponseHandler(), new NullErrorResponseHandler(),
                new ExecutionContext());
        Assert.fail("Client-side socket read timeout is expected!");
    } catch (AmazonClientException e) {
        Assert.assertTrue(e.getCause() instanceof SocketTimeoutException);
        /* The internal request timer should not have been instantiated. */
        ScheduledThreadPoolExecutor httpRequestTimer = httpClient.getHttpRequestTimer().getExecutor();
        Assert.assertNull(httpRequestTimer);
    }

    server.stopServer();
    httpClient.shutdown();
}

From source file:com.atlassian.jira.functest.framework.setup.JiraSetupInstanceHelper.java

private void detectJohnson() {
    final String response = tester.getDialog().getResponseText();
    if (response.contains("JIRA Access Constraints")) {
        FuncTestOut.log("Test failed because we are getting the following johnson page:\n" + response);
        Assert.fail("It appears that JIRA is currenty being Johnsoned.  That cant be good!");
    }//from  w w w  . ja  v a2  s. c om
}

From source file:com.aliyun.oss.integrationtests.ImageProcessTest.java

@Test
public void testResizeImage() {
    String style = "image/resize,m_fixed,w_100,h_100"; // 

    try {//from  ww w  .j a v  a 2 s  . c om
        GetObjectRequest request = new GetObjectRequest(bucketName, originalImage);
        request.setProcess(style);

        OSSObject ossObject = ossClient.getObject(request);
        ossClient.putObject(bucketName, newImage, ossObject.getObjectContent());

        ImageInfo imageInfo = getImageInfo(bucketName, newImage);
        Assert.assertEquals(imageInfo.getHeight(), 100);
        Assert.assertEquals(imageInfo.getWidth(), 100); // 3587
        Assert.assertEquals(imageInfo.getFormat(), "jpg");

    } catch (Exception e) {
        e.printStackTrace();
        Assert.fail(e.getMessage());
    }
}

From source file:com.hybris.datahub.service.impl.DefaultJsonServiceTest.java

/**
 * convertTmallAuthJson//from w  w  w  .  j a  v  a  2 s  .c  om
 */
@Test
public void convertTmallAuthJson() {
    final Class<? extends DefaultJsonServiceTest> instance = getClass();
    if (instance != null) {
        final ClassLoader classLoader = instance.getClassLoader();
        if (classLoader != null) {
            String json = "";
            InputStream resourceAsStream = null;
            try {
                resourceAsStream = classLoader.getResourceAsStream(SAMPLE_TMALL_AUTH_JSON);
                json = IOUtils.toString(resourceAsStream);
            } catch (final IOException e) {
                LOG.error(e.getMessage(), e);
            } finally {
                if (resourceAsStream != null) {
                    try {
                        resourceAsStream.close();
                    } catch (final IOException e) {
                        LOG.error(e.getMessage(), e);
                    }
                }
            }
            final List<Map<String, String>> csv = service.parse(json);
            final Map<String, String> raw = csv.get(0);

            Assert.assertTrue(raw.containsKey("marketplaceStoreName"));
            Assert.assertTrue(raw.containsKey("integrationId"));
            Assert.assertTrue(raw.containsKey("authorized"));
            Assert.assertEquals("TmallStore", raw.get("marketplaceStoreName"));
            Assert.assertEquals("1234567890", raw.get("integrationId"));
            Assert.assertEquals("true", raw.get("authorized"));
        }
    } else {
        Assert.fail("Class not found.");
    }
}

From source file:com.rmn.qa.aws.VmManagerTest.java

@Test
// Test if an AWS access key is not set, the appropriate exception if thrown
public void testAccessKeyNotSet() {
    MockAmazonEc2Client client = new MockAmazonEc2Client(null);
    Properties properties = new Properties();
    String region = "east";
    AwsVmManager AwsVmManager = new AwsVmManager(client, properties, region);
    try {//  www . j a v  a  2  s  .c  o m
        AwsVmManager.getCredentials();
    } catch (IllegalArgumentException e) {
        Assert.assertTrue("Message should be related to access key",
                e.getMessage().contains(AutomationConstants.AWS_ACCESS_KEY));
        return;
    }
    Assert.fail("Exception should have been throw for access key");
}

From source file:fr.msch.wissl.server.TestUsers.java

@Test
public void test() throws IOException, JSONException {
    HttpClient client = new HttpClient();

    // check the users and sessions created by TServer
    GetMethod get = new GetMethod(TServer.URL + "users");
    get.addRequestHeader("sessionId", this.user_sessionId);
    client.executeMethod(get);/*from  w  ww  .  j a  va 2  s .c  o m*/
    Assert.assertEquals(200, get.getStatusCode());
    JSONObject obj = new JSONObject(get.getResponseBodyAsString());
    JSONArray users = obj.getJSONArray("users");
    Assert.assertEquals(2, users.length());
    for (int i = 0; i < 2; i++) {
        JSONObject u = users.getJSONObject(i);
        String username = u.getString("username");
        if (username.equals(this.user_username)) {
            Assert.assertEquals(this.user_userId, u.getInt("id"));
            Assert.assertEquals(2, u.getInt("auth"));
            Assert.assertEquals(0, u.getInt("downloaded"));
        } else if (username.equals(this.admin_username)) {
            Assert.assertEquals(this.admin_userId, u.getInt("id"));
            Assert.assertEquals(1, u.getInt("auth"));
            Assert.assertEquals(0, u.getInt("downloaded"));
        } else {
            Assert.fail("Unexpected user:" + username);
        }
    }

    JSONArray sessions = obj.getJSONArray("sessions");
    Assert.assertEquals(2, sessions.length());
    for (int i = 0; i < 2; i++) {
        JSONObject s = sessions.getJSONObject(i);
        String username = s.getString("username");
        if (username.equals(this.user_username)) {
            Assert.assertEquals(this.user_userId, s.getInt("user_id"));
            Assert.assertTrue(s.getInt("last_activity") >= 0); // might be 0
            Assert.assertTrue(s.getInt("created_at") >= 0);
            Assert.assertFalse(s.has("origins")); // admin only
            Assert.assertFalse(s.has("last_played_song"));
        }
    }

    // unknown user: 404
    get = new GetMethod(TServer.URL + "user/100");
    get.addRequestHeader("sessionId", this.user_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(404, get.getStatusCode());

    // check admin user
    get = new GetMethod(TServer.URL + "user/" + this.admin_userId);
    get.addRequestHeader("sessionId", this.admin_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    JSONObject u = obj.getJSONObject("user");
    Assert.assertEquals(this.admin_userId, u.getInt("id"));
    Assert.assertEquals(this.admin_username, u.getString("username"));
    Assert.assertEquals(1, u.getInt("auth"));
    Assert.assertEquals(0, u.getInt("downloaded"));
    sessions = obj.getJSONArray("sessions");
    Assert.assertEquals(1, sessions.length());
    JSONObject s = sessions.getJSONObject(0);

    Assert.assertEquals(this.admin_userId, s.getInt("user_id"));
    Assert.assertTrue(s.getInt("last_activity") >= 0); // might be 0
    Assert.assertTrue(s.getInt("created_at") > 0);
    Assert.assertTrue(s.has("origins")); // admin only
    Assert.assertFalse(s.has("last_played_song"));
    Assert.assertTrue(obj.getJSONArray("playlists").length() == 0);

    // create a new user with user account: error 401
    PostMethod post = new PostMethod(TServer.URL + "user/add");
    post.addRequestHeader("sessionId", this.user_sessionId);
    post.addParameter("username", "new-user");
    post.addParameter("password", "new-pw");
    client.executeMethod(post);
    Assert.assertEquals(401, post.getStatusCode());

    // create new user with empty username: err 400
    post = new PostMethod(TServer.URL + "user/add");
    post.addRequestHeader("sessionId", this.admin_sessionId);
    post.addParameter("username", "");
    post.addParameter("password", "new-pw");
    post.addParameter("auth", "1");
    client.executeMethod(post);
    Assert.assertEquals(400, post.getStatusCode());

    // create new user with short password: err 400
    post = new PostMethod(TServer.URL + "user/add");
    post.addRequestHeader("sessionId", this.admin_sessionId);
    post.addParameter("username", "new-user");
    post.addParameter("password", "pw");
    post.addParameter("auth", "1");
    client.executeMethod(post);
    Assert.assertEquals(400, post.getStatusCode());

    // create new user with invalid auth: err 400
    post = new PostMethod(TServer.URL + "user/add");
    post.addRequestHeader("sessionId", this.admin_sessionId);
    post.addParameter("username", "new-user");
    post.addParameter("password", "pw");
    post.addParameter("auth", "3");
    client.executeMethod(post);
    Assert.assertEquals(400, post.getStatusCode());

    int new_userId = -1;
    String new_sessionId = null;
    String new_username = "new-user";
    String new_password = "new-pw";

    // create new user
    post = new PostMethod(TServer.URL + "user/add");
    post.addRequestHeader("sessionId", this.admin_sessionId);
    post.addParameter("username", new_username);
    post.addParameter("password", new_password);
    post.addParameter("auth", "2");
    client.executeMethod(post);
    Assert.assertEquals(200, post.getStatusCode());
    u = new JSONObject(post.getResponseBodyAsString()).getJSONObject("user");
    new_userId = u.getInt("id");
    Assert.assertEquals(new_username, u.getString("username"));
    Assert.assertEquals(2, u.getInt("auth"));

    // check new user 
    get = new GetMethod(TServer.URL + "user/" + new_userId);
    get.addRequestHeader("sessionId", this.user_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    Assert.assertTrue(obj.getJSONArray("playlists").length() == 0);
    Assert.assertEquals(0, obj.getJSONArray("sessions").length());

    // login new user
    obj = new JSONObject(this.login(new_username, new_password));
    Assert.assertEquals(new_userId, obj.getInt("userId"));
    new_sessionId = obj.getString("sessionId");

    // check if logged in with /users
    get = new GetMethod(URL + "users");
    get.addRequestHeader("sessionId", new_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    users = obj.getJSONArray("users");
    Assert.assertEquals(3, users.length());
    for (int i = 0; i < 3; i++) {
        u = users.getJSONObject(i);
        String username = u.getString("username");
        if (username.equals(new_username)) {
            Assert.assertEquals(new_userId, u.getInt("id"));
        } else {
            Assert.assertTrue(username.equals(user_username) || username.equals(admin_username));
        }
    }
    sessions = obj.getJSONArray("sessions");
    Assert.assertEquals(3, sessions.length());
    for (int i = 0; i < 3; i++) {
        s = sessions.getJSONObject(i);
        String username = s.getString("username");
        if (username.equals(new_username)) {
            Assert.assertEquals(new_userId, s.getInt("user_id"));
            Assert.assertTrue(s.getInt("last_activity") >= 0); // might be 0
            Assert.assertTrue(s.getInt("created_at") > 0);
            Assert.assertFalse(s.has("origins")); // admin only
            Assert.assertFalse(s.has("last_played_song"));
        } else {
            Assert.assertTrue(username.equals(user_username) || username.equals(admin_username));
        }
    }

    // try to change password without the old password: 401
    post = new PostMethod(URL + "user/password");
    post.addRequestHeader("sessionId", new_sessionId);
    post.addParameter("old_password", "password");
    post.addParameter("new_password", "password2");
    client.executeMethod(post);
    Assert.assertEquals(401, post.getStatusCode());

    // change password for new user
    post = new PostMethod(URL + "user/password");
    post.addRequestHeader("sessionId", new_sessionId);
    post.addParameter("old_password", new_password);
    new_password = "something else";
    post.addParameter("new_password", new_password);
    client.executeMethod(post);
    Assert.assertEquals(204, post.getStatusCode());

    // logout and relogin with new password
    post = new PostMethod(URL + "logout");
    post.addRequestHeader("sessionId", new_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(204, post.getStatusCode());

    obj = new JSONObject(this.login(new_username, new_password));
    Assert.assertEquals(new_userId, obj.getInt("userId"));
    new_sessionId = obj.getString("sessionId");

    // try to delete an user as user: 401
    post = new PostMethod(URL + "user/remove");
    post.addRequestHeader("sessionId", user_sessionId);
    post.addParameter("user_ids[]", "" + new_userId);
    client.executeMethod(post);
    Assert.assertEquals(401, post.getStatusCode());

    // try to delete no user: 400
    post = new PostMethod(URL + "user/remove");
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(400, post.getStatusCode());

    // try to delete admin with admin: 400
    post = new PostMethod(URL + "user/remove");
    post.addRequestHeader("sessionId", admin_sessionId);
    post.addParameter("user_ids[]", "" + admin_userId);
    client.executeMethod(post);
    Assert.assertEquals(400, post.getStatusCode());

    // delete both regular users
    post = new PostMethod(URL + "user/remove");
    post.addRequestHeader("sessionId", admin_sessionId);
    post.addParameter("user_ids[]", "" + user_userId);
    post.addParameter("user_ids[]", "" + new_userId);
    client.executeMethod(post);
    Assert.assertEquals(204, post.getStatusCode());

    // check that old sessions do not work anymore
    get = new GetMethod(URL + "users");
    get.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(401, get.getStatusCode());

    // check that there is only 1 user
    get = new GetMethod(URL + "users");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    Assert.assertEquals(obj.getJSONArray("users").length(), 1);
    Assert.assertEquals(obj.getJSONArray("sessions").length(), 1);

}

From source file:com.mnxfst.testing.activities.http.TestHTTPRequestActivity.java

@Test
public void testPostInit() throws TSPlanActivityExecutionException {

    HTTPRequestActivity activity = new HTTPRequestActivity();
    try {/*from  w w w.j a v  a  2 s.c om*/
        activity.initialize(null);
        Assert.fail("Config options missing");
    } catch (TSPlanActivityExecutionException e) {
        //
    }

    TSPlanConfigOption cfg = new TSPlanConfigOption();
    try {
        activity.initialize(cfg);
        Assert.fail("Config option 'scheme' missing");
    } catch (TSPlanActivityExecutionException e) {
        //
    }

    cfg.addOption("scheme", "http");
    try {
        activity.initialize(cfg);
        Assert.fail("Config option 'host' missing");
    } catch (TSPlanActivityExecutionException e) {
        //
    }

    cfg.addOption("host", "localhost");
    cfg.addOption("port", "dd");
    try {
        activity.initialize(cfg);
        Assert.fail("Config option 'port' holds an invalid value");
    } catch (TSPlanActivityExecutionException e) {
        //
    }

    cfg.addOption("port", "8080");
    cfg.addOption("maxConnections", "");
    cfg.addOption("responseContent", "test");
    Map<String, String> exportVars = new HashMap<String, String>();
    exportVars.put("responseContent", "exportReponseContent");
    activity.setContextExportVariables(exportVars);
    activity.initialize(cfg);

    cfg.addOption("maxConnections", "dd");
    try {
        activity.initialize(cfg);
        Assert.fail("Config option 'maxConnections' holds an invalid value");
    } catch (TSPlanActivityExecutionException e) {
        //
    }
    cfg.addOption("maxConnections", "300");

    cfg.addOption("proxyPort", "");
    activity.initialize(cfg);

    cfg.addOption("proxyPort", "dd");
    try {
        activity.initialize(cfg);
        Assert.fail("Config option 'proxyPort' holds an invalid value");
    } catch (TSPlanActivityExecutionException e) {
        //
    }

    cfg.addOption("userAgent", "junit-test");
    cfg.addOption("httpProtocolVersion", "111");
    try {
        activity.initialize(cfg);
        Assert.fail("Invalid http protocol version");
    } catch (TSPlanActivityExecutionException e) {
        //
    }

    cfg.addOption("httpProtocolVersion", "1.1");
    cfg.addOption("httpRequestProcessors",
            "org.apache.http.protsocol.RequestContent,org.apache.http.protocol.RequestTargetHost,org.apache.http.protocol.RequestConnControl,org.apache.http.protocol.RequestUserAgent,org.apache.http.protocol.RequestExpectContinue");
    try {
        activity.initialize(cfg);
        Assert.fail("Invalid processor");
    } catch (TSPlanActivityExecutionException e) {
        //
    }

    cfg.addOption("httpRequestProcessors",
            "org.apache.http.protocol.RequestContent,org.apache.http.protocol.RequestTargetHost,org.apache.http.protocol.RequestConnControl,org.apache.http.protocol.RequestUserAgent,org.apache.http.protocol.RequestExpectContinue");

    cfg.addOption("method", "GETT");
    try {
        activity.initialize(cfg);
        Assert.fail("Invalid method");
    } catch (TSPlanActivityExecutionException e) {
        //
    }
    cfg.addOption("method", "POST");

    cfg.addOption("proxyUrl", "proxy.mnxfst.com");
    cfg.addOption("proxyPort", "1234");
    cfg.addOption("proxyUser", "user");
    cfg.addOption("proxyPassword", "test");
    cfg.addOption("request.param.key1", "value1");
    cfg.addOption("request.param.key2", "value2");
    activity.initialize(cfg);

}