Example usage for junit.framework AssertionFailedError AssertionFailedError

List of usage examples for junit.framework AssertionFailedError AssertionFailedError

Introduction

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

Prototype

public AssertionFailedError(String message) 

Source Link

Usage

From source file:com.baidu.qa.service.test.client.SoapReqImpl.java

public static Object requestSoap(String caseAction, File file, Config config, VariableGenerator vargen) {
    String host = config.getHost();
    String ip = null;//from www. ja  v  a  2 s  .c o m
    int port = 0;
    String action = null;
    String method = null;
    String xml = FileUtil.readFileByLines(file);

    boolean isHttps = false;
    try {
        /*
         "http://xxx:8880/yyy"
         host == "http://xxx:8880/sem/"
         casedata.getAction() == "yyy"
        */
        String[] protocolAndUrl = host.split("://");

        if ("https".equals(protocolAndUrl[0])) {
            isHttps = true;
        }
        String withoutProtocol = host.split("//")[1];
        String[] uriAndAction = withoutProtocol.split("/", 2);
        String[] ipAndPort = uriAndAction[0].split(":");
        ip = ipAndPort[0];
        if (ipAndPort.length != 2) {
            port = isHttps ? 443 : 80;
        } else {
            port = Integer.parseInt(ipAndPort[1]);
        }
        int indexOfSlash = caseAction.lastIndexOf('/');
        method = caseAction.substring(indexOfSlash, caseAction.length());
        action = "/" + uriAndAction[1] + caseAction.substring(0, indexOfSlash);

    } catch (Exception e) {
        log.error("wrong format host and action in the config~!");
        log.error(e.getMessage(), e);
    }

    String res = null;

    try {
        res = sendSoap(config.getHost(), ip, port, action, method, xml, isHttps);
    } catch (Exception e) {
        log.error("[invoke soap service error]:");
        log.error(e.getMessage(), e);
        throw new AssertionFailedError("[invoke soap service error]:" + file.getPath());
    }

    log.info("[HTTP request end]" + res);
    // responseoutput
    File resfile = FileUtil.rewriteFile(file.getParentFile().getParent() + Constant.FILENAME_OUTPUT,
            file.getName().substring(0, file.getName().indexOf(".")) + ".response", res);

    // 
    vargen.processProps(resfile, Constant.FILE_TYPE_XML);

    return res;

}

From source file:de.codesourcery.eve.apiclient.cache.FilesystemResponseCacheTest.java

protected void assertCacheDirNotContains(APIQuery query) {

    File file = cache.getFilenameForEntry(query);

    if (file.exists()) {
        throw new AssertionFailedError("Cache dir should NOT contain file " + file.getAbsolutePath());
    }/* w  ww. j a v a 2 s.c om*/

}

From source file:com.meltmedia.cadmium.blackbox.test.CadmiumAssertions.java

/**
 * <p>Asserts that the local directory contents have all been deployed to the remote URL prefix.</p>
 * @param message The message that will be in the error if the local directory hasn't been deployed to the remote URL prefix.
 * @param directory The directory locally that should have been deployed.
 * @param urlPrefix The URL prefix that should have the contents of the directory.
 * @param username The Basic HTTP auth username.
 * @param password The Basic HTTP auth password.
 *//* w w  w.j ava  2  s.c  o m*/
public static void assertContentDeployed(String message, File directory, String urlPrefix, String username,
        String password) {
    if (directory == null || !directory.isDirectory() || urlPrefix == null) {
        throw new AssertionFailedError(message);
    }
    File files[] = getAllDirectoryContents(directory, "META-INF", ".git");
    String basePath = directory.getAbsoluteFile().getAbsolutePath();
    if (urlPrefix.endsWith("/")) {
        urlPrefix = urlPrefix.substring(0, urlPrefix.length() - 2);
    }
    for (File file : files) {
        if (file.isFile()) {
            String httpPath = urlPrefix + "/"
                    + file.getAbsoluteFile().getAbsolutePath().replaceFirst(basePath + "/", "");
            assertResourcesEqual(message, file, httpPath, username, password);
        }
    }
}

From source file:de.codesourcery.eve.apiclient.cache.FilesystemResponseCacheTest.java

protected void assertCacheDirContains(APIQuery query) {

    File file = cache.getFilenameForEntry(query);

    if (!file.exists()) {
        throw new AssertionFailedError("Cache dir should contain file " + file.getAbsolutePath());
    }// w ww .ja  v  a  2  s.c  om

    if (file.length() == 0) {
        throw new AssertionFailedError("Cache dir should contain non-empty file " + file.getAbsolutePath());
    }
}

From source file:com.owncloud.android.lib.test_project.test.GetShareesTest.java

/**
 *  Test get sharees//from  ww w.ja va2  s  .c  o m
 * 
 *  Requires OC server 8.2 or later
 */
public void testGetRemoteShareesOperation() {
    Log.v(LOG_TAG, "testGetRemoteSharees in");

    /// successful cases

    // search for sharees including "a"
    GetRemoteShareesOperation getShareesOperation = new GetRemoteShareesOperation("a", 1, 50);
    RemoteOperationResult result = getShareesOperation.execute(mClient);
    JSONObject resultItem;
    JSONObject value;
    int type;
    int userCount = 0, groupCount = 0;
    assertTrue(result.isSuccess() && result.getData().size() > 0);
    try {
        for (int i = 0; i < result.getData().size(); i++) {
            resultItem = (JSONObject) result.getData().get(i);
            value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE);
            type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE);
            if (type == ShareType.GROUP.getValue()) {
                groupCount++;
            } else {
                userCount++;
            }
        }
        assertTrue(userCount > 0);
        assertTrue(groupCount > 0);
    } catch (JSONException e) {
        AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage());
        afe.setStackTrace(e.getStackTrace());
        throw afe;
    }

    // search for sharees including "ad" - expecting user "admin" & group "admin"
    getShareesOperation = new GetRemoteShareesOperation("ad", 1, 50);
    result = getShareesOperation.execute(mClient);
    assertTrue(result.isSuccess() && result.getData().size() == 2);
    userCount = 0;
    groupCount = 0;
    try {
        for (int i = 0; i < 2; i++) {
            resultItem = (JSONObject) result.getData().get(i);
            value = resultItem.getJSONObject(GetRemoteShareesOperation.NODE_VALUE);
            type = value.getInt(GetRemoteShareesOperation.PROPERTY_SHARE_TYPE);
            if (type == ShareType.GROUP.getValue()) {
                groupCount++;
            } else {
                userCount++;
            }
        }
        assertEquals(userCount, 1);
        assertEquals(groupCount, 1);
    } catch (JSONException e) {
        AssertionFailedError afe = new AssertionFailedError(e.getLocalizedMessage());
        afe.setStackTrace(e.getStackTrace());
        throw afe;
    }

    // search for sharees including "bd" - expecting 0 results
    getShareesOperation = new GetRemoteShareesOperation("bd", 1, 50);
    result = getShareesOperation.execute(mClient);
    assertTrue(result.isSuccess() && result.getData().size() == 0);

    /// failed cases

    // search for sharees including wrong page values
    getShareesOperation = new GetRemoteShareesOperation("a", 0, 50);
    result = getShareesOperation.execute(mClient);
    assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST);

    getShareesOperation = new GetRemoteShareesOperation("a", 1, 0);
    result = getShareesOperation.execute(mClient);
    assertTrue(!result.isSuccess() && result.getHttpCode() == HttpStatus.SC_BAD_REQUEST);
}

From source file:de.codesourcery.eve.skills.util.XMLMapperTest.java

private <X> void assertArrayEquals(X[] expected, X[] actual) {

    boolean result;
    if (expected == null || actual == null) {
        result = expected == actual;/*from  w  w w  . j ava  2 s .  com*/
    } else {
        if (expected.length != actual.length) {
            result = false;
        } else {
            for (int i = 0; i < expected.length; i++) {
                if (!ObjectUtils.equals(expected[i], actual[i])) {
                    throw new AssertionFailedError("expected: " + ObjectUtils.toString(expected) + " , got: "
                            + ObjectUtils.toString(actual));
                }
            }
            return;
        }
    }

    if (!result) {
        throw new AssertionFailedError(
                "expected: " + ObjectUtils.toString(expected) + " , got: " + ObjectUtils.toString(actual));
    }
}

From source file:ir.keloud.android.lib.test_project.test.KeloudClientTest.java

public void testExecuteMethodWithTimeouts() throws HttpException, IOException {
    KeloudClient client = new KeloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
    int connectionTimeout = client.getConnectionTimeout();
    int readTimeout = client.getDataTimeout();

    HeadMethod head = new HeadMethod(client.getWebdavUri() + "/");
    try {/*  w  ww .  j  av  a2 s  . c o  m*/
        client.executeMethod(head, 1, 1000);
        throw new AssertionFailedError("Completed HEAD with impossible read timeout");

    } catch (Exception e) {
        Log.e("KeloudClientTest", "EXCEPTION", e);
        assertTrue("Unexcepted exception " + e.getLocalizedMessage(),
                (e instanceof ConnectTimeoutException) || (e instanceof SocketTimeoutException));

    } finally {
        head.releaseConnection();
    }

    assertEquals("Connection timeout was changed for future requests", connectionTimeout,
            client.getConnectionTimeout());
    assertEquals("Read timeout was changed for future requests", readTimeout, client.getDataTimeout());

    try {
        client.executeMethod(head, 1000, 1);
        throw new AssertionFailedError("Completed HEAD with impossible connection timeout");

    } catch (Exception e) {
        Log.e("KeloudClientTest", "EXCEPTION", e);
        assertTrue("Unexcepted exception " + e.getLocalizedMessage(),
                (e instanceof ConnectTimeoutException) || (e instanceof SocketTimeoutException));

    } finally {
        head.releaseConnection();
    }

    assertEquals("Connection timeout was changed for future requests", connectionTimeout,
            client.getConnectionTimeout());
    assertEquals("Read timeout was changed for future requests", readTimeout, client.getDataTimeout());

}

From source file:com.owncloud.android.lib.test_project.test.OwnCloudClientTest.java

public void testExecuteMethodWithTimeouts() throws HttpException, IOException {
    OwnCloudClient client = new OwnCloudClient(mServerUri, NetworkUtils.getMultiThreadedConnManager());
    int connectionTimeout = client.getConnectionTimeout();
    int readTimeout = client.getDataTimeout();

    HeadMethod head = new HeadMethod(client.getWebdavUri() + "/");
    try {/*from  www  .j  ava 2  s . com*/
        client.executeMethod(head, 1, 1000);
        throw new AssertionFailedError("Completed HEAD with impossible read timeout");

    } catch (Exception e) {
        Log.e("OwnCloudClientTest", "EXCEPTION", e);
        assertTrue("Unexcepted exception " + e.getLocalizedMessage(),
                (e instanceof ConnectTimeoutException) || (e instanceof SocketTimeoutException));

    } finally {
        head.releaseConnection();
    }

    assertEquals("Connection timeout was changed for future requests", connectionTimeout,
            client.getConnectionTimeout());
    assertEquals("Read timeout was changed for future requests", readTimeout, client.getDataTimeout());

    try {
        client.executeMethod(head, 1000, 1);
        throw new AssertionFailedError("Completed HEAD with impossible connection timeout");

    } catch (Exception e) {
        Log.e("OwnCloudClientTest", "EXCEPTION", e);
        assertTrue("Unexcepted exception " + e.getLocalizedMessage(),
                (e instanceof ConnectTimeoutException) || (e instanceof SocketTimeoutException));

    } finally {
        head.releaseConnection();
    }

    assertEquals("Connection timeout was changed for future requests", connectionTimeout,
            client.getConnectionTimeout());
    assertEquals("Read timeout was changed for future requests", readTimeout, client.getDataTimeout());

}

From source file:com.splout.db.dnode.TestDNode.java

@Test
public void testPoolCacheEviction() throws Throwable {
    TestUtils.createFooDatabase(DB_1 + ".1", 1, "foo1");
    TestUtils.createFooDatabase(DB_2 + ".1", 2, "foo2");

    SploutConfiguration testConfig = SploutConfiguration.getTestConfig();
    // Set cache eviction to something quite low
    testConfig.setProperty(DNodeProperties.EH_CACHE_SECONDS, 1);
    ///*from w w w.  j a  v  a2s  .  c o m*/
    DNodeHandler dHandler = new DNodeHandler();
    DNode dnode = TestUtils.getTestDNode(testConfig, dHandler, "dnode-" + this.getClass().getName() + "-2");
    //
    DNodeService.Client client = DNodeClient.get("localhost", testConfig.getInt(DNodeProperties.PORT));

    try {
        DeployAction deploy = new DeployAction();
        deploy.setTablespace("tablespace1");
        deploy.setDataURI(new File(DB_1 + ".1", "foo.db").toURI().toString());
        deploy.setPartition(0);
        deploy.setVersion(1l);
        deploy.setMetadata(new PartitionMetadata());
        client.deploy(Arrays.asList(new DeployAction[] { deploy }), 1l);

        Thread.sleep(1000);
        waitForDeployToFinish(client);

        Thread.sleep(200);

        Assert.assertEquals(false, dHandler.lastDeployTimedout.get());
        Assert.assertEquals(false, dHandler.deployInProgress.get() > 0);

        client.sqlQuery("tablespace1", 1l, 0, "SELECT 1;");
        Assert.assertEquals(dHandler.dbCache.getKeysWithExpiryCheck().size(), 1);

        deploy = new DeployAction();
        deploy.setTablespace("tablespace1");
        deploy.setDataURI(new File(DB_2 + ".1", "foo.db").toURI().toString());
        deploy.setPartition(0);
        deploy.setVersion(2l);
        deploy.setMetadata(new PartitionMetadata());
        client.deploy(Arrays.asList(new DeployAction[] { deploy }), 2l);

        Thread.sleep(1000);
        waitForDeployToFinish(client);

        Assert.assertEquals(false, dHandler.lastDeployTimedout.get());
        Assert.assertEquals(false, dHandler.deployInProgress.get() > 0);

        client.sqlQuery("tablespace1", 2l, 0, "SELECT 1;");
        client.sqlQuery("tablespace1", 1l, 0, "SELECT 1;");
        Assert.assertEquals(dHandler.dbCache.getKeysWithExpiryCheck().size(), 2);

        long weAreWaitingSoFar = 0;
        while (dHandler.dbCache.getKeysWithExpiryCheck().size() > 1) {
            Thread.sleep(10);
            weAreWaitingSoFar += 10;
            if (weAreWaitingSoFar > 2000) {
                throw new AssertionFailedError(
                        "Waiting more than twice the specified eviction time for pool cache entries.");
            }
        }
    } finally {
        DNodeClient.close(client);
        //
        dnode.stop();
    }
}

From source file:my.FileBasedTestCase.java

protected void checkWrite(OutputStream output) throws Exception {
    try {/* w  w w.  java 2 s  .  c  o  m*/
        new java.io.PrintStream(output).write(0);
    } catch (Throwable t) {
        throw new AssertionFailedError(
                "The copy() method closed the stream " + "when it shouldn't have. " + t.getMessage());
    }
}