/**
  * Prepare for test case execution by initialising the mocks.
  *
  * @throws Exception If there was a problem preparing the test cases.
  */
 @Before
 public void setUp() throws Exception {
   initMocks(this);
   ReflectionUtils.setVariableValueInObject(mojo, "monitorPort", 10000);
   ReflectionUtils.setVariableValueInObject(mojo, "monitorKey", "dummy");
   ReflectionUtils.setVariableValueInObject(wrongMojo, "monitorPort", 10000);
   ReflectionUtils.setVariableValueInObject(wrongMojo, "monitorKey", "jester");
   when(mojo.getLog()).thenReturn(log);
   when(wrongMojo.getLog()).thenReturn(log);
   when(server.isStarted(any(Logger.class))).thenReturn(true);
   when(server.isStopped(any(Logger.class))).thenReturn(true);
 }
 /**
  * Prepare for test execution by initialising the mock objects and test fixture.
  *
  * @throws Exception If there was an error configuring the test fixture.
  */
 @Before
 public void setUp() throws Exception {
   initMocks(this);
   Class.forName(getDriverClassName());
   mojo = new RunMojo();
   ReflectionUtils.setVariableValueInObject(mojo, "monitorPort", getMonitorPort());
   ReflectionUtils.setVariableValueInObject(mojo, "monitorKey", "inmemdb");
   ReflectionUtils.setVariableValueInObject(mojo, "type", getType());
   ReflectionUtils.setVariableValueInObject(mojo, "database", "test");
   final Script source = new Script();
   source.setSourceFile(getCreateScript());
   final List<Source> sources = new ArrayList<Source>();
   sources.add(source);
   ReflectionUtils.setVariableValueInObject(mojo, "sources", sources);
 }
Exemple #3
0
  private Field getFieldByName(String fieldName, Class clazz)
      throws ComponentConfigurationException {
    Field retValue = ReflectionUtils.getFieldByNameIncludingSuperclasses(fieldName, clazz);

    if (retValue == null) {
      String msg =
          "Class '" + clazz.getName() + "' does not contain a field named '" + fieldName + "'";

      throw new ComponentConfigurationException(msg);
    }

    return retValue;
  }
  private void initSetter() {
    setter = ReflectionUtils.getSetter(fieldName, object.getClass());

    if (setter == null) {
      return;
    }

    setterParamType = setter.getParameterTypes()[0];

    try {
      setterTypeConverter = lookup.lookupConverterForType(setterParamType);
    } catch (ComponentConfigurationException e) {
      // ignore, handle later
    }
  }
  private void initField() {
    field = ReflectionUtils.getFieldByNameIncludingSuperclasses(fieldName, object.getClass());

    if (field == null) {
      return;
    }

    fieldType = field.getType();

    try {
      fieldTypeConverter = lookup.lookupConverterForType(fieldType);
    } catch (ComponentConfigurationException e) {
      // ignore, handle later
    }
  }
  /**
   * Verify that we can start the server as a daemon.
   *
   * @throws Exception If there was an error.
   */
  @Test
  public void testRunDaemon() throws Exception {
    ReflectionUtils.setVariableValueInObject(mojo, "daemon", Boolean.TRUE);
    try {
      mojo.execute();
      Thread.sleep(5000L);
      final Connection jdbcConnection = DriverManager.getConnection(getConnectionString());
      final IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
      IDataSet databaseDataSet = connection.createDataSet();
      assertNotNull(databaseDataSet.getTable(getTableName()));

      connection.close();
      jdbcConnection.close();
    } finally {
      signalStop();
    }
  }
  /**
   * Verify that we can start the server.
   *
   * @throws Exception If there was an error.
   */
  @Test
  public void testRun() throws Exception {
    ReflectionUtils.setVariableValueInObject(mojo, "daemon", Boolean.FALSE);

    final Thread mojoThread =
        new Thread(
            new Runnable() {
              public void run() {
                try {
                  mojo.execute();
                } catch (final Exception e) {
                }
              }
            });
    mojoThread.start();
    try {
      Thread.sleep(5000);

      final Connection jdbcConnection = DriverManager.getConnection(getConnectionString());
      final IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
      IDataSet databaseDataSet = connection.createDataSet();
      assertNotNull(databaseDataSet.getTable(getTableName()));

      connection.close();
      jdbcConnection.close();
    } finally {
      final Timer timer = new Timer();
      timer.schedule(
          new TimerTask() {
            @Override
            public void run() {
              signalStop();
            }
          },
          5000L);
      mojoThread.join(15000L);
    }
  }
  /**
   * This method will run client gen on the given WSDL.
   *
   * @throws MojoExecutionException Thrown if we fail to obtain the WSDL.
   */
  public void execute() throws MojoExecutionException {
    super.execute();

    if (getLog().isInfoEnabled()) {
      getLog().info("Weblogic client gen beginning ");
    }
    if (getLog().isInfoEnabled()) {
      getLog().info(" Detailed client gen settings information " + this.toString());
    }

    try {
      final ClientGenTask clientGen = new ClientGenTask();
      // Set the classpath
      final Project project = new Project();
      project.setName("clientgen");
      final Path path =
          new Path(
              project,
              WeblogicMojoUtilities.getDependencies(
                  this.getArtifacts(), this.getPluginArtifacts()));
      clientGen.setProject(project);
      clientGen.setClasspath(path);

      // in WebLogic 10.3 some methods were renamed (e.g. "setDestDir()") or removed (e.g.
      // "setOverwrite()")
      // so we have to use reflection here
      //            clientGen.setOverwrite( true );
      Method method = ReflectionUtils.getSetter("overwrite", clientGen.getClass());
      if (method != null) {
        method.invoke(clientGen, new Object[] {Boolean.TRUE});
      }
      //            clientGen.setDestdir( new File( this.outputDir ) );
      method = ReflectionUtils.getSetter("destdir", clientGen.getClass());
      if (method != null) {
        method.invoke(clientGen, new Object[] {new File(this.outputDir)});
      }
      //            clientGen.setDestDir( new File( this.outputDir ) );
      method = ReflectionUtils.getSetter("destDir", clientGen.getClass());
      if (method != null) {
        method.invoke(clientGen, new Object[] {new File(this.outputDir)});
      }

      clientGen.setVerbose(this.verbose);
      clientGen.setPackageName(this.packageName);
      clientGen.setIncludeGlobalTypes(this.useServerTypes);
      clientGen.setJaxRPCWrappedArrayStyle(this.jaxRPCWrappedArrayStyle);
      String wsdlUri;
      if (this.warFileName != null) {
        if (getLog().isInfoEnabled()) {
          getLog()
              .info(
                  " calculating wsdl URI from warFileName "
                      + this.warFileName
                      + " with wsdl "
                      + this.inputWSDL);
        }
        wsdlUri =
            "jar:file:"
                + WeblogicMojoUtilities.getWarFileName(this.getArtifacts(), this.warFileName)
                + "!"
                + this.inputWSDL;
        new File(this.inputWSDL).toURI().toString();
        if (getLog().isInfoEnabled()) {
          getLog().info(" using " + wsdlUri + " for clientgen.");
        }
      } else if (this.inputWSDL.startsWith("http")) {
        if (getLog().isInfoEnabled()) {
          getLog().info(" using " + this.inputWSDL + " for clientgen.");
        }
        wsdlUri = this.inputWSDL;
      } else {
        wsdlUri = new File(this.inputWSDL).toURI().toString();
        if (getLog().isInfoEnabled()) {
          getLog().info(" using " + wsdlUri + " for clientgen.");
        }
      }
      clientGen.setWsdl(wsdlUri);
      // set the service name if it is specified
      if (this.serviceName != null) {
        if (getLog().isInfoEnabled()) {
          getLog().info(" generating client for service '" + this.serviceName + "'.");
        }
        clientGen.setServiceName(this.serviceName);
      }
      clientGen.execute();
    } catch (Exception ex) {
      getLog().error("Exception encountered during client gen", ex);
      throw new MojoExecutionException("Exception encountered during listapps", ex);
    } finally {
      WeblogicMojoUtilities.unsetWeblogicProtocolHandler();
    }

    if (getLog().isInfoEnabled()) {
      getLog().info("Weblogic client gen successful ");
    }
  }