Exemplo n.º 1
0
  /** Test of get method, of class SAMPFactory. */
  public void testGet_SAMPMessage_Class() throws Exception {
    String mtype = "test";
    Object instance = getInstance();

    SAMPMessage message = SAMPFactory.createMessage(mtype, instance, TestInterface.class);

    TestInterface result = (TestInterface) SAMPFactory.get(message, TestInterface.class);
    assertEquals("Test Name", result.getName());
    assertTrue(Arrays.equals(new double[] {1., 2., 3.}, result.getArray()));
    assertEquals("Test Something", result.getNested().getSomething());
  }
Exemplo n.º 2
0
  /** Test of createMessage method, of class SAMPFactory. */
  public void testCreateMessage() throws Exception {
    String mtype = "test";
    Object instance = getInstance();

    SAMPMessage result = SAMPFactory.createMessage(mtype, instance, TestInterface.class);
    Message message = result.get();
    assertEquals("test", message.getMType());
    Map obj = message.getParams();
    assertEquals("Test Name", obj.get("name"));
    assertEquals(
        EncodeDoubleArray.encodeBase64(new double[] {1., 2., 3.}, false), obj.get("array"));
    Map nested = (Map) obj.get("nested");
    assertEquals("Test Something", nested.get("something"));
  }
Exemplo n.º 3
0
  /** Test of get method, of class SAMPFactory. */
  public void testGet_Class() {
    TestInterface result = (TestInterface) SAMPFactory.get(TestInterface.class);
    List<String> methods = new ArrayList<>();
    List<String> exp_methods = new ArrayList<>();

    for (Method m : result.getClass().getDeclaredMethods()) methods.add(m.getName());

    for (Method m : TestInterface.class.getDeclaredMethods()) exp_methods.add(m.getName());

    assertTrue(methods.containsAll(exp_methods));

    result.setName("test name");
    result.setArray(new double[] {0.1, 0.2});

    result.getNested().setSomething("test something");

    assertEquals("test name", result.getName());
    assertTrue(Arrays.equals(new double[] {0.1, 0.2}, result.getArray()));
    assertEquals("test something", result.getNested().getSomething());

    result.addThing("Three");

    assertTrue(result.getThings().contains("Three"));
  }