Esempio n. 1
0
  @Test
  public void simultaneousDialing() {
    try {
      Response response = new Response();
      response.dials = new ArrayList<>();
      Dial dial1 = new Dial();
      dial1.users = new ArrayList<>();
      dial1.users.add(new User("sip:[email protected]"));
      dial1.users.add(new User("sip:[email protected]"));
      dial1.numbers = new ArrayList<>();
      dial1.numbers.add(new Number("15671234567"));
      response.dials.add(dial1);

      StringWriter sw = new StringWriter();
      JAXBContext jaxbContext = JAXBContext.newInstance(Response.class);
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

      // output pretty printed
      jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);

      jaxbMarshaller.marshal(response, sw);
      Assert.assertEquals(
          "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Response><Dial><Number>15671234567</Number><User>sip:[email protected]</User><User>sip:[email protected]</User></Dial></Response>",
          sw.toString());

    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail(e.getMessage());
    }
  }
Esempio n. 2
0
  @Test
  public void dialWithNumbers() {
    try {
      StringWriter sw = new StringWriter();
      Response response = new Response();
      Dial dial = new Dial();
      dial.callerId = "12345678901";
      Number number1 = new Number("123456");
      Number number2 = new Number("789120");

      dial.action = "http://http://myserverurl/setredirect/";
      dial.method = Method.GET;
      dial.numbers = new ArrayList<>();
      dial.numbers.add(number1);
      dial.numbers.add(number2);
      response.dials = new ArrayList<>();
      response.dials.add(dial);

      JAXBContext jaxbContext = JAXBContext.newInstance(Response.class);
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
      jaxbMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.FALSE);

      // output pretty printed
      jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);

      jaxbMarshaller.marshal(response, sw);
      Assert.assertEquals(
          "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Response><Dial action=\"http://http://myserverurl/setredirect/\" method=\"GET\" callerId=\"12345678901\"><Number>123456</Number><Number>789120</Number></Dial></Response>",
          sw.toString());

    } catch (JAXBException e) {
      e.printStackTrace();
      Assert.fail(e.getMessage());
    }
  }
Esempio n. 3
0
  @Test
  public void sequentialDialing() {
    try {
      Response response = new Response();
      response.dials = new ArrayList<>();
      Dial dial1 = new Dial();
      dial1.timeout = 20;
      dial1.action = "http://foo.com/dial_action/";
      dial1.numbers = new ArrayList<>();
      dial1.numbers.add(new Number("18217654321"));
      response.dials.add(dial1);
      Dial dial2 = new Dial();
      dial2.numbers = new ArrayList<>();
      dial2.numbers.add(new Number("15671234567"));
      response.dials.add(dial2);
      StringWriter sw = new StringWriter();
      JAXBContext jaxbContext = JAXBContext.newInstance(Response.class);
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

      // output pretty printed
      jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false);
      jaxbMarshaller.marshal(response, sw);
      Assert.assertEquals(
          "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><Response><Dial action=\"http://foo.com/dial_action/\" timeout=\"20\"><Number>18217654321</Number></Dial><Dial><Number>15671234567</Number></Dial></Response>",
          sw.toString());

    } catch (Exception e) {
      e.printStackTrace();
      Assert.fail(e.getMessage());
    }
  }