PageRenderTime 41ms CodeModel.GetById 15ms app.highlight 20ms RepoModel.GetById 2ms app.codeStats 0ms

/v3.2/nimbits-sdk/test/SeriesTest.java

http://nimbits-server.googlecode.com/
Java | 97 lines | 58 code | 27 blank | 12 comment | 3 complexity | 0ea33c7eb7dcdec9a365d7c22b88acda MD5 | raw file
 1/*
 2 * Copyright (c) 2011. Tonic Solutions LLC. All Rights reserved.
 3 *
 4 * This source code is distributed under GPL v3 without any warranty.
 5 */
 6
 7import com.nimbits.client.model.Const;
 8import com.nimbits.client.model.category.CategoryName;
 9import com.nimbits.client.model.common.CommonFactoryLocator;
10import com.nimbits.client.model.point.Point;
11import com.nimbits.client.model.point.PointModel;
12import com.nimbits.client.model.value.Value;
13import org.junit.Test;
14
15import java.io.File;
16import java.io.IOException;
17import java.util.*;
18
19import static org.junit.Assert.assertTrue;
20
21/**
22 * Created by bsautner
23 * User: benjamin
24 * Date: 3/28/11
25 * Time: 12:58 PM
26 *
27 */
28public class SeriesTest  {
29
30
31    @Test
32    public void testGetLargeSeries() throws Exception {
33       Random rx = new Random();
34        Point p = new PointModel();
35
36        p.setName( CommonFactoryLocator.getInstance().createPointName("test" + UUID.randomUUID().toString()));
37        CategoryName categoryName = CommonFactoryLocator.getInstance().createCategoryName( Const.CONST_HIDDEN_CATEGORY);
38        Common.client().addPoint(p,categoryName);
39        for (int i = 0; i < 1100; i++) {
40
41            Common.client().recordValue(p.getName(), rx.nextDouble() * 1000, new Date(new Date().getTime() - (5000 - i)));
42
43        }
44
45        Calendar s = Calendar.getInstance();
46        s.set(2009, 0, 1);
47
48        List<Value> r = Common.client().getSeries(p.getName(), s.getTime(), new Date());
49
50        assertTrue(r.size() > 1000);
51         Common.client().deletePoint(p.getName());
52    }
53    @Test
54    public void testFileDownload() {
55        Calendar s = Calendar.getInstance();
56        String fn = "/tmp/b1.json";
57        s.set(2009, 0, 1);
58                Point p = new PointModel();
59
60        p.setName( CommonFactoryLocator.getInstance().createPointName("test" + UUID.randomUUID().toString()));
61        CategoryName categoryName = CommonFactoryLocator.getInstance().createCategoryName( Const.CONST_HIDDEN_CATEGORY);
62        Common.client().addPoint(p,categoryName);
63        try {
64            Random rx = new Random();
65
66        for (int i = 0; i < 100; i++) {
67
68            Common.client().recordValue(p.getName(), rx.nextDouble() * 1000, new Date(new Date().getTime() - (5000 - i)));
69
70        }
71
72            Common.client().downloadSeries(p.getName(), s.getTime(), new Date(), fn);
73
74            File f = new File(fn);
75
76            assertTrue(f.exists());
77            if (f.exists()) {
78                List<Value> r = Common.client().loadSeriesFile(fn);
79                assertTrue(r.size() > 1);
80
81                f.delete();
82
83            }
84            Common.client().deletePoint(p.getName());
85        } catch (IOException e) {
86
87            e.printStackTrace();
88        } catch (Exception e) {
89          e.printStackTrace();
90        }
91
92    }
93
94
95
96
97}