users@glassfish.java.net

Re: Arquillian and glassfish (Error)

From: <glassfish_at_javadesktop.org>
Date: Tue, 19 Oct 2010 07:23:18 PDT

i don't have any of the *.xml files but i have just an ejb class
here is my classes:

package employee;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author y
 */
@Entity
@Table(name = "employee")
@NamedQueries({
    @NamedQuery(name = "Employee.findAll", query = "SELECT e FROM Employee e"),
    @NamedQuery(name = "Employee.findById", query = "SELECT e FROM Employee e WHERE e.id = :id"),
    @NamedQuery(name = "Employee.findByUsername", query = "SELECT e FROM Employee e WHERE e.username = :username")})
public class Employee implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "id")
    private Long id;
    @Basic(optional = false)
    @Column(name = "username")
    private String username;
    @JoinColumn(name = "id", referencedColumnName = "id", insertable = false, updatable = false)
    @OneToOne(optional = false)
    private Person person;

    public Employee() {
    }

    public Employee(Long id) {
        this.id = id;
    }

    public Employee(Long id, String username) {
        this.id = id;
        this.username = username;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Employee)) {
            return false;
        }
        Employee other = (Employee) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "employee.Employee[id=" + id + "]";
    }

}

the bean class for it:
package employee;

import javax.ejb.Stateless;

/**
 *
 * @author y
 */
@Stateless
public class employeebean {

    protected String name;

    /**
     * Get the value of string
     *
     * @return the value of string
     */


    public String getName() {
        return name;
    }
    public boolean setName(String name){
      this.name=name;
      return true;
    }


}

and the webservice:
package employeews;

import employee.employeebean;
import javax.ejb.EJB;
import javax.jws.Oneway;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

/**
 *
 * @author y
 */
@WebService()
public class NewWebService {
    @EJB
    private employeebean ejbRef;// Add business logic below. (Right-click in editor and choose

    /**
     * Web service operation
     */
    @WebMethod(operationName = "getEmployee")
    public String getEmployee() {
       return "y";

    }

    /**
     * Web service operation
     */
    @WebMethod(operationName = "setName")
// @Oneway
    public boolean setName(@WebParam(name = "name")
    String name) {
        return ejbRef.setName(name);

    }

  

}


and the test class with arquillian :
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package employeews;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import javax.inject.Inject;
import org.jboss.arquillian.api.RunModeType;
import org.jboss.shrinkwrap.api.ArchivePaths;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import junit.framework.Assert;
import java.io.File;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.api.Run;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;

import org.junit.runner.RunWith;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author y
 */
@RunWith(Arquillian.class)
@Run(RunModeType.AS_CLIENT) //RunModeType.IN_CONTAINER)

   /**
    * Deployment for the test
    * @return
    */



public class NewWebServiceTest {

    @Deployment
   public static WebArchive getDeployment()
   {
      return ShrinkWrap.create(WebArchive.class, "test.war").addClasses(NewWebService.class,employee.employeebean.class,employee.Employee.class)
      .addManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
   }
    @Inject NewWebService webservice;
    public NewWebServiceTest() {
    }

    @BeforeClass
   public static void startContainer() throws Exception
   {
      Runtime.getRuntime().exec(new String[] {
            getAsadminCommand(),
            "start-domain",
            "tests"}).waitFor();
   }
    @AfterClass
    public static void stopContainer() throws Exception
   {
      Runtime.getRuntime().exec(new String[] {
            getAsadminCommand(),
            "stop-domain",
            "tests"}).waitFor();
   }

    @Before
    public void setUp() {
    }

    @After
    public void tearDown() {
    }

    /**
     * Test of getEmployee method, of class NewWebService.
     */
    @Test
    public void testGetEmployee() {
        System.out.println("getEmployee");
        NewWebService instance = new NewWebService();
        String expResult = "y";
        String result = instance.getEmployee();
        Assert.assertEquals(expResult, result);

    }
     @Test
     public void testSetEmployee(){
        System.out.println("getEmployee");
        NewWebService instance =new NewWebService();
        instance.setName("Test");

     }

    public static String getAsadminCommand()
   {
      File asadminFile = new File("C:"+File.separator+"Programme"+File.separator+"glassfish-3.0.1" +
            File.separator + "bin" + File.separator + "asadmin.bat");
      if (!asadminFile.exists() || !asadminFile.isFile())
      {
         Assert.fail("Path to asadmin command is invalid: " + asadminFile.getAbsolutePath());
      }
      return asadminFile.getAbsolutePath();
   }

}
[Message sent by forum member 'yahya_h']

http://forums.java.net/jive/thread.jspa?messageID=485594