Ejemplo n.º 1
0
  /**
   * Relates to https://issuetracker.springsource.com/browse/STS-1874. Example code from
   * https://issuetracker.springsource.com/browse/STS-1880.
   */
  public void testAgentBasedReloading() throws Exception {
    GrailsVersion version = GrailsVersion.MOST_RECENT;
    if (version.compareTo(GrailsVersion.V_2_0_0) >= 0
        && !GrailsTestsActivator.isJointGrailsTest()) {
      ensureDefaultGrailsVersion(version);
      final String projectName = TEST_PROJECT_NAME;
      project = ensureProject(projectName);
      createResource(
          project,
          "grails-app/controllers/ReloadableController.groovy",
          "class ReloadableController\n"
              + "{\n"
              + "   def index = { render \"hello world\" }\n"
              + "}");
      StsTestUtil.assertNoErrors(project); // Forces build and checks for compile errors in project.

      final int port = StsTestUtil.findFreeSocketPort();
      ILaunchConfigurationWorkingCopy launchConf =
          (ILaunchConfigurationWorkingCopy)
              GrailsLaunchConfigurationDelegate.getLaunchConfiguration(
                  project, "-Dserver.port=" + port + " run-app", false);

      ILaunch launch = launchConf.launch(ILaunchManager.RUN_MODE, new NullProgressMonitor());
      dumpOutput(launch);
      final URL url = new URL("http://localhost:" + port + "/" + projectName + "/reloadable/index");
      try {
        new ACondition("hello world") {
          public boolean test() throws Exception {
            String page = getPageContent(url);
            assertEquals("hello world\n", page);
            return true;
          }
        }.waitFor(5 * 60 * 1000);

        createResource(
            project,
            "grails-app/controllers/ReloadableController.groovy",
            "class ReloadableController\n"
                + "{\n"
                + "   def index = { render \"goodbye world\" }\n"
                + "}");

        new ACondition("goodbye world") {
          public boolean test() throws Exception {
            String page = getPageContent(url);
            assertEquals("goodbye world\n", page);
            return true;
          }
        }.waitFor(30000); // updating contents with SpringLoaded should be faster?
      } finally {
        launch.terminate();
      }
    } else {
      System.out.println("Skipping this test");
    }
  }
Ejemplo n.º 2
0
  public void testTagLibsFromPlugin() throws Exception {

    IProject proj = ensureProject(TEST_PROJECT_NAME);
    ensureDefaultGrailsVersion(GrailsVersion.getGrailsVersion(proj));

    if (GrailsVersion.V_2_3_.compareTo(GrailsVersion.MOST_RECENT) > 0) {
      // below 2.3 install-plugin command works
      GrailsCommand cmd =
          GrailsCommand.forTest(proj, "install-plugin").addArgument("feeds").addArgument("1.6");
      cmd.synchExec();
    } else {
      // after 2.3, must edit build config
      IFile buildConfig = proj.getFile("grails-app/conf/BuildConfig.groovy");
      String origContents = GrailsTest.getContents(buildConfig);

      // Modify the props file add two plugins
      // A bit of a hack, but this is a simple way to add plugins to the build
      String newContents =
          origContents.replace("plugins {\n", "plugins {\n\t\tcompile \":feeds:1.6\"\n");
      GrailsTest.setContents(buildConfig, newContents);
    }
    refreshDependencies(proj);

    assertPluginSourceFolder(proj, "feeds-1.6", "src", "groovy");

    // now also check to see that the tag is available
    PerProjectTagProvider provider = GrailsCore.get().connect(proj, PerProjectTagProvider.class);
    assertNotNull("feeds:meta tag not installed", provider.getDocumentForTagName("feed:meta"));
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();

    project = ensureProject("bart");
    // On build server, some tests are failing because mismatching grails version (default
    // install was modified by some other tests, since creating the bart project?)
    ensureDefaultGrailsVersion(GrailsVersion.getGrailsVersion(project));
  }
Ejemplo n.º 4
0
  public void testOutputLimit() throws Exception {
    IProject proj = ensureProject(TEST_PROJECT_NAME);
    ensureDefaultGrailsVersion(GrailsVersion.getGrailsVersion(proj));

    GrailsCommand cmd = GrailsCommand.forTest("help");
    ILaunchResult result = cmd.synchExec();
    //		String allOutput = result.getOutput();

    int orgLimit = GrailsCoreActivator.getDefault().getGrailsCommandOutputLimit();
    try {
      GrailsCoreActivator.getDefault().setGrailsCommandOutputLimit(100);
      result = cmd.synchExec();
      assertEquals(100, result.getOutput().length());

    } finally {
      GrailsCoreActivator.getDefault().setGrailsCommandOutputLimit(orgLimit);
    }
  }
 /**
  * Add a system property arg to set killport for Grails 2.3 and higher.
  *
  * @param project
  * @return An array of kill ports to try in order to ask Grails forked process to terminate.
  */
 private ArrayList<Integer> addKillPortArg(IProject project, List<String> vmArgs) {
   ArrayList<Integer> ports = null;
   if (project != null) {
     if (GrailsVersion.V_2_3_.compareTo(GrailsVersion.getEclipseGrailsVersion(project)) <= 0) {
       ports = new ArrayList<Integer>(2); // Will have 1 or two elements not more.
       int serverPort = GrailsWorkspace.get().create(project).getServerPort();
       if (serverPort != DependencyData.UNKNOWN_PORT) {
         ports.add(serverPort + 1);
       }
       // The next bit really only expected to work in in Grails 2.3
       try {
         int allocatedKillPort = portFinder.findUniqueFreePort();
         vmArgs.add("-Dgrails.forked.kill.port=" + allocatedKillPort);
         ports.add(allocatedKillPort);
       } catch (IOException e) {
         // non fatal... log and proceed
         GrailsCoreActivator.log(e);
       }
     }
   }
   return ports;
 }