Package org.jpa

Examples of org.jpa.Grupa


  @Before
  public void setUp() throws Exception {
    emf = Persistence.createEntityManagerFactory("mewp");
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Grupa g = new Grupa();
   
    g.setNumeGrupa("gr1");
    em.persist(g);
    int idgr = g.getIdGrupa();
    for (int i = 0; i < 3; i++) {
      s = new Student();
      s.setIdGrupa(0);
      s.setAnStudiu(1);
      s.setEmail("email");
      s.setNrMatricol(1);
      s.setNume("Student_" + i);
      s.setPrenume("FacultateS_" + i);
      g.getStudenti().add(s);
      em.persist(s);
      em.persist(g);
    }
    em.getTransaction().commit();
    em.close();
View Full Code Here


    String numeGrupaTest = "GrupaTest";
    String numeTest = "numeStudentTest";
    String prenumeTest = "prenumeStudentTest";
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Grupa g = new Grupa();

    g.setNumeGrupa(numeGrupaTest);
    em.persist(g);
    int idGr = g.getIdGrupa();
    final int n = 3;

    for (int i = 0; i < n; i++) {
      Student s = new Student();
      s.setIdGrupa(idGr);
      s.setAnStudiu(anStudiuTest);
      s.setEmail(emailTest);
      s.setNrMatricol(String.valueOf(i));
      s.setNume(numeTest + String.valueOf(i));
      s.setPrenume(prenumeTest + String.valueOf(i));
      g.getStudenti().add(s);
      em.persist(g);
    }
    em.getTransaction().commit();
    em.getTransaction().begin();
    Grupa gTest = new Grupa();
    gTest = em.find(Grupa.class, idGr);
    assertTrue("GrupaTest".equals(gTest.getNumeGrupa()));
    Query q = em.createQuery("select st from Student st ");
    List<Student> st = new ArrayList<Student>();
    st = (List<Student>) q.getResultList();
    assertTrue(st.equals(gTest.getStudenti()));
    em.getTransaction().commit();
    em.close();

  }
View Full Code Here

    String numeGrupaTest = "GrupaTest";
    String numeGrupaTest1 = "GrupaTest1";
    String prenumeTest = "prenumeStudentTest";
    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    Grupa g = new Grupa();

    g.setNumeGrupa(numeGrupaTest);

    em.persist(g);

    int idGr = g.getIdGrupa();

    Student studentTest = new Student();
    studentTest.setIdGrupa(idGr);
    studentTest.setAnStudiu(anStudiuTest);
    studentTest.setEmail(emailTest);
    studentTest.setNrMatricol(numarMatricolTest);
    studentTest.setNume(numeTest);
    studentTest.setPrenume(prenumeTest);
    g.getStudenti().add(studentTest);
    em.persist(g);
    Query q = em.createNativeQuery("SELECT student.studenti_id_grupa  FROM Student WHERE student.studenti_id_grupa=?1")
        .setParameter(1, idGr);
    List st = q.getResultList();
    q = em.createQuery("select s from Student s");
    Student s = new Student();
    s = (Student) q.getSingleResult();
    assertEquals(st.size(), 1);
    Grupa g1 = new Grupa();
    g1.setNumeGrupa(numeGrupaTest1);
    em.persist(g1);
    int idGr1 = g1.getIdGrupa();
    g1.getStudenti().add(s);
    em.persist(g1);
    q = em.createNativeQuery(
        "SELECT student.studenti_id_grupa  FROM Student WHERE student.studenti_id_grupa=?1")
        .setParameter(1, idGr1);
    List st1 = q.getResultList();
View Full Code Here

  @Test
  public void testPersistUpdateDelete() {
    String numeGrupaTest = "GrupaTest";
    String numeGrupaTest1 = "GrupaTest1";
    Grupa g = new Grupa();

    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    g.setNumeGrupa(numeGrupaTest);
    em.persist(g);
    em.getTransaction().commit();
    Query q = em.createQuery("select grT from Grupa grT where grT.numeGrupa='GrupaTest' ");
    Grupa grT=new Grupa();
    grT=(Grupa) q.getSingleResult();
    assertTrue("Nu a fost persistat ","GrupaTest".equals(grT.getNumeGrupa()));
    em.getTransaction().begin();
    grT.setNumeGrupa(numeGrupaTest1);
    em.getTransaction().commit();
    q = em.createQuery("select grT from Grupa grT  ");
    Grupa grT1=new Grupa();
    grT1=(Grupa) q.getSingleResult();
    assertEquals("Nu a fost schimbat numele grupei",grT1.getNumeGrupa(), numeGrupaTest1);
    em.getTransaction().begin();
    q = em.createQuery("Delete from Grupa gr");
    int deletedData = q.executeUpdate();
    em.getTransaction().commit();
    assertEquals("Tabela avea mai mult de o inregistrare",deletedData, 1);
View Full Code Here

  }
  @Test
  public void testStudentRelation(){
    String numeGrupaTest = "GrupaTest";
    Grupa g = new Grupa();
    Student s = new Student();

    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    s=initTest1();
    g.setNumeGrupa(numeGrupaTest);
    g.getStudenti().add(s);
    em.persist(g);
    Query q = em.createQuery("select grT from Grupa grT ");
    Grupa grT1=new Grupa();
    grT1=(Grupa) q.getSingleResult();
    assertTrue("Nu a fost introdus in grupa","GrupaTest".equals(grT1.getNumeGrupa()));
     q = em.createQuery("select st from Student st where st.nume='numeStudentTest' ");
    Student st = new Student();
    st = (Student) q.getSingleResult();
    assertTrue("Nu a fost introdus in student","numeStudentTest".equals(st.getNume()));
   
View Full Code Here

   
  }
  @Test
  public void testOrarRelation(){
    String numeGrupaTest = "GrupaTest";
    Grupa g = new Grupa();
    Orar o = new Orar();

    EntityManager em = emf.createEntityManager();
    em.getTransaction().begin();
    o=initTest2();
    g.setNumeGrupa(numeGrupaTest);
   
    em.persist(g);
      o.setIdGrupa(g.getIdGrupa());
      g.getOrar().add(o);
      em.persist(g);
      em.getTransaction().commit();
    Query q = em.createQuery("select grT from Grupa grT ");
    Grupa grT1=new Grupa();
    grT1=(Grupa) q.getSingleResult();
    assertTrue("Nu a fost introdus in grupa","GrupaTest".equals(grT1.getNumeGrupa()));
     q = em.createQuery("select oT from Orar oT where oT.intervalOrar='12-14' ");
     Orar oT = new Orar();
     oT=(Orar) q.getSingleResult();
     assertTrue("Nu a fost introdus in orar","12-14".equals(oT.getIntervalOrar()));
     em.close();
View Full Code Here

    @Before
    public void setUp() throws Exception {
        emf = Persistence.createEntityManagerFactory("m2_L3");
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        Grupa g = new Grupa();
       
        g.setNumeGrupa("gr1");
        em.persist(g);
        idGr = g.getIdGrupa();
        final int n=3;
        final int temp=1;
        for (int i = 0; i < n; i++) {
            Student s = new Student();
            s.setIdGrupa(0);
            s.setAnStudiu(temp);
            s.setEmail("email");
            s.setNrMatricol(String.valueOf(temp));
            s.setNume("Student_" + i);
            s.setPrenume("FacultateS_" + i);
            g.getStudenti().add(s);
         
            em.persist(g);
        }
       
      
View Full Code Here

         Query q = em.createQuery("select g from Grupa g");
         assertTrue(q.getResultList().size() == temp1);
          q = em.createQuery("select s from Student s");
         assertTrue(q.getResultList().size() == temp2);
       
         Grupa g = new Grupa();
        
         g=em.find(Grupa.class,idGr);
            List<Student>studenti=new ArrayList<Student>();
            studenti=g.getStudenti();
             assertFalse(studenti.isEmpty());
            em.getTransaction().commit();
            em.close();
                   
    }
View Full Code Here

TOP

Related Classes of org.jpa.Grupa

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.