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

http://nimbits-server.googlecode.com/ · Java · 86 lines · 28 code · 13 blank · 45 comment · 2 complexity · c3d773dfffc493defd898bdd355257ca MD5 · raw file

  1. /*
  2. * Copyright (c) 2010 Tonic Solutions LLC.
  3. *
  4. * http://www.nimbits.com
  5. *
  6. *
  7. * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
  8. *
  9. * http://www.gnu.org/licenses/gpl.html
  10. *
  11. * 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.
  12. */
  13. import com.nimbits.client.NimbitsClient;
  14. import com.nimbits.client.NimbitsClientFactory;
  15. import com.nimbits.client.model.common.CommonFactoryLocator;
  16. import com.nimbits.client.model.email.EmailAddress;
  17. import com.nimbits.client.model.point.PointName;
  18. import com.nimbits.user.GoogleUser;
  19. import com.nimbits.user.UserFactory;
  20. import org.junit.Test;
  21. import java.io.IOException;
  22. /**
  23. * Created by bsautner
  24. * User: benjamin
  25. * Date: 10/7/11
  26. * Time: 4:02 PM
  27. */
  28. public class JsonTest {
  29. @Test
  30. public void testM2M() throws IOException, InterruptedException {
  31. // PointName pointName = CommonFactoryLocator.getInstance().createPointName("foo");
  32. // Robot robot = new Robot();
  33. // robot.setFeeling(Robot.Feeling.sad);
  34. // Value value = ValueModelFactory.createValueModel(40.111, -75.146,1, "Angry", robot);
  35. //
  36. //
  37. // Common.meOnProd().recordValue(pointName, value);
  38. //
  39. //
  40. // sleep(1000);
  41. //
  42. // Value v = Common.meOnProd().getCurrentRecordedValue(pointName);
  43. // Robot returnedRobot = (Robot) v.getData(Robot.class);
  44. //
  45. // System.out.println(returnedRobot.getFeeling());
  46. }
  47. @Test
  48. public void sendData() throws Exception {
  49. //
  50. // PointName pointName = CommonFactoryLocator.getInstance().createPointName("MyRobot");
  51. // EmailAddress emailAddress = CommonFactoryLocator.getInstance().createEmailAddress("bsautner@gmail.com");
  52. // GoogleUser me = UserFactory.createGoogleUser(emailAddress, "Port1234");
  53. // NimbitsClient client = NimbitsClientFactory.getInstance(me, "http://nimbits1.appspot.com");
  54. //
  55. // Robot robot = new Robot();
  56. // robot.setEmotion(Robot.Emotion.happy);
  57. //
  58. // Value value = ValueModelFactory.createValueModel(40.111, -75.146,1, "I'm a happy robot", robot);
  59. // client.recordValue(pointName, value);
  60. }
  61. @Test
  62. public void getData() throws Exception {
  63. PointName pointName = CommonFactoryLocator.getInstance().createPointName("MyRobot");
  64. EmailAddress emailAddress = CommonFactoryLocator.getInstance().createEmailAddress("bsautner@gmail.com");
  65. GoogleUser me = UserFactory.createGoogleUser(emailAddress, "Port1234");
  66. NimbitsClient client = NimbitsClientFactory.getInstance(me, "http://nimbits1.appspot.com");
  67. Robot robot = (Robot) client.getCurrentDataObject(pointName, Robot.class);
  68. System.out.print(robot.getEmotion());
  69. if (robot.getEmotion() == Robot.Emotion.angry) {
  70. //destroyAllHumans();
  71. }
  72. }
  73. }