Пример #1
0
 /**
  * This method is notified when the end of an element is reached. Does nothing, by default.
  * Specifies whether element is a positional or named argument.
  *
  * @param uri is a Namespace uri. If the element has no Namespace uri or no Namespace
  *     processing is being performed, it is treated as an empty string.
  * @param localName is the local name. If no Namespace processing is being performed
  *     parameter is treated as an empty string.
  * @param qName is the qualified name. If none are available, parameter is treated as an
  *     empty string.
  * @throws SAXException for any SAX exception.
  */
 public void endElement(String uri, String localName, String qName) throws SAXException {
   if (qName.equals("positionalArgument")) {
     ap.addPositionalArgument(aname, adescription, atype);
   }
   if (qName.equals("namedArgument")) {
     ap.addNamedArgument(aname, adescription, atype, adefault, ashorthand);
   }
 }
Пример #2
0
 @Test
 public void testLoadForAnotherFile() {
   String s = n.getArg("square").getDataType();
   String m = n.getArg("blue").getName();
   assertEquals("TestLoad", n.getProgramName());
   assertEquals("TestLoadProgram", n.getProgramDescription());
   assertEquals("integer", s);
   assertEquals("blue", m);
 }
Пример #3
0
        /**
         * This method is used at the beginning of every element in the XML document. All contents
         * of an element are reported, in order, prior to the invocation of the corresponding
         * endElement() method.
         *
         * @param uri is an empty string if the element has no Namespace URI or Namespace processing
         *     is not being performed. Otherwise, parameter is treated as a Namespace.
         * @param localName if Namespace processing is not being performed, parameter is an empty
         *     string.
         * @param qName represents the qualified name and if no qualified names are available,
         *     parameter is an empty string.
         * @param attributes are attached to the xml elements. This parameter is treated as an empty
         *     Attributes object, if no attributes are available.
         * @throws SAXException for any SAX exception.
         */
        public void startElement(String uri, String localName, String qName, Attributes attributes)
            throws SAXException {

          if (qName.equals("arguments")) {
            ap.addProgram(aname, adescription);
          }

          if (qName.equalsIgnoreCase("name")) {
            name = true;
          }

          if (qName.equalsIgnoreCase("type")) {
            type = true;
          }

          if (qName.equalsIgnoreCase("description")) {
            description = true;
          }

          if (qName.equalsIgnoreCase("default")) {
            defaults = true;
          }
          if (qName.equalsIgnoreCase("shorthand")) {
            shorthand = true;
          }
        }
Пример #4
0
 @Test
 public void testGetArgName() {
   String s = q.getArg("one").getName();
   assertEquals("one", s);
 }
Пример #5
0
 @Test
 public void testLoadGetProgramDescription() {
   assertEquals("Test Program", q.getProgramDescription());
 }
Пример #6
0
 @Test
 public void testLoadGetProgramName() {
   assertEquals("Test", q.getProgramName());
 }
Пример #7
0
  @Test
  public void testSave() {
    List<String> values = new ArrayList<String>();
    values.add("one");
    values.add("two");
    values.add("three");

    String[] mutex = new String[] {"testArg", "testArg2"};

    p.setProgramName("Test");
    p.setProgramDescription("Test Program");
    p.addArg("one", Arg.DataType.STRING, "");
    p.getArg("one").setRestrictedValues(values);
    p.addArg("two", Arg.DataType.INTEGER, "This is a test.");
    p.addNamedArg("testArg", Arg.DataType.STRING, "", "test1", 't');
    p.addNamedArg("testArg2", Arg.DataType.STRING, "", "three");
    p.getArg("testArg2").setRestrictedValues(values);
    p.addNamedArg("testArg3", Arg.DataType.STRING, "NamedDescrip", "one", 'c');
    p.getArg("testArg3").setRestrictedValues(values);
    p.addMutualExclusion(mutex);
    p.setNamedArgToRequired("testArg3");

    x.save(p, "./build/tmp/testSave.xml");
    // read in xml file as string and test against known string
    String actualXMLOutput = "";
    String expectedXLMOutput =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><arguments>    <programname>Test</programname>    <programdescription>Test Program</programdescription>    <mutualexclusion>testArg, testArg2</mutualexclusion><positional>    <position>1</position>    <name>one</name>    <type>string</type>    <restrictedvalues>one, two, three</restrictedvalues></positional><positional>    <position>2</position>    <name>two</name>    <type>integer</type>    <description>This is a test.</description></positional><named>    <name>testArg</name>    <type>string</type>    <shortname>t</shortname>    <default>test1</default></named><named>    <name>testArg2</name>    <type>string</type>    <restrictedvalues>one, two, three</restrictedvalues>    <default>three</default></named><named>    <name>testArg3</name>    <type>string</type>    <restrictedvalues>one, two, three</restrictedvalues>    <description>NamedDescrip</description>    <shortname>c</shortname>    <required>true</required>    <default>one</default></named></arguments>";
    String currentLine = null;
    try {
      FileReader r = new FileReader("./build/tmp/testSave.xml");
      BufferedReader b = new BufferedReader(r);
      while ((currentLine = b.readLine()) != null) actualXMLOutput += currentLine;
      b.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    assertEquals(expectedXLMOutput, actualXMLOutput);
  }
Пример #8
0
 @Test
 public void testRequiredArgs() {
   assertEquals("testArg3", q.getRequiredNamedArgs());
 }
Пример #9
0
  @Test
  public void testMutualExclusion() {
    List<String[]> testList = q.getMutualExclusion();

    assertEquals("[testArg, testArg2]", Arrays.toString(testList.get(0)));
  }
Пример #10
0
 @Test
 public void testGetRestrictedValues() {
   assertEquals("[one, two, three]", q.getArg("one").getRestrictedValues());
   assertEquals("[one, two, three]", q.getArg("testArg3").getRestrictedValues());
 }
Пример #11
0
 @Test
 public void testGetArgDataType() {
   String s = q.getArg("one").getDataType();
   assertEquals("string", s);
 }