3 files added
7 files modified
| | |
| | | int mins = 60;
|
| | | if (!StringUtils.isEmpty(frequency)) {
|
| | | try {
|
| | | String str;
|
| | | String str = frequency.trim();
|
| | | if (frequency.indexOf(' ') > -1) {
|
| | | str = frequency.substring(0, frequency.indexOf(' ')).trim();
|
| | | } else {
|
| | | str = frequency.trim();
|
| | | str = str.substring(0, str.indexOf(' ')).trim();
|
| | | }
|
| | | mins = (int) Float.parseFloat(str);
|
| | | } catch (NumberFormatException e) {
|
| | |
| | | }
|
| | | if (frequency.indexOf("day") > -1) {
|
| | | // convert to minutes
|
| | | mins *= 24 * 60;
|
| | | mins *= 1440;
|
| | | } else if (frequency.indexOf("hour") > -1) {
|
| | | // convert to minutes
|
| | | mins *= 60;
|
New file |
| | |
| | | /*
|
| | | * Copyright 2011 gitblit.com.
|
| | | *
|
| | | * Licensed under the Apache License, Version 2.0 (the "License");
|
| | | * you may not use this file except in compliance with the License.
|
| | | * You may obtain a copy of the License at
|
| | | *
|
| | | * http://www.apache.org/licenses/LICENSE-2.0
|
| | | *
|
| | | * Unless required by applicable law or agreed to in writing, software
|
| | | * distributed under the License is distributed on an "AS IS" BASIS,
|
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| | | * See the License for the specific language governing permissions and
|
| | | * limitations under the License.
|
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | |
|
| | | import com.gitblit.utils.Base64;
|
| | |
|
| | | public class Base64Test extends TestCase {
|
| | |
|
| | | public void testBase64() {
|
| | | String source = "this is a test"; |
| | | String base64 = Base64.encodeBytes(source.getBytes());
|
| | | assertEquals("dGhpcyBpcyBhIHRlc3Q=", base64);
|
| | | String decoded = new String(Base64.decode(base64));
|
| | | assertEquals(source, decoded);
|
| | | }
|
| | | } |
| | |
| | | String rawContent = FileUtils.readContent(new File(dir, "LICENSE"), "\n");
|
| | | assertTrue(rawContent.trim().startsWith("Apache License"));
|
| | | }
|
| | | |
| | | public void testWriteContent() throws Exception {
|
| | | String contentA = "this is a test";
|
| | | File tmp = File.createTempFile("gitblit-", ".test");
|
| | | FileUtils.writeContent(tmp, contentA);
|
| | | String contentB = FileUtils.readContent(tmp, "\n").trim();
|
| | | assertEquals(contentA, contentB);
|
| | | }
|
| | |
|
| | | public void testFolderSize() throws Exception {
|
| | | assertEquals(-1, FileUtils.folderSize(null));
|
| | |
| | | package com.gitblit.tests;
|
| | |
|
| | | import java.io.File;
|
| | | import java.util.concurrent.Executors;
|
| | |
|
| | | import junit.extensions.TestSetup;
|
| | | import junit.framework.Test;
|
| | |
| | | import com.gitblit.FileUserService;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.GitBlitException;
|
| | | import com.gitblit.GitBlitServer;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | |
|
| | | public class GitBlitSuite extends TestSetup {
|
| | |
|
| | | public static final File REPOSITORIES = new File("git");
|
| | |
|
| | | static int port = 8280;
|
| | | static int shutdownPort = 8281;
|
| | |
|
| | | public static String url = "http://localhost:" + port;
|
| | | public static String account = "admin";
|
| | | public static String password = "admin";
|
| | |
|
| | | private GitBlitSuite(TestSuite suite) {
|
| | | super(suite);
|
| | |
| | | suite.addTestSuite(FileUtilsTest.class);
|
| | | suite.addTestSuite(TimeUtilsTest.class);
|
| | | suite.addTestSuite(StringUtilsTest.class);
|
| | | suite.addTestSuite(Base64Test.class);
|
| | | suite.addTestSuite(JsonUtilsTest.class);
|
| | | suite.addTestSuite(ByteFormatTest.class);
|
| | | suite.addTestSuite(ObjectCacheTest.class);
|
| | | suite.addTestSuite(MarkdownUtilsTest.class);
|
| | | suite.addTestSuite(JGitUtilsTest.class);
|
| | | suite.addTestSuite(SyndicationUtilsTest.class);
|
| | |
| | | suite.addTestSuite(MetricUtilsTest.class);
|
| | | suite.addTestSuite(TicgitUtilsTest.class);
|
| | | suite.addTestSuite(GitBlitTest.class);
|
| | | suite.addTestSuite(RpcTests.class);
|
| | | return new GitBlitSuite(suite);
|
| | | }
|
| | |
|
| | |
| | |
|
| | | public static Repository getBluezGnomeRepository() throws Exception {
|
| | | return new FileRepository(new File(REPOSITORIES, "test/bluez-gnome.git"));
|
| | | }
|
| | |
|
| | | public static void startGitblit() throws Exception {
|
| | | // Start a Gitblit instance
|
| | | Executors.newSingleThreadExecutor().execute(new Runnable() {
|
| | | public void run() {
|
| | | GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
|
| | | "" + shutdownPort, "--repositoriesFolder",
|
| | | "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
|
| | | "distrib/users.properties");
|
| | | }
|
| | | });
|
| | |
|
| | | // Wait a few seconds for it to be running
|
| | | Thread.sleep(2500);
|
| | | }
|
| | |
|
| | | public static void stopGitblit() throws Exception {
|
| | | // Stop Gitblit
|
| | | GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort);
|
| | |
|
| | | // Wait a few seconds for it to be running
|
| | | Thread.sleep(2500);
|
| | | }
|
| | |
|
| | | @Override
|
| | |
| | | showRemoteBranches("ticgit.git");
|
| | | showRemoteBranches("test/jgit.git");
|
| | | }
|
| | |
|
| | | startGitblit();
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void tearDown() throws Exception {
|
| | | stopGitblit();
|
| | | }
|
| | |
|
| | | private void cloneOrFetch(String name, String fromUrl) throws Exception {
|
| | |
| | | public void testGitblitSettings() throws Exception {
|
| | | // These are already tested by above test method.
|
| | | assertTrue(GitBlit.getBoolean("missing", true));
|
| | | assertTrue(GitBlit.getString("missing", "default").equals("default"));
|
| | | assertTrue(GitBlit.getInteger("missing", 10) == 10);
|
| | | assertTrue(GitBlit.getInteger("realm.userService", 5) == 5);
|
| | | assertEquals("default", GitBlit.getString("missing", "default"));
|
| | | assertEquals(10, GitBlit.getInteger("missing", 10));
|
| | | assertEquals(5, GitBlit.getInteger("realm.userService", 5));
|
| | |
|
| | | assertTrue(GitBlit.getBoolean("git.enableGitServlet", false));
|
| | | assertTrue(GitBlit.getString("realm.userService", null).equals("users.properties"));
|
| | | assertTrue(GitBlit.getInteger("realm.minPasswordLength", 0) == 5);
|
| | | assertEquals("distrib/users.properties", GitBlit.getString("realm.userService", null));
|
| | | assertEquals(5, GitBlit.getInteger("realm.minPasswordLength", 0));
|
| | | List<String> mdExtensions = GitBlit.getStrings("web.markdownExtensions");
|
| | | assertTrue(mdExtensions.size() > 0);
|
| | | assertTrue(mdExtensions.contains("md"));
|
New file |
| | |
| | | /*
|
| | | * Copyright 2011 gitblit.com.
|
| | | *
|
| | | * Licensed under the Apache License, Version 2.0 (the "License");
|
| | | * you may not use this file except in compliance with the License.
|
| | | * You may obtain a copy of the License at
|
| | | *
|
| | | * http://www.apache.org/licenses/LICENSE-2.0
|
| | | *
|
| | | * Unless required by applicable law or agreed to in writing, software
|
| | | * distributed under the License is distributed on an "AS IS" BASIS,
|
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| | | * See the License for the specific language governing permissions and
|
| | | * limitations under the License.
|
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.Date;
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | |
|
| | | import com.gitblit.utils.JsonUtils;
|
| | | import com.google.gson.reflect.TypeToken;
|
| | |
|
| | | public class JsonUtilsTest extends TestCase {
|
| | |
|
| | | public void testSerialization() {
|
| | | Map<String, String> map = new HashMap<String, String>();
|
| | | map.put("a", "alligator");
|
| | | map.put("b", "bear");
|
| | | map.put("c", "caterpillar");
|
| | | map.put("d", "dingo");
|
| | | map.put("e", "eagle");
|
| | | String json = JsonUtils.toJsonString(map);
|
| | | assertEquals(
|
| | | "{\n \"d\": \"dingo\",\n \"e\": \"eagle\",\n \"b\": \"bear\",\n \"c\": \"caterpillar\",\n \"a\": \"alligator\"\n}",
|
| | | json);
|
| | | Map<String, String> map2 = JsonUtils.fromJsonString(json,
|
| | | new TypeToken<Map<String, String>>() {
|
| | | }.getType());
|
| | | assertEquals(map, map2);
|
| | |
|
| | | SomeJsonObject someJson = new SomeJsonObject();
|
| | | json = JsonUtils.toJsonString(someJson);
|
| | | SomeJsonObject someJson2 = JsonUtils.fromJsonString(json, SomeJsonObject.class);
|
| | | assertEquals(someJson.name, someJson2.name);
|
| | | SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd HHmmss");
|
| | | assertEquals(df.format(someJson.date), df.format(someJson2.date));
|
| | | }
|
| | |
|
| | | private class SomeJsonObject {
|
| | | Date date = new Date();
|
| | | String name = "myJson";
|
| | | }
|
| | | } |
New file |
| | |
| | | /*
|
| | | * Copyright 2011 gitblit.com.
|
| | | *
|
| | | * Licensed under the Apache License, Version 2.0 (the "License");
|
| | | * you may not use this file except in compliance with the License.
|
| | | * You may obtain a copy of the License at
|
| | | *
|
| | | * http://www.apache.org/licenses/LICENSE-2.0
|
| | | *
|
| | | * Unless required by applicable law or agreed to in writing, software
|
| | | * distributed under the License is distributed on an "AS IS" BASIS,
|
| | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| | | * See the License for the specific language governing permissions and
|
| | | * limitations under the License.
|
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import java.util.Date;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | |
|
| | | import com.gitblit.utils.ObjectCache;
|
| | |
|
| | | public class ObjectCacheTest extends TestCase {
|
| | |
|
| | | public void testCache() throws Exception {
|
| | | ObjectCache<String> cache = new ObjectCache<String>();
|
| | | cache.updateObject("test", "alpha");
|
| | | Date date = cache.getDate("test");
|
| | | assertTrue("cache date is not working!", cache.hasCurrent("test", date));
|
| | | // The cache is time-based (msecs) so we insert this artificial sleep to
|
| | | // ensure that time (msecs) advances. The ObjectCache class is suitable
|
| | | // for Gitblit's needs but may not be suitable for other needs.
|
| | | Thread.sleep(10);
|
| | | cache.updateObject("test", "beta");
|
| | | assertFalse("update cache date is not working!", cache.hasCurrent("test", date));
|
| | | assertEquals("unexpected cache object", cache.getObject("test"), "beta");
|
| | | assertEquals("beta", cache.remove("test"));
|
| | | assertEquals(null, cache.getObject("test"));
|
| | | assertEquals(null, cache.remove("test"));
|
| | | }
|
| | | }
|
| | |
| | | */
|
| | | package com.gitblit.tests;
|
| | |
|
| | | import static org.junit.Assert.assertEquals;
|
| | | import static org.junit.Assert.assertTrue;
|
| | |
|
| | | import java.io.IOException;
|
| | | import java.util.Collection;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.concurrent.Executors;
|
| | |
|
| | | import junit.framework.TestCase;
|
| | |
|
| | | import org.junit.AfterClass;
|
| | | import org.junit.BeforeClass;
|
| | |
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.GitBlitException.UnauthorizedException;
|
| | | import com.gitblit.GitBlitServer;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.FederationModel;
|
| | | import com.gitblit.models.FederationProposal;
|
| | |
| | | * @author James Moger
|
| | | *
|
| | | */
|
| | | public class RpcTests {
|
| | | public class RpcTests extends TestCase {
|
| | |
|
| | | static int port = 8180;
|
| | | static int shutdownPort = 8181;
|
| | | String url = GitBlitSuite.url;
|
| | | String account = GitBlitSuite.account;
|
| | | String password = GitBlitSuite.password;
|
| | |
|
| | | String url = "http://localhost:" + port;
|
| | | String account = "admin";
|
| | | String password = "admin";
|
| | |
|
| | | @BeforeClass
|
| | | public static void startGitblit() throws Exception {
|
| | | // Start a Gitblit instance
|
| | | Executors.newSingleThreadExecutor().execute(new Runnable() {
|
| | | public void run() {
|
| | | GitBlitServer.main("--httpPort", "" + port, "--httpsPort", "0", "--shutdownPort",
|
| | | "" + shutdownPort, "--repositoriesFolder",
|
| | | "\"" + GitBlitSuite.REPOSITORIES.getAbsolutePath() + "\"", "--userService",
|
| | | "distrib/users.properties");
|
| | | }
|
| | | });
|
| | |
|
| | | // Wait a few seconds for it to be running
|
| | | Thread.sleep(2500);
|
| | | GitBlitSuite.startGitblit();
|
| | | }
|
| | |
|
| | | @AfterClass
|
| | | public static void stopGitblit() throws Exception {
|
| | | // Stop Gitblit
|
| | | GitBlitServer.main("--stop", "--shutdownPort", "" + shutdownPort);
|
| | |
|
| | | // Wait a few seconds for it to be running
|
| | | Thread.sleep(2500);
|
| | | GitBlitSuite.stopGitblit();
|
| | | }
|
| | |
|
| | | @Test
|
| | |
| | |
|
| | | import junit.framework.TestCase;
|
| | |
|
| | | import com.gitblit.Constants.SearchType;
|
| | | import com.gitblit.models.SyndicatedEntryModel;
|
| | | import com.gitblit.utils.SyndicationUtils;
|
| | |
|
| | |
| | | entry.content = "Content " + i;
|
| | | entry.repository = "Repository " + i;
|
| | | entry.branch = "Branch " + i;
|
| | | List<String> tags = new ArrayList<String>();
|
| | | for (int j = 0; j < 5; j++) {
|
| | | tags.add("Tag " + j);
|
| | | }
|
| | | entry.tags = tags;
|
| | | entries.add(entry);
|
| | | }
|
| | | ByteArrayOutputStream os = new ByteArrayOutputStream();
|
| | |
| | | public void testFeedRead() throws Exception {
|
| | | Set<String> links = new HashSet<String>();
|
| | | for (int i = 0; i < 2; i++) {
|
| | | List<SyndicatedEntryModel> feed = SyndicationUtils.readFeed("https://localhost:8443",
|
| | | "ticgit.git", "master", 5, i, "admin", "admin".toCharArray());
|
| | | List<SyndicatedEntryModel> feed = SyndicationUtils.readFeed(GitBlitSuite.url,
|
| | | "ticgit.git", "master", 5, i, GitBlitSuite.account,
|
| | | GitBlitSuite.password.toCharArray());
|
| | | assertTrue(feed != null);
|
| | | assertTrue(feed.size() > 0);
|
| | | assertEquals(5, feed.size());
|
| | |
| | | }
|
| | |
|
| | | public void testSearchFeedRead() throws Exception {
|
| | | List<SyndicatedEntryModel> feed = SyndicationUtils.readSearchFeed("https://localhost:8443",
|
| | | "ticgit.git", null, "documentation", null, 5, 0, "admin", "admin".toCharArray());
|
| | | List<SyndicatedEntryModel> feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url,
|
| | | "ticgit.git", null, "test", null, 5, 0, GitBlitSuite.account,
|
| | | GitBlitSuite.password.toCharArray());
|
| | | assertTrue(feed != null);
|
| | | assertTrue(feed.size() > 0);
|
| | | assertEquals(2, feed.size());
|
| | | assertEquals(5, feed.size());
|
| | | feed = SyndicationUtils.readSearchFeed(GitBlitSuite.url, "ticgit.git", "master", "test",
|
| | | SearchType.COMMIT, 5, 1, GitBlitSuite.account, GitBlitSuite.password.toCharArray());
|
| | | assertTrue(feed != null);
|
| | | assertTrue(feed.size() > 0);
|
| | | assertEquals(5, feed.size());
|
| | | }
|
| | | } |
| | |
| | | }
|
| | |
|
| | | public void testDurations() throws Exception {
|
| | | assertTrue(TimeUtils.duration(1).equals("1 day"));
|
| | | assertTrue(TimeUtils.duration(5).equals("5 days"));
|
| | | assertTrue(TimeUtils.duration(75).equals("3 months"));
|
| | | assertTrue(TimeUtils.duration(364).equals("12 months"));
|
| | | assertTrue(TimeUtils.duration(365 + 0).equals("1 year"));
|
| | | assertTrue(TimeUtils.duration(365 + 10).equals("1 year"));
|
| | | assertTrue(TimeUtils.duration(365 + 15).equals("1 year, 1 month"));
|
| | | assertTrue(TimeUtils.duration(365 + 30).equals("1 year, 1 month"));
|
| | | assertTrue(TimeUtils.duration(365 + 44).equals("1 year, 1 month"));
|
| | | assertTrue(TimeUtils.duration(365 + 45).equals("1 year, 2 months"));
|
| | | assertTrue(TimeUtils.duration(365 + 60).equals("1 year, 2 months"));
|
| | | assertEquals("1 day", TimeUtils.duration(1));
|
| | | assertEquals("5 days", TimeUtils.duration(5));
|
| | | assertEquals("3 months", TimeUtils.duration(75));
|
| | | assertEquals("12 months", TimeUtils.duration(364));
|
| | | assertEquals("1 year", TimeUtils.duration(365 + 0));
|
| | | assertEquals("1 year", TimeUtils.duration(365 + 10));
|
| | | assertEquals("1 year, 1 month", TimeUtils.duration(365 + 15));
|
| | | assertEquals("1 year, 1 month", TimeUtils.duration(365 + 30));
|
| | | assertEquals("1 year, 1 month", TimeUtils.duration(365 + 44));
|
| | | assertEquals("1 year, 2 months", TimeUtils.duration(365 + 45));
|
| | | assertEquals("1 year, 2 months", TimeUtils.duration(365 + 60));
|
| | |
|
| | | assertTrue(TimeUtils.duration(2 * 365 + 0).equals("2 years"));
|
| | | assertTrue(TimeUtils.duration(2 * 365 + 10).equals("2 years"));
|
| | | assertTrue(TimeUtils.duration(2 * 365 + 15).equals("2 years, 1 month"));
|
| | | assertTrue(TimeUtils.duration(2 * 365 + 30).equals("2 years, 1 month"));
|
| | | assertTrue(TimeUtils.duration(2 * 365 + 44).equals("2 years, 1 month"));
|
| | | assertTrue(TimeUtils.duration(2 * 365 + 45).equals("2 years, 2 months"));
|
| | | assertTrue(TimeUtils.duration(2 * 365 + 60).equals("2 years, 2 months"));
|
| | | assertEquals("2 years", TimeUtils.duration(2 * 365 + 0));
|
| | | assertEquals("2 years", TimeUtils.duration(2 * 365 + 10));
|
| | | assertEquals("2 years, 1 month", TimeUtils.duration(2 * 365 + 15));
|
| | | assertEquals("2 years, 1 month", TimeUtils.duration(2 * 365 + 30));
|
| | | assertEquals("2 years, 1 month", TimeUtils.duration(2 * 365 + 44));
|
| | | assertEquals("2 years, 2 months", TimeUtils.duration(2 * 365 + 45));
|
| | | assertEquals("2 years, 2 months", TimeUtils.duration(2 * 365 + 60));
|
| | | }
|
| | |
|
| | | public void testTimeAgo() throws Exception {
|
| | | // standard time ago tests
|
| | | assertTrue(TimeUtils.timeAgo(offset(1 * TimeUtils.MIN)).equals("1 min ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(60 * TimeUtils.MIN)).equals("60 mins ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(120 * TimeUtils.MIN)).equals("2 hours ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(15 * TimeUtils.ONEHOUR)).equals("15 hours ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(24 * TimeUtils.ONEHOUR)).equals("yesterday"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(2 * TimeUtils.ONEDAY)).equals("2 days ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(35 * TimeUtils.ONEDAY)).equals("5 weeks ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(84 * TimeUtils.ONEDAY)).equals("3 months ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(95 * TimeUtils.ONEDAY)).equals("3 months ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(104 * TimeUtils.ONEDAY)).equals("4 months ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(365 * TimeUtils.ONEDAY)).equals("1 year ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset(395 * TimeUtils.ONEDAY)).equals("13 months ago"));
|
| | | assertTrue(TimeUtils.timeAgo(offset((2 * 365 + 30) * TimeUtils.ONEDAY)).equals(
|
| | | "2 years ago"));
|
| | | assertEquals("1 min ago", TimeUtils.timeAgo(offset(1 * TimeUtils.MIN)));
|
| | | assertEquals("60 mins ago", TimeUtils.timeAgo(offset(60 * TimeUtils.MIN)));
|
| | | assertEquals("2 hours ago", TimeUtils.timeAgo(offset(120 * TimeUtils.MIN)));
|
| | | assertEquals("15 hours ago", TimeUtils.timeAgo(offset(15 * TimeUtils.ONEHOUR)));
|
| | | assertEquals("yesterday", TimeUtils.timeAgo(offset(24 * TimeUtils.ONEHOUR)));
|
| | | assertEquals("2 days ago", TimeUtils.timeAgo(offset(2 * TimeUtils.ONEDAY)));
|
| | | assertEquals("5 weeks ago", TimeUtils.timeAgo(offset(35 * TimeUtils.ONEDAY)));
|
| | | assertEquals("3 months ago", TimeUtils.timeAgo(offset(84 * TimeUtils.ONEDAY)));
|
| | | assertEquals("3 months ago", TimeUtils.timeAgo(offset(95 * TimeUtils.ONEDAY)));
|
| | | assertEquals("4 months ago", TimeUtils.timeAgo(offset(104 * TimeUtils.ONEDAY)));
|
| | | assertEquals("1 year ago", TimeUtils.timeAgo(offset(365 * TimeUtils.ONEDAY)));
|
| | | assertEquals("13 months ago", TimeUtils.timeAgo(offset(395 * TimeUtils.ONEDAY)));
|
| | | assertEquals("2 years ago", TimeUtils.timeAgo(offset((2 * 365 + 30) * TimeUtils.ONEDAY)));
|
| | |
|
| | | // css class tests
|
| | | assertTrue(TimeUtils.timeAgoCss(offset(1 * TimeUtils.MIN)).equals("age0"));
|
| | | assertTrue(TimeUtils.timeAgoCss(offset(60 * TimeUtils.MIN)).equals("age0"));
|
| | | assertTrue(TimeUtils.timeAgoCss(offset(120 * TimeUtils.MIN)).equals("age1"));
|
| | | assertTrue(TimeUtils.timeAgoCss(offset(24 * TimeUtils.ONEHOUR)).equals("age1"));
|
| | | assertTrue(TimeUtils.timeAgoCss(offset(2 * TimeUtils.ONEDAY)).equals("age2"));
|
| | | assertEquals("age0", TimeUtils.timeAgoCss(offset(1 * TimeUtils.MIN)));
|
| | | assertEquals("age0", TimeUtils.timeAgoCss(offset(60 * TimeUtils.MIN)));
|
| | | assertEquals("age1", TimeUtils.timeAgoCss(offset(120 * TimeUtils.MIN)));
|
| | | assertEquals("age1", TimeUtils.timeAgoCss(offset(24 * TimeUtils.ONEHOUR)));
|
| | | assertEquals("age2", TimeUtils.timeAgoCss(offset(2 * TimeUtils.ONEDAY)));
|
| | | }
|
| | |
|
| | | public void testFrequency() {
|
| | | assertEquals(5, TimeUtils.convertFrequencyToMinutes("2 mins"));
|
| | | assertEquals(10, TimeUtils.convertFrequencyToMinutes("10 mins"));
|
| | | assertEquals(600, TimeUtils.convertFrequencyToMinutes("10 hours"));
|
| | | assertEquals(14400, TimeUtils.convertFrequencyToMinutes(" 10 days "));
|
| | | }
|
| | | }
|