/v3.2/nimbits-sdk/test/DataLoadingTest.java
http://nimbits-server.googlecode.com/ · Java · 119 lines · 78 code · 28 blank · 13 comment · 5 complexity · 4edb79e93f899f228e9aa28c3f1fd43d MD5 · raw file
- /*
- * Copyright (c) 2011. Tonic Solutions LLC. All Rights reserved.
- *
- * This source code is distributed under GPL v3 without any warranty.
- */
- import com.nimbits.client.NimbitsClient;
- import com.nimbits.client.NimbitsClientFactory;
- import com.nimbits.client.model.common.CommonFactoryLocator;
- import com.nimbits.client.model.email.EmailAddress;
- import com.nimbits.client.model.point.PointName;
- import com.nimbits.client.model.value.Value;
- import com.nimbits.user.NimbitsUser;
- import com.nimbits.user.UserFactory;
- import org.junit.Test;
- import java.io.IOException;
- import java.util.Date;
- import java.util.List;
- import java.util.Random;
- import static java.lang.Thread.sleep;
- import static org.junit.Assert.assertEquals;
- import static org.junit.Assert.assertNotNull;
- /**
- * Created by bsautner
- * User: benjamin
- * Date: 3/27/11
- * Time: 3:08 PM
- */
- public class DataLoadingTest {
- private void sample() {
- EmailAddress emailAddress = CommonFactoryLocator.getInstance().createEmailAddress("test@example.com");
- NimbitsUser user = UserFactory.createNimbitsUser(emailAddress, "pas$$word");
- NimbitsClient client = NimbitsClientFactory.getInstance(user, "http://mynimbitsserver.domain.com");
- PointName pointName = CommonFactoryLocator.getInstance().createPointName("MyDataPoint");
- Value currentValue = client.getCurrentRecordedValue(pointName);
- System.out.println(currentValue.getValue()); //get the last recorded double value
- System.out.println(currentValue.getAlertState().name()); //the state of the point - i.e high alert or idle
- }
- @Test
- public void TempFTestOnProd() throws InterruptedException, IOException {
- PointName pointName = CommonFactoryLocator.getInstance().createPointName("TempF");
- for (int i = 0; i < 10; i++) {
- Common.meOnProd().recordValueWithGet(pointName, i, new Date());
- sleep(1000);
- }
- sleep(2000);
- List<Value> result = Common.meOnProd().getSeries(pointName, 10);
- double t = 0;
- for (Value v : result) {
- System.out.println(v.getValue());
- t += v.getValue();
- }
- System.out.println(t);
- assertEquals(45.0, t, 0);
- }
- @Test
- public void TempNewPointOnProd() throws InterruptedException, IOException {
- PointName pointName = CommonFactoryLocator.getInstance().createPointName("new");
- System.out.println(Common.meOnProd().isLoggedIn());
- for (int i = 0; i < 10; i++) {
- Common.meOnProd().recordValue(pointName, i, new Date());
- sleep(1000);
- }
- sleep(2000);
- List<Value> result = Common.meOnProd().getSeries(pointName, 10);
- for (Value v : result) {
- System.out.println(v.getValue());
- }
- }
- @Test
- public void testLoadRandom() throws IOException {
- Date start = new Date();
- Random r = new Random();
- for (int i = 0; i < 10; i++) {
- try {
- System.out.println(i);
- PointName pointName = CommonFactoryLocator.getInstance().createPointName("b1");
- Value v = Common.client().recordValue(pointName, (r.nextDouble() * 100), new Date());
- assertNotNull(v);
- // Assert.assertTrue(v.getKey() > 0);
- // Thread.sleep(100);
- } catch (Exception ex) {
- ex.printStackTrace();
- }
- }
- Date end = new Date();
- long time = (end.getTime() - start.getTime()) / 1000;
- System.out.println(time);
- PointName pointName = CommonFactoryLocator.getInstance().createPointName("Time to record 10 values to b1");
- Common.clientSupportOnProd().recordValue(pointName, time, new Date());
- }
- }