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:com.nokia.dempsy.router.TestRouterClusterManagement.java

@Test
public void testGetRouterNotFound() {
    Set<ClusterRouter> router = routerFactory.getRouter(java.lang.String.class);
    Assert.assertNull(router);/*  ww w .j a v  a  2 s  .c o  m*/
    Assert.assertTrue(routerFactory.missingMsgTypes.containsKey(java.lang.String.class));
}

From source file:io.cloudslang.lang.runtime.steps.ExecutableStepsTest.java

@Test
public void testStartWithInput() throws Exception {
    List<Input> inputs = Collections.singletonList(new Input.InputBuilder("input1", "input1").build());
    RunEnvironment runEnv = new RunEnvironment();

    Map<String, Serializable> resultMap = new HashMap<>();
    resultMap.put("input1", 5);

    when(inputsBinding.bindInputs(eq(inputs), anyMap(), anySet())).thenReturn(resultMap);
    executableSteps.startExecutable(inputs, runEnv, new HashMap<String, Serializable>(),
            new ExecutionRuntimeServices(), "", 2L);

    Map<String, Serializable> opVars = runEnv.getStack().popContext().getImmutableViewOfVariables();
    Assert.assertTrue(opVars.containsKey("input1"));
    Assert.assertEquals(5, opVars.get("input1"));

    Map<String, Serializable> callArg = runEnv.removeCallArguments();
    Assert.assertEquals(1, callArg.size());
    Assert.assertTrue(callArg.containsKey("input1"));
    Assert.assertEquals(5, callArg.get("input1"));
}

From source file:io.fabric8.quickstarts.cxfcdi.CrmTest.java

/**
 * HTTP GET http://localhost:8181/cxf/crm/customerservice/customers/123
 * returns the XML document representing customer 123
 * <p/>//from  w w w  .  ja  va 2s  .  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:org.ocpsoft.redoculous.tests.git.InitializeRepositoryTest.java

@Test
public void testInitializeRepositoryAndServeAsciidoc() throws Exception {
    WebTest test = new WebTest(baseUrl);
    String repositoryURL = "file://" + repository.getAbsolutePath();
    HttpAction<HttpPost> action = test.post("/api/v1/manage?repo=" + repositoryURL);
    Assert.assertEquals(201, action.getResponse().getStatusLine().getStatusCode());
    String location = URLDecoder.decode(action.getResponseHeaderValue("location"), "UTF8");
    Assert.assertEquals(test.getBaseURL() + test.getContextPath() + "/api/v1/serve?repo=" + repositoryURL,
            location);//  w w w.  j a v  a2 s  .  c  om

    HttpAction<HttpGet> document = test
            .get("/api/v1/serve?repo=" + repositoryURL + "&ref=master&path=document");
    HttpAction<HttpGet> documentFull = test
            .get("/api/v1/serve?repo=" + repositoryURL + "&ref=master&path=document");

    Assert.assertTrue(document.getResponseContent().startsWith("<h1"));
    Assert.assertTrue(documentFull.getResponseContent().startsWith("<h1"));
}

From source file:im.tym.wraop.both.SpringAOPWrapperFactorySpiTest.java

@Test
public void testAdvisor() {
    Assert.assertTrue(factory.addAspect(new RegexpMethodPointcutAdvisor(".*", new TrimTransformerAdvice())));
    Transformer<Object, String> transformer = factory.wrap(new ToStringTransformer(),
            this.getClass().getClassLoader());
    Assert.assertEquals("test", transformer.transform(" test "));
}

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);/*  w w w.  ja  v  a2 s.c om*/
    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:es.tekniker.framework.ktek.questionnaire.mng.db.test.TestQuestionnaireManagerDB.java

public void testGetQuestion4QuestionnaireItem() {
    log.info("*************************************************************");
    log.info("testGetQuestion4QuestionnaireItem: START ");

    QuestionnaireManagerDB db = new QuestionnaireManagerDB();
    String result = TestDefines.RESULT_OK;

    int idquestionnaireitem = 2;

    Ktek_question instance = db.getQuestion4QuestionnaireItem(idquestionnaireitem);

    if (instance != null) {
        log.info("testGetQuestion4QuestionnaireItem: Instance exists ");
        Assert.assertTrue(true);
    } else {/*from  w ww  .j  a v  a  2  s  . c  o  m*/
        log.error("testGetQuestion4QuestionnaireItem: instance is NULL ");
        Assert.assertTrue(false);
        result = TestDefines.RESULT_ERROR;
    }

    log.info("testGetQuestion4QuestionnaireItem: RESULT " + result);
    log.info("testGetQuestion4QuestionnaireItem: END ");
    log.info("*************************************************************");
    log.info("");
}

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

@Before
public void setUp() throws Exception {
    startServer();/* www .ja  v  a  2 s  .  c o m*/

    Assert.assertFalse(hasUsers());

    // create admin-level user
    String ret = this.addUser(admin_username, admin_password, "1", null);
    JSONObject o = new JSONObject(ret);
    JSONObject user = o.getJSONObject("user");
    this.admin_userId = user.getInt("id");
    Assert.assertEquals(this.admin_username, user.getString("username"));

    // login admin
    ret = this.login(admin_username, admin_password);
    o = new JSONObject(ret);
    Assert.assertEquals(this.admin_userId, o.getInt("userId"));
    this.admin_sessionId = o.getString("sessionId");

    // create user-level user
    ret = this.addUser(user_username, user_password, "2", admin_sessionId);
    o = new JSONObject(ret);
    user = o.getJSONObject("user");
    this.user_userId = user.getInt("id");
    Assert.assertEquals(this.user_username, user.getString("username"));

    // login user
    ret = this.login(user_username, user_password);
    o = new JSONObject(ret);
    Assert.assertEquals(this.user_userId, o.getInt("userId"));
    this.user_sessionId = o.getString("sessionId");

    Assert.assertTrue(hasUsers());
}

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

@Test
public void test3() {
    RemoteServiceGroupConfig config;//from w ww.j av  a2  s  . c o  m

    config = appContext.getBean("serviceGroup103", RemoteServiceGroupConfig.class);
    Assert.assertTrue(config.getRpcTokenProtectionEnabled());
}

From source file:org.geomajas.gwt.server.mvc.GeomajasControllerTest.java

@Test
public void testMockWebContext() throws ServletException, IOException {
    // create mock context that loads from the classpath
    MockServletConfig config = new MockServletConfig();
    MockHttpServletRequest request = new MockHttpServletRequest(config.getServletContext());
    request.setContentType("text/x-gwt-rpc");
    request.setCharacterEncoding("UTF-8");
    request.setContent(("6|0|10|http://apps.geomajas.org/explorer/be.geosparc.Explorer/"
            + "|54044FB0C988344F1715C8B91330B0A2|org.geomajas.gwt.client.GeomajasService|"
            + "execute|org.geomajas.gwt.client.command.GwtCommand/4093389776|command.configuration.GetMap|"
            + "org.geomajas.command.dto.GetMapConfigurationRequest/104733661|explorer|mainMap|"
            + "ss.TqRPfHFh24NVxB|1|2|3|4|1|5|5|6|7|8|9|0|10|").getBytes("UTF-8"));
    request.addHeader("X-GWT-Permutation", "54044FB0C988344F1715C8B91330B0A2");
    request.addHeader("X-GWT-Module-Base", "http://test/module/");
    MockHttpServletResponse response = new MockHttpServletResponse();
    defaultController.setServletConfig(config);
    defaultController.doPost(request, response);
    // expect the message of the out-dated 1.3 policy of GWT
    Assert.assertTrue(response.getContentAsString()
            .contains("Type 'org.geomajas.gwt.client.command.GwtCommand' was not assignable"
                    + " to 'com.google.gwt.user.client.rpc.IsSerializable'"));
}