Example usage for junit.framework Assert assertTrue

List of usage examples for junit.framework Assert assertTrue

Introduction

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

Prototype

static public void assertTrue(boolean condition) 

Source Link

Document

Asserts that a condition is true.

Usage

From source file:de.itsvs.cwtrpc.controller.AutowiredRemoteServiceGroupConfigTest.java

@Test
public void testAfterPropertiesSet2() {
    final StaticApplicationContext appContext;
    final AutowiredRemoteServiceGroupConfig config;

    appContext = new StaticApplicationContext();
    appContext.registerSingleton("testService1", TestService1Impl.class);

    config = new AutowiredRemoteServiceGroupConfig();
    config.setBasePackages(Arrays.asList(new String[] { "de.itsvs.cwtrpc.controller.config." }));
    config.setApplicationContext(appContext);
    config.afterPropertiesSet();/*w  w  w.  j av  a  2  s.  c o m*/

    Assert.assertTrue(config.getChildGroupConfigs().isEmpty());
    Assert.assertEquals(1, config.getServiceConfigs().size());
}

From source file:edu.cuny.cat.market.FourHeapTest.java

public void testRandom() {
    System.out.println("\n>>>>>>>>>\t " + "testRandom() \n");

    int matches = 0;

    try {//from w  ww .ja v a2s  . co  m

        Shout testRemoveShout = null, testRemoveShout2 = null;

        for (int round = 0; round < 700; round++) {

            if (testRemoveShout != null) {
                shoutEngine.removeShout(testRemoveShout);
                shoutEngine.removeShout(testRemoveShout2);
            }

            for (int shout = 0; shout < 200; shout++) {
                shoutEngine.newShout(randomShout());
            }

            shoutEngine.newShout(testRemoveShout = randomShout());
            testRemoveShout2 = (Shout) testRemoveShout.clone();
            testRemoveShout2 = new Shout(testRemoveShout.getQuantity(), testRemoveShout.getPrice(),
                    !testRemoveShout.isBid());
            shoutEngine.newShout(testRemoveShout2);

            if ((round & 0x01) > 0) {
                continue;
            }

            final List<Shout> matched = shoutEngine.getMatchedShouts();
            final Iterator<Shout> i = matched.iterator();
            while (i.hasNext()) {
                matches++;
                final Shout bid = i.next();
                final Shout ask = i.next();
                Assert.assertTrue(bid.isBid());
                Assert.assertTrue(ask.isAsk());
                Assert.assertTrue(bid.getPrice() >= ask.getPrice());
                // System.out.print(bid + "/" + ask + " ");
            }
            // System.out.println("");
        }

    } catch (final Exception e) {
        shoutEngine.printState();
        e.printStackTrace();
        Assert.fail();
    }

    System.out.println("Matches = " + matches);

}

From source file:com.atlassian.jira.rest.client.TestUtil.java

public static void assertErrorCode(int errorCode, String message, Runnable runnable) {
    try {//www  . ja  v a2  s.co  m
        runnable.run();
        Assert.fail(RestClientException.class + " exception expected");
    } catch (com.atlassian.jira.rest.client.api.RestClientException e) {
        Assert.assertTrue(e.getStatusCode().isPresent());
        Assert.assertEquals(errorCode, e.getStatusCode().get().intValue());
        if (!StringUtils.isEmpty(message)) {
            // We expect a single error message. Either error or error message.
            Assert.assertEquals(1, e.getErrorCollections().size());
            if (Iterators.getOnlyElement(e.getErrorCollections().iterator()).getErrorMessages().size() > 0) {
                Assert.assertEquals(getOnlyElement(
                        getOnlyElement(e.getErrorCollections().iterator()).getErrorMessages().iterator()),
                        message);
            } else if (Iterators.getOnlyElement(e.getErrorCollections().iterator()).getErrors().size() > 0) {
                Assert.assertEquals(getOnlyElement(
                        getOnlyElement(e.getErrorCollections().iterator()).getErrors().values().iterator()),
                        message);
            } else {
                Assert.fail("Expected an error message.");
            }
        }
    }
}

From source file:com.hybris.instore.widgets.listtracker.ListTrackerControllerTest.java

@Test
public void testSetList() {
    final List<Integer> testList = initTestList();
    controller.setList(testList);//w  ww. j  a va 2 s .  c om
    final List<Integer> tempList = controller.getValue(ListTrackerController.MODEL_LIST, List.class);
    Assert.assertTrue(testList.equals(tempList));
}

From source file:org.opencastproject.remotetest.server.WorkingFileRepoRestEndpointTest.java

@Test
public void testPutAndGetFile() throws Exception {
    // Store a file in the repository
    String mediapackageId = "123";
    String elementId = "456";
    byte[] bytesFromPost = IOUtils
            .toByteArray(getClass().getClassLoader().getResourceAsStream("opencast_header.gif"));
    InputStream in = getClass().getClassLoader().getResourceAsStream("opencast_header.gif");
    String fileName = "our_logo.gif"; // Used to simulate a file upload
    MultipartEntity postEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
    postEntity.addPart("file", new InputStreamBody(in, fileName));
    HttpPost post = new HttpPost(BASE_URL + "/files/mediapackage/" + mediapackageId + "/" + elementId);
    post.setEntity(postEntity);//from w ww .  ja v  a 2  s . c  o  m
    HttpResponse response = client.execute(post);
    HttpEntity responseEntity = response.getEntity();
    String stringResponse = EntityUtils.toString(responseEntity);
    String expectedResponse = BASE_URL + "/files/mediapackage/" + mediapackageId + "/" + elementId + "/"
            + fileName;
    Assert.assertEquals(expectedResponse, stringResponse);

    // Get the file back from the repository
    HttpGet get = new HttpGet(BASE_URL + "/files/mediapackage/" + mediapackageId + "/" + elementId);
    HttpResponse getResponse = client.execute(get);
    byte[] bytesFromGet = IOUtils.toByteArray(getResponse.getEntity().getContent());

    // Ensure that the bytes that we posted are the same we received
    Assert.assertTrue(Arrays.equals(bytesFromGet, bytesFromPost));
}

From source file:eu.trentorise.smartcampus.ac.provider.repository.persistence.AcDaoPersistenceImplTest.java

@Test
public void searchUserBySocialId() {
    Assert.assertTrue(dao.readUserBySocialId((long) 1001) != null);
    Assert.assertTrue(dao.readUserBySocialId((long) 1) == null);
}

From source file:cn.javass.spring.chapter4.ResourcePatternTest.java

@Test
public void testVfsPrefix() throws IOException {
    //1./*from w  ww .ja va 2s  .  co m*/
    VirtualFile home = VFS.getChild("/home");
    //2.?
    VFS.mount(home, new RealFileSystem(new File("d:")));
    //3.??
    VirtualFile testFile = home.getChild("test.txt");

    ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
    Resource[] resources = resolver.getResources("/home/test.txt");
    Assert.assertTrue(resources.length > 0);
    System.out.println(resources[0].getClass());

}

From source file:com.couchbase.lite.DatabaseAttachmentTest.java

/**
 * in DatabaseAttachment_Tests.m//w  ww  . ja  va2  s.com
 * - (void) test10_Attachments
 */
@SuppressWarnings("unchecked")
public void testAttachments() throws Exception {
    BlobStore attachments = database.getAttachmentStore();
    Assert.assertEquals(0, attachments.count());
    Assert.assertEquals(new HashSet<Object>(), attachments.allKeys());

    // Add a revision and an attachment to it:
    Status status = new Status(Status.OK);
    byte[] attach1 = "This is the body of attach1".getBytes();
    Map<String, Object> props = new HashMap<String, Object>();
    props.put("foo", 1);
    props.put("bar", false);
    props.put("_attachments", getAttachmentsDict(attach1, "attach", "text/plain", false));
    RevisionInternal rev1 = database.putRevision(new RevisionInternal(props), null, false, status);
    Assert.assertEquals(Status.CREATED, status.getCode());

    AttachmentInternal att = database.getAttachment(rev1, "attach");
    Assert.assertNotNull(att);
    Log.i(TAG, new String(att.getContent()));
    Assert.assertTrue(Arrays.equals(attach1, att.getContent()));
    Assert.assertEquals("text/plain", att.getContentType());
    Assert.assertEquals(AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, att.getEncoding());

    // Check the attachment dict:
    Map<String, Object> itemDict = new HashMap<String, Object>();
    itemDict.put("content_type", "text/plain");
    itemDict.put("digest", "sha1-gOHUOBmIMoDCrMuGyaLWzf1hQTE=");
    itemDict.put("length", 27);
    itemDict.put("stub", true);
    itemDict.put("revpos", 1);
    Map<String, Object> attachmentDict = new HashMap<String, Object>();
    attachmentDict.put("attach", itemDict);
    RevisionInternal gotRev1 = database.getDocument(rev1.getDocID(), rev1.getRevID(), true);
    Map<String, Object> gotAttachmentDict = (Map<String, Object>) gotRev1.getProperties().get("_attachments");
    Assert.assertEquals(attachmentDict, gotAttachmentDict);

    // Check the attachment dict, with attachments included:
    itemDict.remove("stub");
    itemDict.put("data", Base64.encodeBytes(attach1));
    gotRev1 = database.getDocument(rev1.getDocID(), rev1.getRevID(), true);
    RevisionInternal expandedRev = gotRev1.copy();
    Assert.assertTrue(database.expandAttachments(expandedRev, 0, false, true, status));
    Assert.assertEquals(attachmentDict, expandedRev.getAttachments());

    // Add a second revision that doesn't update the attachment:
    props = new HashMap<String, Object>();
    props.put("_id", rev1.getDocID());
    props.put("foo", 2);
    props.put("bazz", false);
    props.put("_attachments", getAttachmentsStub("attach"));
    RevisionInternal rev2 = database.putRevision(new RevisionInternal(props), rev1.getRevID(), false, status);
    Assert.assertEquals(Status.CREATED, status.getCode());

    // Add a third revision of the same document:
    byte[] attach2 = "<html>And this is attach2</html>".getBytes();
    props = new HashMap<String, Object>();
    props.put("_id", rev2.getDocID());
    props.put("foo", 2);
    props.put("bazz", false);
    props.put("_attachments", getAttachmentsDict(attach2, "attach", "text/html", false));
    RevisionInternal rev3 = database.putRevision(new RevisionInternal(props), rev2.getRevID(), false, status);
    Assert.assertEquals(Status.CREATED, status.getCode());

    // Check the 2nd revision's attachment:
    att = database.getAttachment(rev2, "attach");
    Assert.assertNotNull(att);
    Assert.assertEquals("text/plain", att.getContentType());
    Assert.assertEquals(AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, att.getEncoding());
    Assert.assertTrue(Arrays.equals(attach1, att.getContent()));

    expandedRev = rev2.copy();
    Assert.assertTrue(database.expandAttachments(expandedRev, 2, false, true, status));
    attachmentDict = new HashMap<String, Object>();
    itemDict = new HashMap<String, Object>();
    itemDict.put("stub", true);
    itemDict.put("revpos", 1);
    attachmentDict.put("attach", itemDict);
    Assert.assertEquals(attachmentDict, expandedRev.getAttachments());

    // Check the 3rd revision's attachment:
    att = database.getAttachment(rev3, "attach");
    Assert.assertNotNull(att);
    Assert.assertEquals("text/html", att.getContentType());
    Assert.assertEquals(AttachmentInternal.AttachmentEncoding.AttachmentEncodingNone, att.getEncoding());
    Assert.assertTrue(Arrays.equals(attach2, att.getContent()));

    expandedRev = rev3.copy();
    Assert.assertTrue(database.expandAttachments(expandedRev, 2, false, true, status));
    attachmentDict = new HashMap<String, Object>();
    itemDict = new HashMap<String, Object>();
    itemDict.put("content_type", "text/html");
    itemDict.put("data", "PGh0bWw+QW5kIHRoaXMgaXMgYXR0YWNoMjwvaHRtbD4=");
    itemDict.put("digest", "sha1-s14XRTXlwvzYfjo1t1u0rjB+ZUA=");
    itemDict.put("length", 32);
    itemDict.put("revpos", 3);
    attachmentDict.put("attach", itemDict);
    Map<String, Object> data = expandedRev.getAttachments();
    Assert.assertEquals(attachmentDict, expandedRev.getAttachments());

    // Examine the attachment store:
    Assert.assertEquals(2, attachments.count());
    Set<BlobKey> expected = new HashSet<BlobKey>();
    expected.add(BlobStore.keyForBlob(attach1));
    expected.add(BlobStore.keyForBlob(attach2));

    Assert.assertEquals(expected, attachments.allKeys());

    database.compact(); // This clears the body of the first revision
    Assert.assertEquals(1, attachments.count());

    Set<BlobKey> expected2 = new HashSet<BlobKey>();
    expected2.add(BlobStore.keyForBlob(attach2));
    Assert.assertEquals(expected2, attachments.allKeys());
}

From source file:$.CrmTest.java

/**
     * HTTP GET http://localhost:8181/cxf/crm/customerservice/customers/123
     * returns the XML document representing customer 123
     * <p/>/*w w w . j a  v a 2  s  .c  o m*/
     * On the server side, it matches the CustomerService's getCustomer() method
     *
     * @throws Exception
     */
    @Test
    public void getCustomerTest() throws Exception {
        LOG.info("Sent HTTP GET request to query customer info");
        url = new URL(CUSTOMER_TEST_URL);
        InputStream in = null;
        try {
            in = url.openStream();
        } catch (IOException e) {
            LOG.error("Error connecting to {}", CUSTOMER_TEST_URL);
            LOG.error(
                    "You should build the 'cxf-cdi' quick start and deploy it to a local Fabric8 before running this test");
            LOG.error("Please read the README.md file in 'cxf-cdi' quick start root");
            Assert.fail("Connection error");
        }
        String res = getStringFromInputStream(in);
        LOG.info(res);
        Assert.assertTrue(res.contains("123"));
    }

From source file:de.itsvs.cwtrpc.controller.config.AutowiredRemoteServiceGroupConfigBeanDefinitionParserTest.java

@Test
public void test3() {
    AutowiredRemoteServiceGroupConfig config;

    config = appContext.getBean("autowiredServiceGroup103", AutowiredRemoteServiceGroupConfig.class);
    Assert.assertTrue(config.getRpcTokenProtectionEnabled());
}