Throwable thrown = new NullPointerException("TESTING NULL POINTER");
EntityManager em = perUtils.createEntityManager();
em.getTransaction().begin();
String userId = "file";
int session = 1;
Logfile log = new Logfile(userId, session);
DbInsertion insertion = new DbInsertion(rec, thrown, new TestLogFileTask(em, log));
insertion.start(new ExceptionsData());
//waitLogsParsed();
List<org.netbeans.modules.exceptions.entity.Exceptions> all =
PersistenceUtils.getAll(em, org.netbeans.modules.exceptions.entity.Exceptions.class);
org.netbeans.modules.exceptions.entity.Exceptions rootException = all.get(all.size() - 1);
rootId = rootException.getId();
List<Nbuser> users = PersistenceUtils.getAll(em, Nbuser.class);
Nbuser user = null;
for (Nbuser us : users) {
if (userName.equals(us.getName())) {
user = us;
}
}
all = PersistenceUtils.getAll(em, org.netbeans.modules.exceptions.entity.Exceptions.class);
rootException = all.get(all.size() - 1);
assertNotNull(rootException);
assertEquals(1, rootException.getReportId().getDuplicates(em));
assertEquals(1, rootException.getReportId().getDuplicatesFromDistinctUsers(em));
assertEquals(1, rootException.getReportId().getDuplicatesFromOneUser(em, user));
session = 2;
log = new Logfile(userId, session);
// -- refresh persistence context ---//
em.getTransaction().commit();
em.close();
em = perUtils.createEntityManager();
em.getTransaction().begin();
all = PersistenceUtils.getAll(em, org.netbeans.modules.exceptions.entity.Exceptions.class);
rootException = all.get(all.size() - 1);
rootException = insert(em, new DbInsertion(rec, thrown, new TestLogFileTask(em, log)));
assertEquals(2, rootException.getReportId().getDuplicates(em));
assertEquals(1, rootException.getReportId().getDuplicatesFromDistinctUsers(em));
assertEquals(2, rootException.getReportId().getDuplicatesFromOneUser(em, user));
session = 3;
log = new Logfile(userId, session);
// -- refresh persistence context ---//
em.getTransaction().commit();
em.close();
em = perUtils.createEntityManager();
em.getTransaction().begin();
all = PersistenceUtils.getAll(em, org.netbeans.modules.exceptions.entity.Exceptions.class);
rootException = all.get(all.size() - 1);
rootException = insert(em, new DbInsertion(rec, thrown, new TestLogFileTask(em, log)));
assertEquals(3, rootException.getReportId().getDuplicates(em));
assertEquals(1, rootException.getReportId().getDuplicatesFromDistinctUsers(em));
assertEquals(3, rootException.getReportId().getDuplicatesFromOneUser(em, user));
userName = "exceptions";
params.set(3, userName);
params.set(6, "petrzajac");
rec.setParameters(params.toArray());
session = 4;
log = new Logfile(userId, session);
// -- refresh persistence context ---//
em.getTransaction().commit();
em.close();
em = perUtils.createEntityManager();
em.getTransaction().begin();
all = PersistenceUtils.getAll(em, org.netbeans.modules.exceptions.entity.Exceptions.class);
rootException = all.get(all.size() - 1);
rootException = insert(em, new DbInsertion(rec, thrown, new TestLogFileTask(em, log)));
users = PersistenceUtils.getAll(em, Nbuser.class);
Iterator<Nbuser> userIt = users.iterator();
Nbuser user2 = null;
while (userIt.hasNext()) {
user2 = userIt.next();
if (user2.getName().equals(userName)) {
break;
}
}
assertEquals(4, rootException.getReportId().getDuplicates(em));
assertEquals(2, rootException.getReportId().getDuplicatesFromDistinctUsers(em));
assertEquals(3, rootException.getReportId().getDuplicatesFromOneUser(em, user));
assertEquals(1, rootException.getReportId().getDuplicatesFromOneUser(em, user2));
session = 5;
log = new Logfile(userId, session);
rootException = insert(em, new DbInsertion(rec, thrown, new TestLogFileTask(em, log)));
// -- refresh persistence context ---//
em.getTransaction().commit();
em.close();