List of usage examples for junit.framework Assert assertFalse
static public void assertFalse(boolean condition)
From source file:ejportal.webapp.action.InteresseActionTest.java
/** * Test save.//from w ww. j a v a 2 s . c o m * * @throws Exception * the exception */ public void testSave() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); ServletActionContext.setRequest(request); this.action.setInteresseId(1L); Assert.assertEquals("edit", this.action.edit()); Assert.assertNotNull(this.action.getInteresseBaseTO()); // update Name and save this.action.getInteresseBaseTO().setInteresse("Updated Interesse"); Assert.assertEquals("success", this.action.save()); Assert.assertEquals("Updated Interesse", this.action.getInteresseBaseTO().getInteresse()); Assert.assertFalse(this.action.hasActionErrors()); Assert.assertFalse(this.action.hasFieldErrors()); Assert.assertNotNull(request.getSession().getAttribute("messages")); }
From source file:ejportal.webapp.action.RechnungActionTest.java
/** * Test save.//from w w w. j av a 2s . c o m * * @throws Exception * the exception */ public void testSave() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); ServletActionContext.setRequest(request); this.action.setRechnungId(1L); Assert.assertEquals("edit", this.action.edit()); Assert.assertNotNull(this.action.getRechnungBaseTO()); // update bezugsform and save this.action.getRechnungBaseTO().setBezugsform("Updated Bezugsform"); Assert.assertEquals("success", this.action.save()); Assert.assertEquals("Updated Bezugsform", this.action.getRechnungBaseTO().getBezugsform()); Assert.assertFalse(this.action.hasActionErrors()); Assert.assertFalse(this.action.hasFieldErrors()); Assert.assertNotNull(request.getSession().getAttribute("messages")); }
From source file:ejportal.webapp.action.BestellerActionTest.java
/** * Test save.//from w ww. j a va 2 s . c om * * @throws Exception * the exception */ public void testSave() throws Exception { final MockHttpServletRequest request = new MockHttpServletRequest(); ServletActionContext.setRequest(request); this.action.setBestellerId(1L); Assert.assertEquals("edit", this.action.edit()); Assert.assertNotNull(this.action.getBestellerBaseTO()); // update Name and save this.action.getBestellerBaseTO().setBestellerName("Updated Name"); Assert.assertEquals("success", this.action.save()); Assert.assertEquals("Updated Name", this.action.getBestellerBaseTO().getBestellerName()); Assert.assertFalse(this.action.hasActionErrors()); Assert.assertFalse(this.action.hasFieldErrors()); Assert.assertNotNull(request.getSession().getAttribute("messages")); }
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 . j a v a 2s .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.onesite.sdk.test.api.SessionApiTest.java
@Test public void testJoinCrossDomain() { String callbackUrl = "http://example.com"; String domain = "twilight-fans.net"; SessionApi api = new SessionApi(); try {//w w w . j a v a 2 s . c o m URL redirectUrl = api.joinCrossDomain(callbackUrl, domain, ip, agent); System.out.println("Join Cross Domain Redirect Url"); System.out.println(redirectUrl.toString()); Assert.assertFalse(StringUtils.isEmpty(redirectUrl.toString())); } catch (Exception e) { Assert.fail(); } }
From source file:de.itsvs.cwtrpc.controller.config.RemoteServiceControllerConfigBeanDefinitionParserTest.java
@Test public void test3() { RemoteServiceControllerConfig config; config = appContext.getBean("serviceController102", RemoteServiceControllerConfig.class); Assert.assertFalse(config.getResponseCompressionEnabled()); }
From source file:org.geomajas.gwt2.client.map.layer.VectorLayerTest.java
@Test public void testMarkedAsVisible() { VectorServerLayerImpl layer = new VectorServerLayerImpl(mapConfig, layerInfo, viewPort, eventBus); Assert.assertTrue(layer.isMarkedAsVisible()); layer.setMarkedAsVisible(false);/*from ww w .j a v a 2 s .co m*/ Assert.assertFalse(layer.isMarkedAsVisible()); layer.setMarkedAsVisible(true); Assert.assertTrue(layer.isMarkedAsVisible()); }
From source file:com.couchbase.lite.DocumentTest.java
/** * https://github.com/couchbase/couchbase-lite-android/issues/301 *//*from w w w . j av a2s . co m*/ public void testPutDeletedDocument() throws CouchbaseLiteException { Document document = database.createDocument(); Map<String, Object> properties = new HashMap<String, Object>(); properties.put("foo", "foo"); properties.put("bar", Boolean.FALSE); document.putProperties(properties); Assert.assertNotNull(document.getCurrentRevision()); String docId = document.getId(); properties.put("_rev", document.getCurrentRevisionId()); properties.put("_deleted", true); properties.put("mykey", "myval"); SavedRevision newRev = document.putProperties(properties); newRev.loadProperties(); assertTrue(newRev.getProperties().containsKey("mykey")); Assert.assertTrue(document.isDeleted()); Document fetchedDoc = database.getExistingDocument(docId); Assert.assertNull(fetchedDoc); // query all docs and make sure we don't see that document database.getAllDocs(new QueryOptions()); Query queryAllDocs = database.createAllDocumentsQuery(); QueryEnumerator queryEnumerator = queryAllDocs.run(); for (Iterator<QueryRow> it = queryEnumerator; it.hasNext();) { QueryRow row = it.next(); Assert.assertFalse(row.getDocument().getId().equals(docId)); } }
From source file:com.cemeterylistingswebtest.test.services.ViewListingByDateOfDeathServiceTest.java
@Test(enabled = true) public void TestDoD() { dateServ = ctx.getBean(ViewListingByDateOfDeathService.class); repoList = ctx.getBean(PublishedDeceasedListingRepository.class); subRepo = ctx.getBean(SubscriberRepository.class); userRepo = ctx.getBean(UserRoleRepository.class); //Initialise date Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, 2008); calendar.set(Calendar.MONTH, Calendar.FEBRUARY); calendar.set(Calendar.DATE, 4); java.sql.Date javaSqlDate = new java.sql.Date(calendar.getTime().getTime()); //Initialise user role UserRole userRole = new UserRole.Builder().setLevel(1).build(); //userRepo.save(userRole); //userRoleID = userRole.getUserRoleID(); //Initialise subscriber Subscriber newSub = new Subscriber.Builder().setEmail("manfredOsulivan@horseRaddish.com") .setFirstName("Manfred").setSurname("Osulivan").setPwd("jesus").setUsername("ManiFredOssy") .setSubscriptionDate(javaSqlDate).setUserRoleID(userRole).build(); subRepo.save(newSub);/*from w w w .j av a 2s . co m*/ subID = newSub.getSubscriberID(); PublishedDeceasedListing newListing = new PublishedDeceasedListing.Builder().setFirstName("Hendrika") .setSurname("Fourie").setMaidenName("Gerber").setGender("Female").setDateOfBirth("08/06/1969") .setDateOfDeath("14/02/2005").setGraveInscription("Hippiest person eva").setGraveNumber("2456") .setImageOfBurialSite("/images/001.jpg").setLastKnownContactName("Berry") .setLastKnownContactNumber("0725576482") .setSubscriberSubmitID(subID).build(); repoList.save(newListing); List<PublishedDeceasedListing> pubListDod = dateServ.findListingByDOD("14/02/2005"); Assert.assertFalse(pubListDod.isEmpty()); repoList.delete(newListing); subRepo.delete(subID); }
From source file:com.sap.prd.mobile.ios.mios.FatBinaryTest.java
@Test public void testUsePreferredFatLib() throws Exception { final File testSourceDirApp = new File(getTestRootDirectory(), "straight-forward/MyApp"); final File alternateTestSourceDirApp = new File(getTestRootDirectory(), "straight-forward-fat-libs/MyApp"); final String testName = getTestName(); Map<String, String> additionalSystemProperties = new HashMap<String, String>(); additionalSystemProperties.put("xcode.preferFatLibs", Boolean.TRUE.toString()); Properties pomReplacements = new Properties(); pomReplacements.setProperty(PROP_NAME_DEPLOY_REPO_DIR, remoteRepoDir.getAbsolutePath()); pomReplacements.setProperty(PROP_NAME_DYNAMIC_VERSION, dynamicVersion); test(testName, testSourceDirApp, "install", THE_EMPTY_LIST, additionalSystemProperties, pomReplacements, new FileCopyProjectModifier(alternateTestSourceDirApp)); final File testRootDir = getTestExecutionDirectory(testName, "MyApp"); Assert.assertTrue(new File(testRootDir, "target/xcode-deps/libs/Release/com.sap.ondevice.production.ios.tests/MyLibrary/libMyLibrary.a") .exists());/* w ww . j a va 2 s . c o m*/ Assert.assertFalse(new File(testRootDir, "target/libs/Release-iphoneos/com.sap.ondevice.production.ios.tests/MyLibrary/libMyLibrary.a") .exists()); Assert.assertFalse(new File(testRootDir, "target/libs/Release-iphonesimulator/com.sap.ondevice.production.ios.tests/MyLibrary/libMyLibrary.a") .exists()); }