Example #1
0
  @Test
  public void testAlreadyExistingMuleConfigWithApikitRouter() throws Exception {
    List<File> ramls = Arrays.asList(getFile("scaffolder-existing/simple.raml"));
    File xmlFile = getFile("scaffolder-existing/mule-config-no-api-flows.xml");
    List<File> xmls = Arrays.asList(xmlFile);
    File muleXmlOut = folder.newFolder("mule-xml-out");

    Scaffolder scaffolder = createScaffolder(ramls, xmls, muleXmlOut);
    scaffolder.run();

    assertTrue(xmlFile.exists());
    String s = IOUtils.toString(new FileInputStream(xmlFile));
    assertEquals(
        1,
        countOccurences(
            s,
            "http:listener-config name=\"HTTP_Listener_Configuration\" host=\"localhost\" port=\"${serverPort}\""));
    assertEquals(
        1,
        countOccurences(
            s, "http:listener config-ref=\"HTTP_Listener_Configuration\" path=\"/api/*\""));
    assertEquals(1, countOccurences(s, "<apikit:router config-ref=\"apikit-config\" />"));
    assertEquals(0, countOccurences(s, "http:inbound-endpoint"));
    assertEquals(1, countOccurences(s, "get:/pet"));
    assertEquals(1, countOccurences(s, "post:/pet"));
    assertEquals(1, countOccurences(s, "get:/:"));
    Collection<File> newXmlConfigs = FileUtils.listFiles(muleXmlOut, new String[] {"xml"}, true);
    assertEquals(0, newXmlConfigs.size());
  }
Example #2
0
  @Test
  public void testAlreadyExistsGenerate() throws Exception {
    List<File> ramls = Arrays.asList(getFile("scaffolder-existing/simple.raml"));
    File xmlFile = getFile("scaffolder-existing/simple.xml");
    List<File> xmls = Arrays.asList(xmlFile);
    File muleXmlOut = folder.newFolder("mule-xml-out");

    Scaffolder scaffolder = createScaffolder(ramls, xmls, muleXmlOut);
    scaffolder.run();

    assertTrue(xmlFile.exists());
    String s = IOUtils.toString(new FileInputStream(xmlFile));
    assertEquals(
        1,
        countOccurences(
            s,
            "http:listener-config name=\"HTTP_Listener_Configuration\" host=\"localhost\" port=\"${serverPort}\""));
    assertEquals(
        1,
        countOccurences(
            s, "http:listener config-ref=\"HTTP_Listener_Configuration\" path=\"/api/*\""));
    assertEquals(0, countOccurences(s, "http:inbound-endpoint"));
    assertEquals(1, countOccurences(s, "get:/pet"));
    assertEquals(1, countOccurences(s, "post:/pet"));
    assertEquals(1, countOccurences(s, "get:/\""));
  }
Example #3
0
  private File simpleGeneration(String name) throws Exception {
    List<File> ramls = Arrays.asList(getFile("scaffolder/" + name + ".raml"));
    List<File> xmls = Arrays.asList();
    File muleXmlOut = folder.newFolder("mule-xml-out");

    Scaffolder scaffolder = createScaffolder(ramls, xmls, muleXmlOut);
    scaffolder.run();

    return new File(muleXmlOut, name + ".xml");
  }
Example #4
0
  @Test
  public void testAlreadyExistsGenerateWithCustomDomain() throws Exception {
    List<File> ramls = Arrays.asList(getFile("scaffolder-existing-custom-lc/simple.raml"));
    File xmlFile = getFile("scaffolder-existing-custom-lc/simple.xml");
    File domainFile = getFile("custom-domain/mule-domain-config.xml");

    List<File> xmls = Arrays.asList(xmlFile);
    File muleXmlOut = folder.newFolder("mule-xml-out");
    Scaffolder scaffolder = createScaffolder(ramls, xmls, muleXmlOut, domainFile);
    scaffolder.run();

    assertTrue(xmlFile.exists());
    String s = IOUtils.toString(new FileInputStream(xmlFile));
    assertEquals(0, countOccurences(s, "<http:listener-config"));
    assertEquals(
        1, countOccurences(s, "http:listener config-ref=\"http-lc-0.0.0.0-8081\" path=\"/api/*\""));
    assertEquals(0, countOccurences(s, "http:inbound-endpoint"));
    assertEquals(1, countOccurences(s, "get:/pet"));
    assertEquals(1, countOccurences(s, "get:/\""));
  }
Example #5
0
  @Test
  public void testAlreadyExistsOldWithAddressGenerate() throws Exception {
    List<File> ramls = Arrays.asList(getFile("scaffolder-existing-old-address/complex.raml"));
    File xmlFile = getFile("scaffolder-existing-old-address/complex.xml");
    List<File> xmls = Arrays.asList(xmlFile);
    File muleXmlOut = folder.newFolder("mule-xml-out");

    Scaffolder scaffolder = createScaffolder(ramls, xmls, muleXmlOut);
    scaffolder.run();

    assertTrue(xmlFile.exists());
    String s = IOUtils.toString(new FileInputStream(xmlFile));
    assertEquals(0, countOccurences(s, "http:listener-config"));
    assertEquals(0, countOccurences(s, "http:listener"));
    assertEquals(1, countOccurences(s, "http:inbound-endpoint address"));

    assertEquals(1, countOccurences(s, "put:/clients/{clientId}:complex-config"));
    assertEquals(1, countOccurences(s, "put:/invoices/{invoiceId}:complex-config"));
    assertEquals(1, countOccurences(s, "put:/items/{itemId}:application/json:complex-config"));
    assertEquals(1, countOccurences(s, "put:/providers/{providerId}:complex-config"));
    assertEquals(1, countOccurences(s, "delete:/clients/{clientId}:complex-config"));
    assertEquals(1, countOccurences(s, "delete:/invoices/{invoiceId}:complex-config"));
    assertEquals(
        1, countOccurences(s, "delete:/items/{itemId}:multipart/form-data:complex-config"));
    assertEquals(1, countOccurences(s, "delete:/providers/{providerId}:complex-config"));
    assertEquals(1, countOccurences(s, "get:/:complex-config"));
    assertEquals(1, countOccurences(s, "get:/clients/{clientId}:complex-config"));
    assertEquals(1, countOccurences(s, "get:/clients:complex-config"));
    assertEquals(1, countOccurences(s, "get:/invoices/{invoiceId}:complex-config"));
    assertEquals(1, countOccurences(s, "get:/invoices:complex-config"));
    assertEquals(1, countOccurences(s, "get:/items/{itemId}:complex-config"));
    assertEquals(1, countOccurences(s, "get:/items:complex-config"));
    assertEquals(1, countOccurences(s, "get:/providers/{providerId}:complex-config"));
    assertEquals(1, countOccurences(s, "get:/providers:complex-config"));
    assertEquals(1, countOccurences(s, "post:/clients:complex-config"));
    assertEquals(1, countOccurences(s, "post:/invoices:complex-config"));
    assertEquals(1, countOccurences(s, "post:/items:application/json:complex-config"));
    assertEquals(1, countOccurences(s, "post:/providers:complex-config"));
  }
Example #6
0
  public void execute() throws MojoExecutionException {
    Validate.notNull(muleXmlDirectory, "Error: muleXmlDirectory parameter cannot be null");
    Validate.notNull(specDirectory, "Error: specDirectory parameter cannot be null");

    log = getLog();

    List<String> specFiles = getIncludedFiles(specDirectory, specIncludes, specExcludes);
    List<String> muleXmlFiles =
        getIncludedFiles(muleXmlDirectory, muleXmlIncludes, muleXmlExcludes);
    String domainFile = null;

    if (domainDirectory != null) {
      List<String> domainFiles =
          getIncludedFiles(domainDirectory, new String[] {"*.xml"}, new String[] {});
      if (domainFiles.size() > 0) {
        domainFile = domainFiles.get(0);
        if (domainFiles.size() > 1) {
          log.info(
              "There is more than one domain file inside of the domain folder. The domain: "
                  + domainFile
                  + " will be used.");
        }
      } else {
        log.error(
            "The specified domain directory ["
                + domainDirectory
                + "] does not contain any xml file.");
      }
    } else {
      log.info("No domain was provided. To send it, use -DdomainDirectory.");
    }
    log.info("Processing the following RAML files: " + specFiles);
    log.info("Processing the following xml files as mule configs: " + muleXmlFiles);

    Scaffolder scaffolder =
        Scaffolder.createScaffolder(
            log, muleXmlOutputDirectory, specFiles, muleXmlFiles, domainFile);
    scaffolder.run();
  }