/v3.2/nimbits-sdk/test/DataLoadingTest.java
Java | 119 lines | 78 code | 28 blank | 13 comment | 5 complexity | 4edb79e93f899f228e9aa28c3f1fd43d 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.NimbitsClient; 8import com.nimbits.client.NimbitsClientFactory; 9import com.nimbits.client.model.common.CommonFactoryLocator; 10import com.nimbits.client.model.email.EmailAddress; 11import com.nimbits.client.model.point.PointName; 12import com.nimbits.client.model.value.Value; 13import com.nimbits.user.NimbitsUser; 14import com.nimbits.user.UserFactory; 15import org.junit.Test; 16 17import java.io.IOException; 18import java.util.Date; 19import java.util.List; 20import java.util.Random; 21 22import static java.lang.Thread.sleep; 23import static org.junit.Assert.assertEquals; 24import static org.junit.Assert.assertNotNull; 25 26/** 27 * Created by bsautner 28 * User: benjamin 29 * Date: 3/27/11 30 * Time: 3:08 PM 31 */ 32public class DataLoadingTest { 33 private void sample() { 34 EmailAddress emailAddress = CommonFactoryLocator.getInstance().createEmailAddress("test@example.com"); 35 NimbitsUser user = UserFactory.createNimbitsUser(emailAddress, "pas$$word"); 36 NimbitsClient client = NimbitsClientFactory.getInstance(user, "http://mynimbitsserver.domain.com"); 37 PointName pointName = CommonFactoryLocator.getInstance().createPointName("MyDataPoint"); 38 Value currentValue = client.getCurrentRecordedValue(pointName); 39 40 System.out.println(currentValue.getValue()); //get the last recorded double value 41 System.out.println(currentValue.getAlertState().name()); //the state of the point - i.e high alert or idle 42 43 } 44 45 @Test 46 public void TempFTestOnProd() throws InterruptedException, IOException { 47 PointName pointName = CommonFactoryLocator.getInstance().createPointName("TempF"); 48 49 50 for (int i = 0; i < 10; i++) { 51 52 Common.meOnProd().recordValueWithGet(pointName, i, new Date()); 53 sleep(1000); 54 } 55 56 sleep(2000); 57 List<Value> result = Common.meOnProd().getSeries(pointName, 10); 58 double t = 0; 59 for (Value v : result) { 60 System.out.println(v.getValue()); 61 t += v.getValue(); 62 } 63 System.out.println(t); 64 assertEquals(45.0, t, 0); 65 66 } 67 68 @Test 69 public void TempNewPointOnProd() throws InterruptedException, IOException { 70 PointName pointName = CommonFactoryLocator.getInstance().createPointName("new"); 71 System.out.println(Common.meOnProd().isLoggedIn()); 72 73 for (int i = 0; i < 10; i++) { 74 Common.meOnProd().recordValue(pointName, i, new Date()); 75 sleep(1000); 76 } 77 78 sleep(2000); 79 List<Value> result = Common.meOnProd().getSeries(pointName, 10); 80 for (Value v : result) { 81 System.out.println(v.getValue()); 82 } 83 } 84 85 @Test 86 public void testLoadRandom() throws IOException { 87 88 Date start = new Date(); 89 90 91 Random r = new Random(); 92 93 for (int i = 0; i < 10; i++) { 94 try { 95 System.out.println(i); 96 PointName pointName = CommonFactoryLocator.getInstance().createPointName("b1"); 97 Value v = Common.client().recordValue(pointName, (r.nextDouble() * 100), new Date()); 98 assertNotNull(v); 99 100 // Assert.assertTrue(v.getKey() > 0); 101 // Thread.sleep(100); 102 } catch (Exception ex) { 103 ex.printStackTrace(); 104 } 105 106 107 } 108 109 Date end = new Date(); 110 long time = (end.getTime() - start.getTime()) / 1000; 111 System.out.println(time); 112 PointName pointName = CommonFactoryLocator.getInstance().createPointName("Time to record 10 values to b1"); 113 Common.clientSupportOnProd().recordValue(pointName, time, new Date()); 114 115 116 } 117 118 119}