Example usage for junit.framework Assert assertEquals

List of usage examples for junit.framework Assert assertEquals

Introduction

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

Prototype

static public void assertEquals(int expected, int actual) 

Source Link

Document

Asserts that two ints are equal.

Usage

From source file:com.brienwheeler.svc.monitor.intervene.impl.LoggingInterventionListenerTest.java

@Test
public void testProvidedLogEnabled() {
    LoggingInterventionListener listener = new LoggingInterventionListener();
    TestLog testLog = new TestLog();
    listener.recordInterventionRequest(this, testLog, "intervention required");
    Assert.assertEquals(1, testLog.getWarnCount());
}

From source file:com.brienwheeler.lib.test.stepper.SteppableThreadTest.java

@Test
public void testSteppedThrows() {
    SteppableThread stepper = new SteppableThrows();
    stepper.start();//from  ww  w. j  av a2s  .  com
    stepper.releaseAndJoin();
    Assert.assertEquals(RuntimeException.class, stepper.getTestThrowable().getClass());
}

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

public void test() throws Exception {
    HttpClient client = new HttpClient();

    // /indexer/status as user: 401
    GetMethod get = new GetMethod(URL + "indexer/status");
    get.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(get);/* w w  w  .j a  v  a  2 s.c  o  m*/
    Assert.assertEquals(401, get.getStatusCode());

    // /indexer/status as admin: 200
    get = new GetMethod(URL + "indexer/status");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(200, get.getStatusCode());
    JSONObject obj = new JSONObject(get.getResponseBodyAsString());
    // won't try to check the actual content of this object,
    // since I can't predict easily and accurately if 
    // the Indexer will be in Running or Sleeping state at a given time.
    assertTrue(obj.has("running"));
    assertTrue(obj.has("percentDone"));
    assertTrue(obj.has("secondsLeft"));
    assertTrue(obj.has("songsDone"));
    assertTrue(obj.has("songsTodo"));

    // /indexer/rescan as user: 401
    PostMethod post = new PostMethod(URL + "indexer/rescan");
    post.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(401, post.getStatusCode());

    // /indexer/rescan as amdin
    post = new PostMethod(URL + "indexer/rescan");
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(204, post.getStatusCode());

    // /folders as user: 401
    get = new GetMethod(URL + "folders");
    get.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(401, get.getStatusCode());

    // /folders: should be empty
    get = new GetMethod(URL + "folders");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(0, obj.getJSONArray("folders").length());

    // /folders/listing as user: 401
    get = new GetMethod(URL + "folders/listing");
    get.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(401, get.getStatusCode());

    // /folders/listing on some file that does not exist: 404
    get = new GetMethod(URL + "folders/listing?directory=/does/not/exist");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(404, get.getStatusCode());

    File exp_home = new File(System.getProperty("user.home"));

    // /folders/listing with no arg: homedir
    get = new GetMethod(URL + "folders/listing");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(File.separator, obj.getString("separator"));
    File dir = new File(obj.getString("directory"));
    assertEquals(exp_home.getAbsolutePath(), dir.getAbsolutePath());
    assertEquals(exp_home.getParentFile().getAbsolutePath(), dir.getParentFile().getAbsolutePath());
    assertTrue(obj.getJSONArray("listing").length() > 0);

    // /folders/listing with arg '$ROOT'
    get = new GetMethod(URL + "folders/listing?directory=$ROOT");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    Assert.assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(File.separator, obj.getString("separator"));
    File[] dirs = File.listRoots();
    assertEquals("", obj.getString("directory"));
    assertEquals("$ROOT", obj.getString("parent"));
    JSONArray arr = obj.getJSONArray("listing");
    HashSet<String> hs = new HashSet<String>(arr.length());
    for (int i = 0; i < arr.length(); i++) {
        hs.add(new File(arr.getString(i)).getAbsolutePath());
    }
    for (File d : dirs) {
        // on windows, listRoots returns a bunch of drive names that don't exist
        if (d.exists()) {
            assertTrue(hs.remove(d.getAbsolutePath()));
        }
    }
    assertTrue(hs.isEmpty());

    // lists test resources folder
    File f = new File("src/test/resources/data2");
    get = new GetMethod(URL + "folders/listing?directory=" + URIUtil.encodeQuery(f.getAbsolutePath()));
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(File.separator, obj.getString("separator"));
    dir = new File(obj.getString("directory"));
    assertEquals(f.getAbsolutePath(), dir.getAbsolutePath());
    assertEquals(f.getParentFile().getAbsolutePath(), dir.getParentFile().getAbsolutePath());
    dirs = dir.listFiles();
    arr = obj.getJSONArray("listing");
    assertEquals(2, arr.length());
    assertEquals(new File("src/test/resources/data2/sub1").getAbsolutePath(), arr.get(0));
    assertEquals(new File("src/test/resources/data2/sub2").getAbsolutePath(), arr.get(1));

    // /folders/add as user: 401
    post = new PostMethod(URL + "folders/add");
    post.addParameter("directory", "/");
    post.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(401, post.getStatusCode());

    // /folders/add : directory does not exist: 404
    post = new PostMethod(URL + "folders/add");
    post.addParameter("directory", "/does/not/exist");
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(404, post.getStatusCode());

    // /folders/add : not a directory: 400
    post = new PostMethod(URL + "folders/add");
    post.addParameter("directory", new File("src/test/resources/data/1.mp3").getAbsolutePath());
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(400, post.getStatusCode());

    // /folders/add "/src/test/resources/data"
    f = new File("src/test/resources/data");
    RuntimeStats rt = new RuntimeStats();
    rt.songCount.set(15);
    rt.albumCount.set(5);
    rt.artistCount.set(2);
    rt.playlistCount.set(0);
    rt.userCount.set(2);
    rt.playtime.set(15);
    rt.downloaded.set(0);
    this.addMusicFolder(f.getAbsolutePath(), rt);

    // check /folders
    get = new GetMethod(URL + "folders");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(f.getAbsolutePath(), obj.getJSONArray("folders").getString(0));

    // /folders/add "/src/test/resources/data2/sub1"
    f = new File("src/test/resources/data2/sub1");
    rt.songCount.addAndGet(3);
    rt.albumCount.addAndGet(1);
    rt.artistCount.addAndGet(1);
    rt.playtime.addAndGet(3);
    this.addMusicFolder(f.getAbsolutePath(), rt);

    // /folders/add "/src/test/resources/data2/"
    f = new File("src/test/resources/data2/");
    rt.songCount.addAndGet(6);
    rt.playtime.addAndGet(6);
    this.addMusicFolder(f.getAbsolutePath(), rt);

    // check /folders
    get = new GetMethod(URL + "folders");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    arr = obj.getJSONArray("folders");
    assertEquals(3, arr.length());
    for (int i = 0; i < 3; i++) {
        String s = new File(arr.getString(i)).getAbsolutePath();
        String s1 = new File("src/test/resources/data").getAbsolutePath();
        String s2 = new File("src/test/resources/data2/sub1").getAbsolutePath();
        String s3 = new File("src/test/resources/data2").getAbsolutePath();
        assertTrue(s.equals(s1) || s.equals(s2) || s.equals(s3));
    }

    // /folders/remove as user: 401
    post = new PostMethod(URL + "folders/remove");
    post.addParameter("directory[]", "/");
    post.addRequestHeader("sessionId", user_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(401, post.getStatusCode());

    // /folders/remove unknown dir: 400
    post = new PostMethod(URL + "folders/remove");
    post.addParameter("directory[]", "/does/not/exist");
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    Assert.assertEquals(400, post.getStatusCode());

    // /folders/remove "/src/test/resources/data","src/test/resources/data2"
    post = new PostMethod(URL + "folders/remove");
    f = new File("src/test/resources/data");
    post.addParameter("directory[]", f.getAbsolutePath());
    f = new File("src/test/resources/data2");
    post.addParameter("directory[]", f.getAbsolutePath());
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    assertEquals(204, post.getStatusCode());

    rt.songCount.set(3);
    rt.albumCount.set(1);
    rt.artistCount.set(1);
    rt.userCount.set(2);
    rt.playtime.set(3);
    rt.downloaded.set(0);
    this.checkStats(rt);

    // /folders/remove "/src/test/resources/data/sub1"
    post = new PostMethod(URL + "folders/remove");
    f = new File("src/test/resources/data2/sub1");
    post.addParameter("directory[]", f.getAbsolutePath());
    post.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(post);
    assertEquals(204, post.getStatusCode());

    rt.songCount.set(0);
    rt.albumCount.set(0);
    rt.artistCount.set(0);
    rt.userCount.set(2);
    rt.playtime.set(0);
    rt.downloaded.set(0);
    this.checkStats(rt);

    // /folders: should be empty
    get = new GetMethod(URL + "folders");
    get.addRequestHeader("sessionId", admin_sessionId);
    client.executeMethod(get);
    assertEquals(200, get.getStatusCode());
    obj = new JSONObject(get.getResponseBodyAsString());
    assertEquals(0, obj.getJSONArray("folders").length());

}

From source file:org.imsglobal.lti.lti2.ProductInstanceTest.java

@Test
public void deserializeProfile() throws JsonProcessingException, IOException {
    ProductInstance ppi = new ProductInstance(new TestLtiConsumerProfile());
    ppi.addAdditionalProperty("test", "yolo");
    ppi.addAdditionalProperty("another_test", "swag");

    String json = getJson(ppi, false);

    ProductInstance pi = toObject(json, ProductInstance.class);

    Assert.assertEquals("1", pi.getGuid());
    Assert.assertEquals("yolo", pi.getAdditionalProperties().get("test"));
    Assert.assertEquals("swag", pi.getAdditionalProperties().get("another_test"));
}

From source file:com.cloudmine.api.rest.AndroidCMWebServiceIntegrationTest.java

@Test
public void testSentHeaders() {
    Robolectric.getFakeHttpLayer().interceptHttpRequests(true);
    try {//from  w  ww.  j a  v  a 2 s  .co m
        String firstResponseId = "abc123";
        BasicHeader responseHeader = new BasicHeader(HeaderFactory.REQUEST_ID_KEY, firstResponseId);
        String responseJson = "{ \"success\": { \"someKey\":\"deleted\" } }";
        Robolectric.addPendingHttpResponse(200, responseJson, responseHeader);
        service.asyncDelete("someKey", hasSuccess);
        AsyncTestResultsCoordinator.waitThenAssertTestResults();

        HttpRequest sentRequest = Robolectric.getSentHttpRequest(0);
        Header idHeader = sentRequest.getFirstHeader(HeaderFactory.DEVICE_HEADER_KEY);
        assertNotNull(idHeader);
        Assert.assertEquals(DeviceIdentifier.getUniqueId(), idHeader.getValue());

        Header agentHeader = sentRequest.getFirstHeader(HeaderFactory.AGENT_HEADER_KEY);
        assertNotNull(agentHeader);
        Assert.assertEquals(AndroidHeaderFactory.CLOUD_MINE_AGENT, agentHeader.getValue());

        responseHeader = new BasicHeader(HeaderFactory.REQUEST_ID_KEY, "def456");
        Robolectric.addPendingHttpResponse(200, responseJson, responseHeader);
        service.asyncDelete("someKey", hasSuccess);
        AsyncTestResultsCoordinator.waitThenAssertTestResults();

        HttpRequest secondRequest = Robolectric.getSentHttpRequest(1);
        assertNotNull(secondRequest);

        idHeader = secondRequest.getFirstHeader(HeaderFactory.DEVICE_HEADER_KEY);
        assertNotNull(idHeader);
        String value = idHeader.getValue();
        assertTrue(value.contains(firstResponseId));

    } finally {
        Robolectric.getFakeHttpLayer().interceptHttpRequests(false);
    }
}

From source file:org.openmrs.module.webservices.rest.web.v1_0.controller.PersonAttributeControllerTest.java

@Test
public void shouldGetAPersonAttribute() throws Exception {
    Object result = controller.retrieve(personUuid, attributeUuid, request);
    Assert.assertNotNull(result);/*from w  ww .j  av a 2  s . c  om*/
    Assert.assertEquals(attributeUuid, PropertyUtils.getProperty(result, "uuid"));
    Assert.assertEquals("", PropertyUtils.getProperty(result, "value"));
    Assert.assertNull(PropertyUtils.getProperty(result, "auditInfo"));
}

From source file:ch.medshare.elexis_directories.TestElexisDirectories.java

private List<KontaktEntry> compare_file_to_kontacts(File file, List<KontaktEntry> expectedKontakte)
        throws IOException {
    String content = FileUtils.readFileToString(file);
    DirectoriesContentParser parser = new DirectoriesContentParser(content);
    List<KontaktEntry> kontakte = parser.extractKontakte();
    if (expectedKontakte != null) {
        for (int j = 0; j < expectedKontakte.size(); j++) {
            KontaktEntry soll = expectedKontakte.get(j);
            KontaktEntry ist = kontakte.get(j);
            // we must compare the different fields
            Assert.assertEquals(soll.getName(), ist.getName());
            Assert.assertEquals(soll.getVorname(), ist.getVorname());
            Assert.assertEquals(soll.getZusatz(), ist.getZusatz());
            Assert.assertEquals(soll.getEmail(), ist.getEmail());
            Assert.assertEquals(soll.getAdresse(), ist.getAdresse());
            Assert.assertEquals(soll.getFax(), ist.getFax());
            Assert.assertEquals(soll.getOrt(), ist.getOrt());
            Assert.assertEquals(soll.getPlz(), ist.getPlz());
            Assert.assertEquals(soll.getTelefon(), ist.getTelefon());
        }//from  w w  w.j  a va 2 s . c  o m
    }
    return kontakte;
}

From source file:org.ocpsoft.rewrite.servlet.container.ContainerSecurityTest.java

@Test
public void testContainerSecurityFunctionsWithRewriteJoin() throws Exception {
    HttpAction<HttpGet> action = get("/user/home");
    Assert.assertEquals(200, action.getResponse().getStatusLine().getStatusCode());
    Assert.assertTrue(action.getResponseContent().contains("LOGIN PAGE"));
}

From source file:com.swcguild.contactlistmvc.dao.ContactListDaoTest.java

@Test
public void addUpdateContact() {
    Contact nc = new Contact();
    nc.setFirstName("Jimmy");
    nc.setLastName("Smith");
    nc.setCompany("Sun");
    nc.setEmail("jimmy@smith.com");
    nc.setPhone("1112223333");

    dao.addContact(nc);//w w w.ja v  a  2 s  .com

    nc.setPhone("9999999999");
    dao.updateContact(nc);

    Contact fromDb = dao.getContactById(nc.getContactId());

    Assert.assertEquals(fromDb, nc);

}

From source file:crawlercommons.fetcher.file.SimpleFileFetcherTest.java

@Test
public void testEmptyFile() throws Exception {
    URI uri = new File("src/test/resources/empty-file").toURI();
    String url = uri.toURL().toExternalForm();

    SimpleFileFetcher fetcher = new SimpleFileFetcher();
    FetchedResult result = fetcher.get(url);
    Assert.assertEquals(HttpStatus.SC_OK, result.getStatusCode());
    Assert.assertEquals(0, result.getContentLength());
    Assert.assertEquals(0, result.getResponseRate());
}