@Test
  public void testMetadataWithCustomModule() {
    try {
      // Create the server
      IServer s = ServerCreationTestUtils.createMockServerWithRuntime(serverType, serverType);
      IServerWorkingCopy wc = s.createWorkingCopy();
      wc.setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, IDeployableServer.DEPLOY_METADATA);
      s = wc.save(true, null);

      // Create the project
      projNum++;
      String projName = "Project" + projNum;
      IDataModel dm =
          CreateProjectOperationsUtility.getWebDataModel(
              projName, null, null, null, null, JavaEEFacetConstants.WEB_24, false);
      try {
        OperationTestCase.runAndVerify(dm);
      } catch (Exception e) {
        fail("Unable to create test web project: " + e.getMessage());
      }
      IProject p = ResourceUtils.findProject(projName);
      assertTrue(p.exists());
      IModule projMod = ServerUtil.getModule(p);

      // Set the custom setting. For now, just override output name
      wc = s.createWorkingCopy();
      AbstractPublishingTest.setCustomDeployOverride(wc, projMod, "newName.war", null, null);
      s = wc.save(true, null);

      // verify no change vs standard metadata
      String[] folders = getAdditions().getDeployLocationFolders(s);
      assertEquals(1, folders.length);
      assertTrue(folders[0].contains("metadata"));

      // Change it to now make some other output folder
      wc = s.createWorkingCopy();
      AbstractPublishingTest.setCustomDeployOverride(
          wc, projMod, "newName.war", "/home/user/deploy", null);
      s = wc.save(true, null);
      folders = getAdditions().getDeployLocationFolders(s);
      assertEquals(2, folders.length);
      assertTrue(folders[0].contains("metadata"));
      assertTrue(folders[1].equals("/home/user/deploy"));

    } catch (CoreException ce) {
      fail("Unable to save changes to server");
    }
  }
    @Override
    public Change perform(IProgressMonitor progressMonitor) throws CoreException {
      IServerWorkingCopy wc = null;

      wc = server.createWorkingCopy();
      if (wc != null) {
        wc.saveAll(true, null);
      }
      return null;
    }
 @Test
 public void testMetadata() {
   try {
     IServer s = ServerCreationTestUtils.createMockServerWithRuntime(serverType, serverType);
     IServerWorkingCopy wc = s.createWorkingCopy();
     wc.setAttribute(IDeployableServer.DEPLOY_DIRECTORY_TYPE, IDeployableServer.DEPLOY_METADATA);
     s = wc.save(true, null);
     String[] folders = getAdditions().getDeployLocationFolders(s);
     assertEquals(1, folders.length);
     assertTrue(folders[0].contains("metadata"));
   } catch (CoreException ce) {
     fail("Unable to save changes to server");
   }
 }
  @Test
  public void testRemoteGetsNoAdditionsInvalidMode() {
    // This test ensures that 'remote' servers are not handled by the standard listeners
    IServer s = ServerCreationTestUtils.createMockServerWithRuntime(serverType, serverType);
    try {
      IServerWorkingCopy wc = s.createWorkingCopy();
      wc.setAttribute(IDeployableServer.SERVER_MODE, "mock5unknown");
      s = wc.save(true, null);
    } catch (CoreException ce) {
      fail("Could not set server mode to non-local");
    }
    boolean accepts = new LocalJBoss7DeploymentScannerAdditions().accepts(s);
    assertFalse(accepts);
    accepts = new JMXServerDeploymentScannerAdditions().accepts(s);
    assertFalse(accepts);

    Job j1 = new LocalJBoss7DeploymentScannerAdditions().getUpdateDeploymentScannerJob(s);
    assertNull(j1);
    Job j2 = new JMXServerDeploymentScannerAdditions().getUpdateDeploymentScannerJob(s);
    assertNull(j2);
  }
  @Test
  public void testNoAdditionsRemovalsFromSettings() {
    // This test ensures that 'remote' servers are not handled by the standard listeners
    IServer s = ServerCreationTestUtils.createMockServerWithRuntime(serverType, serverType);
    try {
      IServerWorkingCopy wc = s.createWorkingCopy();
      wc.setAttribute(IJBossToolingConstants.PROPERTY_ADD_DEPLOYMENT_SCANNERS, false);
      wc.setAttribute(IJBossToolingConstants.PROPERTY_REMOVE_DEPLOYMENT_SCANNERS, false);
      s = wc.save(true, null);
    } catch (CoreException ce) {
      fail("Could not set server mode to non-local");
    }

    // Accepts will also check if the proper server type is here
    ServerExtendedProperties props =
        (ServerExtendedProperties) s.loadAdapter(ServerExtendedProperties.class, null);
    boolean usesManagement =
        props != null
            && props.getMultipleDeployFolderSupport()
                == ServerExtendedProperties.DEPLOYMENT_SCANNER_AS7_MANAGEMENT_SUPPORT;
    boolean usesJMX =
        props != null
            && props.getMultipleDeployFolderSupport()
                == ServerExtendedProperties.DEPLOYMENT_SCANNER_JMX_SUPPORT;

    boolean accepts = new LocalJBoss7DeploymentScannerAdditions().accepts(s);
    assertEquals(accepts, usesManagement);
    accepts = new JMXServerDeploymentScannerAdditions().accepts(s);
    assertEquals(accepts, usesJMX);

    Job j1 = new LocalJBoss7DeploymentScannerAdditions().getUpdateDeploymentScannerJob(s);
    assertNull(j1);
    Job j2 = new JMXServerDeploymentScannerAdditions().getUpdateDeploymentScannerJob(s);
    assertNull(j2);
    Job j3 = new LocalJBoss7DeploymentScannerAdditions().getRemoveDeploymentScannerJob(s);
    assertNull(j3);
    Job j4 = new JMXServerDeploymentScannerAdditions().getRemoveDeploymentScannerJob(s);
    assertNull(j4);
  }
  private IStatus updateServerRefs(
      IModule[] modulesToRemove, IServer affectedServer, IProgressMonitor monitor)
      throws CoreException {
    if (modulesToRemove == null || modulesToRemove.length == 0) {
      return Status.OK_STATUS;
    }
    monitor.beginTask(MODS_FROM_SERVERS, modulesToRemove.length * 100);
    for (int j = 0; j < modulesToRemove.length; j++) {
      IServerWorkingCopy wc = null;
      try {
        wc = affectedServer.createWorkingCopy();
        List list = Arrays.asList(affectedServer.getModules());
        if (list.contains(modulesToRemove[j])) {
          ServerUtil.modifyModules(wc, null, new IModule[] {modulesToRemove[j]}, null);
        }
      } catch (CoreException ce) {
        // Add it to a multistatus list?
        throw ce;
        // J2EEPlugin.logError(ce);
      } finally {
        try {
          if (wc != null) {
            IServer newServer = wc.saveAll(true, null);
            int state = newServer.getServerState();
            if (state == IServer.STATE_STARTED) {
              newServer.publish(
                  IServer.PUBLISH_INCREMENTAL,
                  new NullProgressMonitor()); // TODO use child progress?
            }
          }

        } catch (CoreException ce) {
          throw ce;
        }
      }
    }
    return Status.OK_STATUS;
  }
  /**
   * ModifyModulesWizard constructor.
   *
   * @param server a server
   */
  public ModifyModulesWizard(IServer server) {
    super(Messages.wizModuleWizardTitle, new ModifyModulesWizard2());

    if (server != null) getTaskModel().putObject(TaskModel.TASK_SERVER, server.createWorkingCopy());
  }